-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·128 lines (94 loc) · 2.64 KB
/
setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
function usage()
{
echo \
"Usage: $0 [OPTIONS]
Install the requested version of 'docker-template' in your system
Options:
-g | --gem Uses GEM instead of Bundler to install 'docker-template'
"
# Prints default usage options, from ./env.sh
usage_general_options
}
function install_bundler()
{
log info "Installing bundler"
sudo gem install bundler
return
}
function install_docker_template_bundler()
{
log info "Installation of 'docker-template' with Bundler"
log info "Copying Gemfile [${DIR}/Gemfile -> ${PWD}]"
cp ${DIR}/Gemfile ./
bundler show docker-template || { bundler install --path=vendor/bundler; log info "'docker-template' installed with Bundler"; }
return
}
function install_docker_template_gem()
{
log info "Installing docker-template with Gem"
sudo gem install docker-template
return
}
function write_gitignore_line()
{
gitignore_file=$1
shift
ignore_pattern=$@
if [ ! -f "$gitignore_file" ]; then
touch $gitignore_file
fi
if [ -z "$(grep -x "${ignore_pattern}" ${gitignore_file})" \
-a -z "$(grep -x "#${ignore_pattern}" ${gitignore_file})" \
-a -z "$(grep -x "# ${ignore_pattern}" ${gitignore_file})" ]; then
echo "$gitignore_file -> $ignore_pattern"
echo "$ignore_pattern" >> "$gitignore_file"
fi
return
}
function set_gitignore()
{
for p in "# docker-template / docker-template-wrapper files" \
"Gemfile" \
"Gemfile.lock" \
".bundle/" \
"vendor/" \
"**/cache/"; do
write_gitignore_line "${PWD}/.gitignore" $p
done
return
}
function setup()
{
log info "Executing from ${PWD}"
command_exists gem || { log error "Ruby or Gem not found. Please install Ruby 2.1+ before proceeding." ; exit $E_MISSING_DEPENDENCY; }
command_exists bundler || install_bundler
if [ ! "$DOCKER_TEMPLATE" == "gem" ]; then
install_docker_template_bundler
else
install_docker_template_gem
fi
set_gitignore
return
}
################################################################################
#### main
################################################################################
DIR=$(dirname $(readlink -f $0))
# includes ./env.sh that resolve environment variables and add default functions
. ${DIR}/env.sh
for arg in $@; do
case $arg in
--gem | -g)
DOCKER_TEMPLATE="gem"
shift
;;
-*)
# Any remaining / not parsed option (arg starting with '--' | '-') is consider invalid
exit_invalid_option "$arg"
;;
esac
done
# set working dir PROJECT_PATH (resolved by ./env.sh) to setup
cd "$PROJECT_PATH"
setup "$@"