forked from pivotal-sprout/sprout-wrap
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprout
executable file
·120 lines (102 loc) · 3.97 KB
/
sprout
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
#!/usr/bin/env bash
REPO_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -e
function check_sprout_locked_ruby_versions() {
# Check locked versions
sprout_ruby_version=$(cat "${REPO_BASE}/.ruby-version" | tr -d '\n')
sprout_ruby_gemset=$(cat "${REPO_BASE}/.ruby-gemset" | tr -d '\n')
sprout_rubygems_ver=$(cat "${REPO_BASE}/.rubygems-version" | tr -d '\n') ## Passed to gem update --system
sprout_bundler_ver=$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1 | tr -d '[:blank:]')
}
function load_rvm() {
if ! type rvm 2>&1 | grep -q 'rvm is a function' ; then
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
fi
}
function use_local_gems() {
SPROUT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export SPROUT_HOME
current_ruby=$(which ruby)
if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
load_rvm
current_rvm_ruby=$(rvm current 2>/dev/null)
check_sprout_locked_ruby_versions
if [[ "$current_rvm_ruby" != "ruby-${sprout_ruby_version}@${sprout_ruby_gemset}" ]]; then
echo -e "\033[33mWarning: current ruby '${current_ruby}' is not the same as locked [email protected] = 'ruby-${sprout_ruby_version}@${sprout_ruby_gemset}' \033[0m"
if rvm list rubies 2>/dev/null | grep -q "ruby-${sprout_ruby_version}" ; then
echo -e "\033[93mWarning: Changing RVM ruby to 'ruby-${sprout_ruby_version}@${sprout_ruby_gemset}' \033[0m"
rvm use ruby-${sprout_ruby_version}@${sprout_ruby_gemset} --create
else
echo -e "\033[31mError: Currently supported ruby-${sprout_ruby_version}@${sprout_ruby_gemset} not found!\033[0m"
echo -e "\033[96mInfo: Did you forget to run ./bootstrap-scripts/bootstrap.sh ?!\033[0m"
echo -e "\033[31mError: Could not find a supported version of ruby; Exiting...\033[0m"
exit 1
fi
fi
elif [ "${current_ruby}" == '/usr/bin/ruby' ]; then
echo -e "\033[31mWarning: sprout should NO LONGER be run with system ruby; using '${current_ruby}'\033[0m"
echo -e "\033[31mWarning: Please review https://dontusesystemruby.com/ \033[0m"
echo ""
echo -e "\033[31mWarning: Continuing onwards... yet here be dragons! I assume you know what youre doing?\033[0m"
export GEM_HOME="${SPROUT_HOME}/tmp/ruby/2.0.0"
export GEM_PATH="${GEM_HOME}"
export PATH="${GEM_HOME}/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
else
echo -e "\033[31mWarning: Could not find a supported version of ruby; Exiting...\033[0m"
echo -e "\033[96mInfo: Did you forget to run ./bootstrap-scripts/bootstrap.sh ?!\033[0m"
exit 1
fi
echo "# - Using $(${current_ruby} -v)"
}
function ensure_in_sprout_home() {
if [ "${SPROUT_HOME}" != "$(pwd)" ]; then
echo "\033[91mError: sprout must be run from ${SPROUT_HOME}\033[0m"
exit 1
fi
}
function bundle_exec() {
if bundler_installed; then
echo "# - Using $(bundle -v)"
else
gem install bundler --no-document
fi
if bundle check > /dev/null 2>&1; then
echo '# - Gemfile dependencies satisfied'
else
bundle install --jobs 6
fi
bundle exec "${@}"
}
function bundler_installed() {
command -v bundle > /dev/null
}
function update_resources() {
gem install bundler --no-document
bundle update
bundle exec librarian-chef update
}
function main() {
use_local_gems
ensure_in_sprout_home
case "${1}" in
'')
export LOG_LEVEL="warn" # make chef less noisy
bundle_exec soloist
;;
exec)
shift
bundle_exec "${@}"
;;
update)
update_resources
;;
*)
echo "Usage:"
echo " sprout - install dependencies and run 'soloist'"
echo " sprout exec some cmd - run 'some cmd' in this cookbooks's bundler context"
echo " sprout update: - update gems and cookbook dependencies"
esac
}
main "${@}"