-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.sh
120 lines (97 loc) · 2.6 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
#!/bin/sh
# to setup vm : wget https://raw.github.com/motech/motech-scm/master/bootstrap.sh && sh ./bootstrap.sh
#parameters:
# config=path/to/config/file
# debug=true
# help
#Globals:
CONFIG_FILE=$1
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 motech 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
}
getMotechSCM() {
cd /tmp/
if [ ! -d /tmp/motech-scm/ ]; then
git clone git://github.com/motech/motech-scm.git
else
cd /tmp/motech-scm/ && git reset --hard && git pull --rebase && cd /tmp/
fi
}
setupPuppetConfiguration() {
cd /tmp/motech-scm/puppet
if [ -f $CONFIG_FILE ]; then
cp $CONFIG_FILE manifests/nodes/configuration.pp
else
vi manifests/nodes/configuration.pp
fi
}
puppetApply() {
cd /tmp/motech-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
}
_main_() {
ensurePuppetInstallation
setConfigFileAbsolutePath
installGit
getMotechSCM
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_
#############################