This repository has been archived by the owner on Jul 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
sprout
executable file
·76 lines (64 loc) · 1.71 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
#!/usr/bin/env bash
set -e
function use_local_gems() {
SPROUT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export SPROUT_HOME
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"
current_ruby=$(which ruby)
if [ "${current_ruby}" != '/usr/bin/ruby' ]; then
echo -e "\033[31mWarning: sprout should be run with system ruby; using '${current_ruby}'\033[0m"
fi
echo "# - Using $(${current_ruby} -v)"
}
function ensure_in_sprout_home() {
if [ "${SPROUT_HOME}" != "$(pwd)" ]; then
echo "Error: sprout must be run from ${SPROUT_HOME}"
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 "${@}"