-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
246 lines (176 loc) · 5.9 KB
/
setup
File metadata and controls
246 lines (176 loc) · 5.9 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
IPADDRESS=192.168.56.101
NETMASK=255.255.255.0
INTERFACE=eth1
PROJECT_NAME=Tester #no spaces!
FILESURL=https://raw.githubusercontent.com/draftchallenge/continuous-integration-setup/master/
WITH_PAUSE_AFTER_EACH_STEP=true
#####################################################################################
#see bottom first
#####################################################################################
checkPermissions() {
if [[ $EUID -ne 0 ]]; then
exitWithError "This script must run as root"
fi
}
addJenkinsToAptList() {
echo "01/11 Adding Jenkins to apt repository"
file=/etc/apt/sources.list.d/jenkins.list
rm -f $file
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
echo "deb http://pkg.jenkins-ci.org/debian binary/" > $file
pause
}
installPackages() {
echo "02/11 Installing updates and packages - please be patient"
apt-get -q update
apt-get -q -y --force-yes install openjdk-7-jdk subversion apache2 libapache2-svn python-setuptools libapache2-mod-python enscript jenkins trac sqlite3 openssh-server
#apt-get -q -y --force-yes install openjdk-7-jdk subversion apache2=2.2.22-1ubuntu1.5 libapache2-svn python-setuptools libapache2-mod-python enscript jenkins=1.557 trac=0.12.2-1build1 sqlite3 openssh-server
pause
}
getFilesFromGithub() {
echo "03/11 Downloading files from Github for setup"
rm -rf files/
rm -f adduser
rm -f rollback
mkdir -p files/
local files=( "/apache_dav_svn.conf" "/apache_jenkins" "/apache_ports.conf" "/apache_python.conf" "/default_jenkins" "/svn_post-commit" "/svn_trac-hook" "/www_index.html" )
for i in "${files[@]}"
do
wget -q $FILESURL"files"$i -O "files/$i"
done
wget -q $FILESURL"adduser" -O adduser
wget -q $FILESURL"rollback" -O rollback
pause
}
prepareLocalNetwork() {
echo "04/11 Preparing local host only network at $INTERFACE with $IPADDRESS"
ifconfig $INTERFACE $IPADDRESS netmask $NETMASK
file="/etc/ssh/sshd_config"
restoreFromBakFileIfExisitsAndCreate $file
echo "ListenAddress $IPADDRESS" >> $file
echo "ListenAddress 127.0.0.1" >> $file
pause
}
prepareApache() {
echo "05/11 Preparing Apache with mods, index file and ports"
a2enmod proxy
a2enmod proxy_http
a2enmod rewrite
cp files/www_index.html /var/www/index.html
chown www-data:www-data /var/www/index.html
file=/etc/apache2/ports.conf
restoreFromBakFileIfExisitsAndCreate $file
cp files/apache_ports.conf $file
sed -i "s/IPADDRESS/$IPADDRESS/g" $file
pause
}
prepareDAV() {
echo "06/11 Preparing DAV for login and other services"
file=/etc/apache2/mods-enabled/dav_svn.conf
restoreFromBakFileIfExisitsAndCreate $file
cp files/apache_dav_svn.conf $file
chown www-data:www-data $file
touch /etc/apache2/dav_svn.passwd
pause
}
prepareSubversion() {
echo "07/11 Preparing Subversion and Hooks to Trac and Jenkins"
dir=/var/svn
rm -rf $dir
mkdir $dir
svnadmin create $dir/repos
chown -R www-data:www-data $dir
prepareHook $dir post-commit
prepareHook $dir trac-hook
echo "http://localhost/jenkins/job/$PROJECT_NAME/build" >> $dir/repos/hooks/post-commit
pause
}
prepareTrac() {
echo "08/11 Prepare Trac and connect to SVN and Apache"
dir=/var/www/trac/repos
rm -rf $dir
mkdir -p $dir
trac-admin $dir initenv "$PROJECT_NAME" sqlite:db/trac.db svn /var/svn/repos
chown -R www-data.www-data /var/www/trac
cp files/apache_python.conf /etc/apache2/mods-enabled/python.conf
chown root:root /etc/apache2/mods-enabled/python.conf
pause
}
prepareJenkins() {
echo "09/11 Prepare Jenkins and disable default site, enable jenkins site"
rm -f /etc/apache2/sites-available/jenkins
cp files/default_jenkins /etc/default/jenkins
cp files/apache_jenkins /etc/apache2/sites-available/jenkins
a2dissite default
a2ensite jenkins
pause
}
restartServices() {
echo "10/11 Restart services"
service jenkins restart
service apache2 restart
service ssh restart
pause
}
testSetup() {
echo "11/11 Verifying setup - be patient as script needs to wait (30s) until all services are running"
sleep 30
netstat=`netstat -tunl`
checkService "$netstat" "127.0.0.1:22"
checkService "$netstat" "$IPADDRESS:22"
checkService "$netstat" "127.0.0.1:80"
checkService "$netstat" "$IPADDRESS:80"
checkService "$netstat" "127.0.0.1:8080"
checkHTTP http://localhost/ "HTTP/1.1 200 OK"
checkHTTP http://localhost/jenkins/ "HTTP/1.1 401 Authorization Required"
checkHTTP http://localhost/svn/ "HTTP/1.1 401 Authorization Required"
checkHTTP http://localhost/trac/ "HTTP/1.1 401 Authorization Required"
rm -rf files/
echo "...Done."
echo "Don't forget to run 'bash ./adduser <User name>' to add users for authentication."
}
pause() {
if [ "$WITH_PAUSE_AFTER_EACH_STEP" = true ]; then
read -p "Done. Press [Enter] key to continue"
fi
}
prepareHook() {
cp files/svn_$2 $1/repos/hooks/$2
chown www-data:www-data $1/repos/hooks/$2
chmod +x $1/repos/hooks/$2
}
checkService() {
if [[ ! $1 =~ $2 ]]; then
exitWithError "Setup was not correct: $2 is not running"
fi
}
checkHTTP() {
result=`curl -sI $1`
if [[ ! "$result" == "$2"* ]]; then
exitWithError "Setup was not correct: $1 is not OK"
fi
}
restoreFromBakFileIfExisitsAndCreate() {
if [ -f "$1.bak" ]; then
cp "$1".bak "$1"
fi
cp "$1" "$1".bak
}
exitWithError() {
echo "$1" 1>&2
echo "...Abort" 1>&2
exit 1
}
checkPermissions
addJenkinsToAptList
installPackages
getFilesFromGithub
prepareLocalNetwork
prepareApache
prepareDAV
prepareSubversion
prepareTrac
prepareJenkins
restartServices
testSetup