-
-
Notifications
You must be signed in to change notification settings - Fork 909
/
Copy pathsetup
executable file
·286 lines (234 loc) · 6.85 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env bash
set -euo pipefail
### PROJECT SETUP ##############################################################
# Feel free to add whatever functions or variables you want to add in this
# section. You may also delete this section altogether if your project doesn't
# need a custom setup.
provision-project() {
banner "Installing Appraisals"
bundle exec appraisal install
}
### DON'T MODIFY ANYTHING BELOW THIS LINE! #####################################
# This setup script was generated with setup_script_generator 0.3.1,
# available on RubyGems.
#
# To regenerate this section, install the gem and run:
#
# generate-setup -p ruby
#
# --- SETUP --------------------------------------------------------------------
something_already_printed=0
determine-platform() {
local uname=$(uname)
if [[ $uname == 'Darwin' ]]; then
echo 'mac'
else
echo 'linux'
fi
}
banner() {
print-with-color 34 "== $@ =="
}
success() {
print-with-color 32 "$@"
}
warning() {
print-with-color 33 "$@"
}
error() {
print-with-color 31 "$@"
}
print-with-color() {
pad-from-existing-output
echo -ne "\033[${1}m"
echo -n "${@:2}"
echo -e "\033[0m"
something_already_printed=1
}
print-wrapped() {
pad-from-existing-output
echo -n "$@" | fmt -w 80 | cat
something_already_printed=1
}
pad-from-existing-output() {
if [[ $something_already_printed -eq 1 ]]; then
echo
fi
}
print() {
pad-from-existing-output
echo "$@"
something_already_printed=1
}
has-executable() {
type "$1" &>/dev/null
}
is-running() {
pgrep "$1" >/dev/null
}
start() {
if has-executable brew; then
brew services start "$1"
else
sudo service "${2:-$1}" start
fi
}
install() {
local apt_package=""
local rpm_package=""
local brew_package=""
local default_package=""
local package=""
for arg in "$@"; do
case $arg in
apt=*)
apt_package="${arg#apt=}"
;;
rpm=*)
rpm_package="${arg#rpm=}"
;;
brew=*)
brew_package="${arg#brew=}"
;;
*)
default_package="$arg"
;;
esac
done
if has-executable brew; then
package="${brew_package:-$default_package}"
if [[ -n $package ]]; then
brew install "$package"
fi
elif has-executable apt-get; then
package="${apt_package:-$default_package}"
if [[ -n $package ]]; then
sudo apt-get install -y "$package"
fi
elif has-executable yum; then
package="${rpm_package:-$default_package}"
if [[ -n $package ]]; then
sudo yum install -y "$package"
fi
else
error "Sorry, I'm not sure how to install $default_package."
exit 1
fi
}
check-for-package-manager() {
local platform=$(determine-platform)
if [[ $platform == "linux" ]] && ! has-executable apt-get && ! has-executable yum; then
# TODO: Check if build-essential is installed on Debian?
# TODO: Check if 'Development Tools' group is installed on RedHat?
error "You don't seem to have a package manager installed."
print-wrapped "\
This setup script assumes you're using a flavor of Linux derived from Debian or
RedHat (i.e. something with Apt or Yum). If this is not the case, then we would
gladly take a PR fixing this!"
exit 1
elif [[ $platform == "mac" ]] && ! has-executable brew; then
# TODO: Check that OS X Command Line Tools are installed?
error "You don't seem to have Homebrew installed."
print-wrapped "\
Visit <https://brew.sh> and follow the instructions there, then re-run this
script."
exit 1
fi
}
install-development-libraries() {
install rpm=zlib-devel
}
setup() {
cd "$(dirname "$(dirname "$0")")"
check-for-package-manager
install-development-libraries
run-provisions
if type provision-project &>/dev/null; then
provision-project
fi
success "Setup complete!"
}
# --- RUBY ---------------------------------------------------------------------
provision-ruby() {
if [[ -f .tool-versions ]]; then
REQUIRED_RUBY_VERSION=$(cat .tool-versions | grep '^ruby ' | head -n 1 | sed -Ee 's/^ruby (.+)$/\1/')
elif [[ -f .ruby-version ]]; then
REQUIRED_RUBY_VERSION=$(cat .ruby-version | head -n 1 | sed -Ee 's/^ruby-([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)$/\1/')
fi
if [[ -z $REQUIRED_RUBY_VERSION ]]; then
error "Could not determine required Ruby version for this project."
print-wrapped "\
Your project needs to include either a valid .tool-versions file with a 'ruby'
line or a valid .ruby-version file."
exit 1
fi
ensure-ruby-development-libraries-installed
ensure-ruby-installed
if [[ -f Gemfile ]]; then
ensure-project-ruby-dependencies-installed
fi
}
ensure-ruby-development-libraries-installed() {
local platform=$(determine-platform)
if [[ $platform == "linux" ]]; then
banner "Installing Ruby development libraries"
install apt=ruby-dev rpm=ruby-devel
fi
}
ensure-ruby-installed() {
if has-executable asdf; then
if ! (asdf current ruby | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
banner "Installing Ruby $REQUIRED_RUBY_VERSION with asdf"
asdf install ruby $REQUIRED_RUBY_VERSION
fi
elif has-executable rbenv; then
if ! (rbenv versions | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
banner "Installing Ruby $REQUIRED_RUBY_VERSION with rbenv"
rbenv install --skip-existing "$REQUIRED_RUBY_VERSION"
fi
elif has-executable chruby-exec; then
if [ -f /usr/local/share/chruby/chruby.sh ]; then
CHRUBY_SH=/usr/local/share/chruby/chruby.sh
elif [ -f /opt/homebrew/share/chruby/chruby.sh ]; then
CHRUBY_SH=/opt/homebrew/share/chruby/chruby.sh
fi
if [ -z "$CHRUBY_SH" ]; then
error "chruby-exec detected, but could not find chruby.sh for loading"
exit 1
fi
PREFIX='' source $CHRUBY_SH
if ! (chruby '' | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
if has-executable install-ruby; then
banner "Installing Ruby $REQUIRED_RUBY_VERSION with install-ruby"
install-ruby "$REQUIRED_RUBY_VERSION"
else
error "Please use chruby to install Ruby $REQUIRED_RUBY_VERSION!"
fi
fi
elif has-executable rvm; then
if ! (rvm list | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
banner "Installing Ruby $REQUIRED_RUBY_VERSION with rvm"
rvm install $REQUIRED_RUBY_VERSION
fi
else
error "You don't seem to have a Ruby manager installed."
print-wrapped "\
We recommend using asdf. You can find instructions to install it here:
https://asdf-vm.com
When you're done, close and re-open this terminal tab and re-run this script."
exit 1
fi
}
has-bundler() {
has-executable bundle && bundle -v &>/dev/null
}
ensure-project-ruby-dependencies-installed() {
banner 'Installing Ruby dependencies'
gem install bundler
bundle check || bundle install
}
run-provisions() {
provision-ruby
}
# --- FIN ----------------------------------------------------------------------
setup