-
Notifications
You must be signed in to change notification settings - Fork 19
/
bootstrap.sh
126 lines (102 loc) · 2.66 KB
/
bootstrap.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
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
#!/bin/sh
# to setup vm :
# $ wget https://raw.github.com/jss-emr/jss-scm/master/bootstrap.sh
# $ chmod +x bootstrap.sh
# $ sudo ./bootstrap.sh
#parameters:
# config=path/to/config/file
# debug=true
# help
#Globals:
CONFIG_FILE=
DEBUG="false"
usage() {
echo "**** HELP ****"
echo "Two main options: -c & -d"
echo ""
echo "./bootstrap.sh -c path/to/configuration.pp"
echo " This will run bootstrap the box with jss software according to configuration.pp"
echo ""
echo "./bootstrap.sh -d"
echo " This will run apply configuration via puppet in debug mode"
echo ""
echo "./bootstrap.sh -dc path/to/configuration.pp"
echo " You can provide both option parameters together"
echo ""
echo "./bootstrap.sh"
echo " Running without config (-c) option allows you to manually edit (via vi editor) the default configuration.pp before puppet apply"
echo ""
echo "./bootstrap.sh -h"
echo " Prints this"
}
ensurePuppetInstallation(){
if ! type puppet > /dev/null 2>&1
then
arch=`uname -m`
epelFileName=`curl --location 'http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/'$arch'/' | grep epel-release | sed -e 's/^.*\(epel.*rpm\).*$/\1/g'`
rpmUrl="http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/$arch/$epelFileName"
cd /tmp && rpm -ivh "$rpmUrl"
yum -y install puppet
fi
}
setConfigFileAbsolutePath() {
locationPathFromRoot=`echo $CONFIG_FILE | cut -c 1 | grep / | wc -l`
if [ $locationPathFromRoot -eq 0 ]; then
CONFIG_FILE=`pwd`/$CONFIG_FILE
fi
}
installGit() {
yum -y install git
}
getJssSCM() {
cd /tmp/
if [ ! -d /tmp/jss-scm/ ]; then
git clone git://github.com/jss-emr/jss-scm.git
else
cd /tmp/jss-scm/ && git reset --hard && git clean -fd && git pull --rebase && cd /tmp/
fi
chmod -R a+w /tmp/jss-scm/
}
setupPuppetConfiguration() {
cd /tmp/jss-scm/puppet
if [ -f $CONFIG_FILE ]; then
cp $CONFIG_FILE manifests/nodes/configuration.pp
else
vi manifests/nodes/configuration.pp
fi
}
puppetApply() {
cd /tmp/jss-scm/puppet
if [ "$DEBUG" = "true" ]; then
puppet apply manifests/site.pp --debug --modulepath=modules/ && echo "Completed"
else
puppet apply manifests/site.pp --modulepath=modules/ && echo "Completed"
fi
}
set -x
_main_() {
ensurePuppetInstallation
setConfigFileAbsolutePath
installGit
getJssSCM
setupPuppetConfiguration
puppetApply
}
######### _main_ call #########
while getopts "c:dh" OPTION
do
case $OPTION in
'c')
CONFIG_FILE=$OPTARG
;;
'd')
DEBUG="true"
;;
'h')
usage
exit 0
;;
esac
done
_main_
#############################