-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathensure_env_bootstrapped.sh
executable file
·89 lines (67 loc) · 1.88 KB
/
ensure_env_bootstrapped.sh
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
#!/usr/bin/env sh
################################################################################
# Helpers
################################################################################
function error() {
local -r msg="${1}"
echo "ERROR: ${msg}"
}
function info() {
local -r msg="${1}"
echo "> ${msg}"
}
function die() {
error "Exiting..."
exit 1
}
function die_with_message() {
local -r msg="${1}"
error "${msg}"
die
}
function is_installed() {
local cmd="${1}"
command -v "${cmd}" >/dev/null 2>&1
}
function ensure_installed() {
local cmd="${1}"
if ! is_installed "${cmd}"; then
die_with_message "'${cmd}' is not installed, but is required"
fi
}
function ensure_correct_ruby() {
local -r target_ruby_version=$( cat .ruby-version )
local -r actual_ruby_version=$( ruby -e "puts RUBY_VERSION" )
if [ "${target_ruby_version}" != "${actual_ruby_version}" ]; then
die_with_message "Your version of ruby [${actual_ruby_version}] is different than the required version [${target_ruby_version}]"
fi
}
function ensure_bundle_install() {
if ! bundle check >/dev/null; then
if bundle install; then
echo
else
echo '--------------------------------------------------------------------------------'
error 'Bundle install failed'
error 'Please reach out for help on odevs slack so we can update this script'
die
fi
fi
}
function print_success_msg() {
info 'Looks like your environment is setup correctly!'
info
info 'You should now be able to begin work with:'
info ' bundle exec jekyll serve'
}
################################################################################
# DO WORK SON
################################################################################
function main() {
ensure_installed ruby
ensure_correct_ruby
ensure_installed bundle
ensure_bundle_install
print_success_msg
}
main