-
Notifications
You must be signed in to change notification settings - Fork 2
/
local-puppet-adm
executable file
·113 lines (96 loc) · 3.54 KB
/
local-puppet-adm
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
#!/bin/bash
# This is the univerasl do-stuff with Puppet script.
# It can:
# * setup a Puppet environment for you
# * generate module boilerplate for you
#
# The module boilerplate comes in two forms:
# * pcs: package, configuration, service
# * plain: default layout the Puppet Module Tool creates.
#
# It will default to the 'pcs' template as that is the preferred layout when
# managing a service on a host. The necessary files and directories will be
# created and some initial manifests populated with sane defaults.
#
# A test structure will be created for you if it detects rspec-puppet in your
# environment. If not, it will nag you about it for you should be testing your
# modules.
requirements_puppet () {
command -v ruby >/dev/null 2>&1 || error "Really now, no Ruby?! Install Ruby and Rubygems first!" 1
command -v gem >/dev/null 2>&1 || error "Ruby but no gem, install Rubygems first!" 1
command -v bundle >/dev/null 2>&1 || warn "Bundle is not installed, I'll try and do that for you..."; BUNDLE_INSTALL=1;
command -v chgems >/dev/null 2>&1 && CHGEMS=1 || CHGEMS=0
ruby_versions=("1.8.7" "1.9.3")
if ! inarray "$(ruby -v)" "${ruby_versions[@]}";then
error "Sorry, we need Ruby one of the following Ruby versions since that's what Puppet runs in production and for CI: $(IFS=,;printf %s "${ruby_versions[*]}")." 1
fi
}
requirements_module () {
command -v puppet >/dev/null 2>&1 || error "Could not find Puppet on your system, exiting" 1
command -v rspec-puppet-init >/dev/null 2>&1 || error "Could not detect rspec-puppet, you ought to get into testing!" 1
}
# Load daenney's awesomesauce libshellfunc
for x in puppet-shell-scripts/libshellfunc/*;do source $x;done
# Allow for longer output lines
LIBSF_JUSTIFY=120
setup_environment () {
if test $# -gt 0; then
error "setup doesn't take any arguments." 1
fi
requirements_puppet
if [ ${BUNDLE_INSTALL} -eq 1 ];
then
check_exit "gem install bundler" "Something went really wrong installing bundler. Please fix this!"
fi
info "Running ${YLW}bundle install${RESET} in your environment."
if [ ${CHGEMS} -eq 1 ];
then
check_exit "bundle install" "Failed to install the bundle" do_exit=true
warn "Don't forget to run ${YLW}chgems${RESET} before doing anything!"
else
check_exit "bundle install --binstubs" "Failed to install the gems and generate binstubs" do_exit=true
fi
info "Linking the pre-commit hook."
ln -nfs /data/git/alex/scripts/puppet-shell-scripts/pre-commit /data/git/nedap/puppet/.git/hooks
info "For vim, install the following plugins:"
info "... • scrooloose/${YLW}syntastic${RESET}"
info "... • godlygeek/${YLW}tabular${RESET}"
info "... • daenney/${YLW}vim-puppet${RESET}"
info "Now ${RED}read${RESET} the docs"
info "... write ${RED}decent${RESET} commit messages,"
info "write ${RED}complete, working${RESET} tests and"
info "${RED}don't disable${RESET} the pre-commit hook."
info "Hurray, we're done!"
exit 0
}
create_module () {
info "${YLW}This is done by cloning the following repo:${RESET}"
info "${YLW}Replace this with this template:${RESET}"
info "${YLW}https://github.com/garethr/puppet-module-skeleton${RESET}"
info "${YLW}Then '${GREEN}puppet module generate' creates a proper module.${RESET}"
exit 0
}
display_help () {
echo "boe"
}
while test $# -gt 0; do
case $1 in
setup)
shift
setup_environment ${@}
;;
module)
shift
create_module ${@}
;;
help)
display_help
shift
;;
*)
display_help
shift
;;
esac
shift
done