update_jdn.sh 17.8 KB
Newer Older
1
2
#!/bin/bash

Philip Hands's avatar
set -e    
Philip Hands committed
3
4
set -e

5
# Copyright 2012-2016 Holger Levsen <holger@layer-acht.org>
6
7
# released under the GPLv=2

Holger Levsen's avatar
Holger Levsen committed
8
BASEDIR=$HOME/jenkins.debian.net
9
10
PVNAME=/dev/vdb      # LVM physical volume for jobs
VGNAME=jenkins01     # LVM volume group
11
STAMP=/var/log/jenkins/update-jenkins.stamp
12
TMPFILE=$(mktemp)
13
14
15
# The $@ below means that command line args get passed on to j-j-b
# which allows one to specify --flush-cache or --ignore-cache
JJB="jenkins-job-builder $@"
Holger Levsen's avatar
Holger Levsen committed
16

17
# so we can later run some commands only if $0 has been updated…
Holger Levsen's avatar
Holger Levsen committed
18
if [ ! -f $STAMP ] && [ $BASEDIR/$0 -nt $STAMP ] ; then
19
20
21
22
23
24
	UPTODATE=false
else
	UPTODATE=true
fi


Holger Levsen's avatar
Holger Levsen committed
25
explain() {
Holger Levsen's avatar
Holger Levsen committed
26
	echo "$HOSTNAME: $1"
Holger Levsen's avatar
Holger Levsen committed
27
28
}

29
30


31
echo "--------------------------------------------"
Holger Levsen's avatar
Holger Levsen committed
32
explain "$(date) - begin deployment update."
33
34
35

# run update at current date
case $HOSTNAME in
36
	profitbricks-build4-amd64|profitbricks-build5-amd64|profitbricks-build6-i386)
37
38
		# set correct date (if ntpdate is installed)
		[ ! -f /usr/sbin/ntpdate ] || sudo ntpdate -b de.pool.ntp.org
39
40
41
42
		;;
	*)	;;
esac

43
44
45
#
# set up users and groups
#
46
if ! getent passwd jenkins > /dev/null ; then
47
	sudo addgroup --system jenkins
48
	sudo adduser --system --shell /bin/bash --home /var/lib/jenkins --ingroup jenkins --disabled-login jenkins
49
fi
Holger Levsen's avatar
Holger Levsen committed
50
if ! getent group jenkins-adm > /dev/null ; then
51
52
	sudo addgroup --system jenkins-adm
fi
53
if ! getent passwd jenkins-adm > /dev/null  ; then
54
	sudo adduser --system --shell /bin/bash --no-create-home --ingroup jenkins-adm --disabled-login --no-create-home jenkins-adm
Holger Levsen's avatar
Holger Levsen committed
55
	sudo usermod -G jenkins jenkins-adm
56
fi
57
for user in helmut holger mattia lunar phil ; do
58
59
60
61
	if [ "$user" = "lunar" ] && [ "$HOSTNAME" != "jenkins" ] ; then
		# lunar only wants to configure jekyll
		continue
	fi
62
	if [ "$user" = "phil" ] && [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
Philip Hands's avatar
Philip Hands committed
63
64
65
66
		# phil only wants to test stuff
		sudo adduser $user libvirt
		sudo adduser $user libvirt-qemu
		continue
67
68
	elif [ "$user" = "phil" ] && ( ! [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ) ; then
		# create phil on jenkins and jenkins-test-vm only
Holger Levsen's avatar
Holger Levsen committed
69
70
		continue
	fi
71
	# actually create the user
72
	if ! getent passwd $user > /dev/null ; then
73
		if [ "$user" = "mattia" ] ; then
74
			usershell=/bin/zsh
75
		else
76
			usershell=/bin/bash
77
		fi
78
		sudo adduser --gecos "" --shell "$usershell" --disabled-password $user
79
	fi
80
81
82
83
84
85
86
87
88
	# put user in groups
	if [ "$HOSTNAME" = "jenkins" ] && [ "$user" = "lunar" ] ; then
		extra_groups="reproducible"
	elif [ "$HOSTNAME" = "jenkins" ] ; then
		extra_groups="reproducible,jenkins,jenkins-adm,sudo,adm"
	else
		extra_groups="jenkins,jenkins-adm,sudo,adm"
	fi
	sudo usermod -G $extra_groups $user
89
90
done

91
if [ "$HOSTNAME" = "jenkins-test-vm" ] || [ "$HOSTNAME" = "profitbricks-build10-amd64" ] ; then
92
93
94
95
96
	# jenkins needs access to libvirt
	sudo adduser jenkins libvirt
	sudo adduser jenkins libvirt-qemu
fi

97
sudo mkdir -p /srv/workspace
98
[ -d /srv/schroots ] || sudo mkdir -p /srv/schroots
99
[ -h /chroots ] || sudo ln -s /srv/workspace/chroots /chroots
100
[ -h /schroots ] || sudo ln -s /srv/schroots /schroots
101

102
103
# prepare tmpfs on some hosts
case $HOSTNAME in
Mattia Rizzolo's avatar
Mattia Rizzolo committed
104
105
106
107
	jenkins)
		TMPFSSIZE=100
		TMPSIZE=15
		;;
Holger Levsen's avatar
Holger Levsen committed
108
	profitbricks-build9-amd64)
Mattia Rizzolo's avatar
Mattia Rizzolo committed
109
110
111
		TMPFSSIZE=32
		TMPSIZE=8
		;;
Holger Levsen's avatar
Holger Levsen committed
112
	profitbricks-build*)
Mattia Rizzolo's avatar
Mattia Rizzolo committed
113
114
115
		TMPFSSIZE=200
		TMPSIZE=15
		;;
116
117
118
	*) ;;
esac
case $HOSTNAME in
119
120
121
122
123
124
125
	profitbricks-build*i386)
		if ! grep -q '/srv/workspace' /etc/fstab; then
			echo "Warning: you need to manually create a /srv/workspace partition on i386 nodes, exiting."
			exit 1
		fi
		;;
	jenkins|profitbricks-build*amd64)
126
		if ! grep -q '^tmpfs\s\+/srv/workspace\s' /etc/fstab; then
127
			echo "tmpfs		/srv/workspace	tmpfs	defaults,size=${TMPFSSIZE}g	0	0" | sudo tee -a /etc/fstab >/dev/null  
128
		fi
Mattia Rizzolo's avatar
Mattia Rizzolo committed
129
130
131
		if ! grep -q '^tmpfs\s\+/tmp\s' /etc/fstab; then
			echo "tmpfs		/tmp	tmpfs	defaults,size=${TMPSIZE}g	0	0" | sudo tee -a /etc/fstab >/dev/null
		fi
132
133
		if ! mountpoint -q /srv/workspace; then
			if test -z "$(ls -A /srv/workspace)"; then
134
				sudo mount /srv/workspace
135
			else
136
				explain "WARNING: mountpoint /srv/workspace is non-empty."
137
138
139
140
141
			fi
		fi
		;;
	*) ;;
esac
142

143
# make sure needed directories exists - some directories will not be needed on all hosts...
144
for directory in /schroots /srv/reproducible-results /srv/d-i /srv/udebs /srv/live-build /var/log/jenkins/ /srv/jenkins /srv/jenkins/pseudo-hosts /srv/workspace/chroots ; do
145
146
147
	if [ ! -d $directory ] ; then
		sudo mkdir $directory
	fi
Holger Levsen's avatar
Holger Levsen committed
148
	sudo chown jenkins.jenkins $directory
149
done
Holger Levsen's avatar
Holger Levsen committed
150
for directory in /srv/jenkins ; do
151
152
153
154
155
	if [ ! -d $directory ] ; then
		sudo mkdir $directory
		sudo chown jenkins-adm.jenkins-adm $directory
	fi
done
156

157
if ! test -h /chroots; then
Holger Levsen's avatar
Holger Levsen committed
158
	sudo rmdir /chroots || sudo rm -f /chroots # do not recurse
159
	if test -e /chroots; then
Holger Levsen's avatar
Holger Levsen committed
160
		explain "/chroots could not be cleared."
161
	else
162
		sudo ln -s /srv/workspace/chroots /chroots
163
164
165
	fi
fi

166
167
168
169
170
171
# only on Debian systems
if [ -f /etc/debian_version ] ; then
	#
	# install packages we need
	#
	if [ ./$0 -nt $STAMP ] || [ ! -f $STAMP ] ; then
Holger Levsen's avatar
Holger Levsen committed
172
173
		DEBS=" 
			bash-completion 
174
175
			bc
			bsd-mailx
Holger Levsen's avatar
Holger Levsen committed
176
177
			curl 
			debootstrap 
178
179
			devscripts
			eatmydata
180
			etckeeper
181
			figlet
Holger Levsen's avatar
Holger Levsen committed
182
			git
183
			haveged
Holger Levsen's avatar
Holger Levsen committed
184
			htop
185
			less
186
			locales-all
187
188
			molly-guard
			moreutils
189
			munin-node
190
191
			munin-plugins-extra
			netcat-traditional
192
			pigz 
193
			postfix
194
			procmail
195
			psmisc
196
			python3-psycopg2 
Holger Levsen's avatar
Holger Levsen committed
197
			schroot 
198
199
			screen
			slay
Holger Levsen's avatar
Holger Levsen committed
200
201
202
203
204
			subversion 
			subversion-tools 
			sudo 
			unzip 
			vim 
205
			zsh
206
			"
207
		# install squid everywhere except on the armhf nodes
208
		case $HOSTNAME in
209
			jenkins|jenkins-test-vm|profitbricks-build*) DEBS="$DEBS
210
211
				squid3"
			   ;;
212
213
			*) ;;
		esac
214
215
		# needed to run the 2nd reproducible builds nodes in the future...
		case $HOSTNAME in
216
			profitbricks-build4-amd64|profitbricks-build5-amd64|profitbricks-build6-i386) DEBS="$DEBS ntpdate" ;;
217
218
			*) ;;
		esac
219
		# needed to run coreboot/openwrt/netbsd/fedora/fdroid jobs
220
		case $HOSTNAME in
221
			profitbricks-build3-amd64|profitbricks-build4-amd64) DEBS="$DEBS
Holger Levsen's avatar
Holger Levsen committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
				bison
				cmake
				diffutils
				findutils
				flex
				g++
				gawk
				gcc
				git
				grep
				iasl
				libc6-dev
				libncurses5-dev
				libssl-dev
				locales-all
				kgb-client
				m4
				make
				python3-yaml
				subversion
242
				sysvinit-core
243
				tree
Holger Levsen's avatar
Holger Levsen committed
244
245
				unzip
				util-linux
246
				vagrant
247
				virtualbox
Holger Levsen's avatar
Holger Levsen committed
248
249
				zlib1g-dev"
			   ;;
250
251
			*) ;;
		esac
252
253
254
255
256
257
		# cucumber dependencies
		case $HOSTNAME in
			profitbricks-build10-amd64|jenkins-test-vm) DEBS="$DEBS
				cucumber
				tesseract-ocr
				i18nspector
Holger Levsen's avatar
Holger Levsen committed
258
				imagemagick
259
260
				libav-tools
				libsikuli-script-java
261
				libvirt-bin
262
263
264
265
				libvirt-dev
				ovmf
				python-jabberbot
				python-potr
266
				python3-yaml
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
				ruby-guestfs
				ruby-libvirt
				ruby-net-irc
				ruby-packetfu
				ruby-rb-inotify
				ruby-rjb
				ruby-test-unit
				tcpdump
				unclutter
				virt-viewer
				x264
				xvfb
				x11vnc"
			   ;;
			*) ;;
		esac
283
284
285
286
		if [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
			# for phil only
			DEBS="$DEBS postfix-pcre"
		fi
287
		if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
Holger Levsen's avatar
Holger Levsen committed
288
289
290
291
			MASTERDEBS=" 
				apache2 
				apt-file 
				apt-listchanges 
292
				asciidoc
Holger Levsen's avatar
Holger Levsen committed
293
294
295
296
297
298
299
300
301
302
303
				binfmt-support 
				bison 
				build-essential 
				calamaris 
				cmake 
				cron-apt 
				csvtool 
				dnsmasq-base 
				dose-extra 
				dstat 
				figlet 
Holger Levsen's avatar
Holger Levsen committed
304
				flex
Holger Levsen's avatar
Holger Levsen committed
305
				gawk 
306
307
				ghc
				git-notifier 
Holger Levsen's avatar
Holger Levsen committed
308
309
310
311
				gocr 
				graphviz 
				iasl 
				imagemagick 
312
313
				ip2host
				jekyll
314
				kgb-client
Holger Levsen's avatar
Holger Levsen committed
315
316
317
318
319
320
321
322
323
324
				libapache2-mod-macro 
				libcap2-bin 
				libfile-touch-perl 
				libguestfs-tools 
				libjson-rpc-perl 
				libsoap-lite-perl 
				libvirt0 
				libvirt-bin 
				libvpx1 
				libxslt1-dev 
325
				linux-image-amd64
Holger Levsen's avatar
Holger Levsen committed
326
327
328
329
330
331
332
333
				moreutils 
				mr 
				mtr-tiny 
				munin 
				ntp 
				openbios-ppc 
				openbios-sparc 
				openjdk-7-jre 
334
				pandoc
Holger Levsen's avatar
Holger Levsen committed
335
336
337
338
				postgresql-client-9.4 
				poxml 
				procmail 
				python3-debian 
339
				python3-xdg
Holger Levsen's avatar
Holger Levsen committed
340
				python3-yaml 
341
				python3-pystache
Holger Levsen's avatar
Holger Levsen committed
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
				python-arpy 
				python-hachoir-metadata 
				python-imaging 
				python-lzma 
				python-pip 
				python-rpy2 
				python-setuptools 
				python-twisted 
				python-yaml 
				qemu 
				qemu-kvm 
				qemu-system-x86 
				qemu-user-static 
				radvd 
				ruby-json 
				ruby-rspec 
				seabios 
				shorewall 
				shorewall6 
				sqlite3 
				syslinux 
363
				tor
Holger Levsen's avatar
Holger Levsen committed
364
				vncsnapshot 
365
366
				vnstat
				whohas
Holger Levsen's avatar
Holger Levsen committed
367
				x11-apps 
368
				xtightvncviewer
369
				xvfb
370
				xvkbd
371
				zutils"
372
373
374
		else
			MASTERDEBS=""
		fi
375
		$UP2DATE || sudo apt-get update
376
377
		$UP2DATE || sudo apt-get install $DEBS $MASTERDEBS
		$UP2DATE || sudo apt-get install -t jessie-backports \
378
				pbuilder lintian || echo "this should only fail on the first install"
379
		#		botch
380
381
		# we need mock from bpo to build current fedora
		if [ "$HOSTNAME" = "profitbricks-build3-amd64" ] || [ "$HOSTNAME" = "profitbricks-build4-amd64" ] || [ "$HOSTNAME" = "jenkins" ] ; then
382
			$UP2DATE || sudo apt-get install -t jessie-backports mock \
383
				|| echo "this should only fail on the first install"
384
		fi
385
		# for varying kernels
386
387
		# we use bpo kernels on pb-build5+6 (and i386 kernel on pb-build2-i386)
		if [ "$HOSTNAME" = "profitbricks-build5-amd64" ] || [ "$HOSTNAME" = "profitbricks-build6-i386" ]; then
388
			$UP2DATE || sudo apt-get install -t jessie-backports linux-image-amd64 || echo "this should only fail on the first install"
389
		fi
390
		# only needed on the main node
Holger Levsen's avatar
Holger Levsen committed
391
		if [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
392
			$UP2DATE || sudo apt-get install -t jessie-backports jenkins-job-builder || echo "this should only fail on the first install"
Holger Levsen's avatar
Holger Levsen committed
393
		elif [ "$HOSTNAME" = "jenkins" ] ; then
394
			$UP2DATE || sudo apt-get install -t jessie-backports ffmpeg libav-tools python3-popcon jenkins-job-builder
395
		fi
Holger Levsen's avatar
Holger Levsen committed
396
		explain "packages installed."
397
	else
Holger Levsen's avatar
Holger Levsen committed
398
		explain "no new packages to be installed."
399
	fi
400
fi
401

402
#
403
# deploy package configuration in /etc and /usr/local/
404
#
Holger Levsen's avatar
Holger Levsen committed
405
cd $BASEDIR
406
sudo cp --preserve=mode,timestamps -r hosts/$HOSTNAME/etc/* /etc
407
sudo cp --preserve=mode,timestamps -r hosts/$HOSTNAME/usr/* /usr/
408
409
410
411
412

#
# more configuration than a simple cp can do
#
sudo chown root.root /etc/sudoers.d/jenkins ; sudo chmod 700 /etc/sudoers.d/jenkins
413
sudo chown root.root /etc/sudoers.d/jenkins-adm ; sudo chmod 700 /etc/sudoers.d/jenkins-adm
414
415

if [ "$HOSTNAME" = "jenkins" ] ; then
416
417
418
419
420
421
422
423
424
425
426
427
	if [ $BASEDIR/hosts/$HOSTNAME/etc/apache2 -nt $STAMP ] || [ ! -f $STAMP ] ; then
		if [ ! -e /etc/apache2/mods-enabled/proxy.load ] ; then
			sudo a2enmod proxy
			sudo a2enmod proxy_http
			sudo a2enmod rewrite
			sudo a2enmod ssl
			sudo a2enmod headers
			sudo a2enmod macro
			sudo a2enmod filter
		fi
		sudo a2ensite -q jenkins.debian.net
		sudo a2enconf -q munin
428
		sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/jenkins.debian.net.conf
429
430
431
		# for reproducible.d.n url rewriting:
		[ -L /var/www/userContent ] || sudo ln -sf /var/lib/jenkins/userContent /var/www/userContent
		sudo service apache2 reload
432
433
434
	fi
fi

435
if [ $BASEDIR/hosts/$HOSTNAME/etc/munin -nt $STAMP ] || [ ! -f $STAMP ] ; then
436
	cd /etc/munin/plugins
437
	sudo rm -f postfix_* open_inodes interrupts irqstats threads proc_pri vmstat if_err_* exim_* netstat fw_forwarded_local fw_packets forks open_files users nfs* iostat_ios 2>/dev/null
438
	case $HOSTNAME in
Holger Levsen's avatar
Holger Levsen committed
439
			jenkins|profitbricks-build*) [ -L /etc/munin/plugins/squid_cache ] || for i in squid_cache squid_objectsize squid_requests squid_traffic ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done ;;
440
441
			*)	;;
	esac
442
443
444
	if [ "$HOSTNAME" != "jenkins" ] && [ -L /etc/munin/plugins/iostat ] ; then
		sudo rm /etc/munin/plugins/iostat
	fi
445
446
	if [ "$HOSTNAME" = "jenkins" ] && [ ! -L /etc/munin/plugins/apache_accesses ] ; then
		for i in apache_accesses apache_volume ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done
447
		sudo ln -s /usr/share/munin/plugins/loggrep jenkins_oom
448
449
	fi
	sudo service munin-node force-reload
450
fi
Holger Levsen's avatar
Holger Levsen committed
451
explain "packages configured."
Holger Levsen's avatar
Holger Levsen committed
452
453
454
455

#
# install the heart of jenkins.debian.net
#
Holger Levsen's avatar
Holger Levsen committed
456
cd $BASEDIR
457
458
[ -d /srv/jenkins/features ] && sudo rm -rf /srv/jenkins/features
for dir in bin logparse cucumber live ; do
459
460
	sudo mkdir -p /srv/jenkins/$dir
	sudo rsync -rpt --delete $dir/ /srv/jenkins/$dir/
Holger Levsen's avatar
Holger Levsen committed
461
	sudo chown -R jenkins-adm.jenkins-adm /srv/jenkins/$dir
462
done
463
464
HOST_JOBS="hosts/$HOSTNAME/job-cfg"
if [ -e "$HOST_JOBS" ] ; then
465
	sudo rsync -rpt --copy-links --delete "$HOST_JOBS/" /srv/jenkins/job-cfg/
466
467
468
469
470
471
	sudo chown -R jenkins-adm.jenkins-adm /srv/jenkins/$dir
else
    # tidying up ... assuming that we don't want clutter on peripheral servers
    [ -d /srv/jenkins/job-cfg ] && sudo rm -rf /srv/jenkins/job-cfg
fi

Holger Levsen's avatar
Holger Levsen committed
472
sudo mkdir -p /var/lib/jenkins/.ssh
473
474
475
476
477
478
if [ "$HOSTNAME" = "jenkins" ] ; then
	sudo cp jenkins-home/procmailrc /var/lib/jenkins/.procmailrc
	sudo cp jenkins-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
else
	sudo cp jenkins-nodes-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
fi
Holger Levsen's avatar
Holger Levsen committed
479
480
481
sudo chown -R jenkins:jenkins /var/lib/jenkins/.ssh
sudo chmod 700 /var/lib/jenkins/.ssh
sudo chmod 600 /var/lib/jenkins/.ssh/authorized_keys
Holger Levsen's avatar
Holger Levsen committed
482
explain "scripts and configurations for jenkins updated."
483

484
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
485
	sudo cp -pr README INSTALL TODO CONTRIBUTING d-i-preseed-cfgs /var/lib/jenkins/userContent/
486
	git log | grep ^Author| cut -d " " -f2-|sort -u -f > $TMPFILE
487
	echo "----" >> $TMPFILE
488
	sudo tee /var/lib/jenkins/userContent/THANKS > /dev/null < THANKS.head
Holger Levsen's avatar
Holger Levsen committed
489
490
	# samuel, lunar, josch and phil committed with several commiters, only display one
	grep -v -e "samuel.thibault@ens-lyon.org" -e Lunar -e "j.schauer@email.de" -e "mattia@mapreri.org" -e "phil@jenkins-test-vm" $TMPFILE | sudo tee -a /var/lib/jenkins/userContent/THANKS > /dev/null
491
	rm $TMPFILE
492
	TMPDIR=$(mktemp -d -t update-jdn-XXXXXXXX)
493
	sudo cp -pr userContent $TMPDIR/
Holger Levsen's avatar
Holger Levsen committed
494
495
496
	sudo chown -R jenkins.jenkins $TMPDIR
	sudo cp -pr $TMPDIR/userContent  /var/lib/jenkins/
	sudo rm -r $TMPDIR > /dev/null
497
498
499
500
501
502
503
504
505
	cd /var/lib/jenkins/userContent/
	ASCIIDOC_PARAMS="-a numbered -a data-uri -a iconsdir=/etc/asciidoc/images/icons -a scriptsdir=/etc/asciidoc/javascripts -b html5 -a toc -a toclevels=4 -a icons -a stylesheet=$(pwd)/theme/debian-asciidoc.css"
	[ about.html -nt README ] || asciidoc $ASCIIDOC_PARAMS -o about.html README
	[ todo.html -nt TODO ] || asciidoc $ASCIIDOC_PARAMS -o todo.html TODO
	[ setup.html -nt INSTALL ] || asciidoc $ASCIIDOC_PARAMS -o setup.html INSTALL
	[ contributing.html -nt CONTRIBUTING ] || asciidoc $ASCIIDOC_PARAMS -o contributing.html CONTRIBUTING
	diff THANKS .THANKS >/dev/null || asciidoc $ASCIIDOC_PARAMS -o thanks.html THANKS
	mv THANKS .THANKS
	rm TODO README INSTALL CONTRIBUTING
506
	sudo chown jenkins.jenkins /var/lib/jenkins/userContent/*html
Holger Levsen's avatar
Holger Levsen committed
507
	explain "user content for jenkins updated."
508
fi
509

510
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
511
512
513
514
515
516
517
	#
	# run jenkins-job-builder to update jobs if needed
	#     (using sudo because /etc/jenkins_jobs is root:root 700)
	#
	cd /srv/jenkins/job-cfg
	for metaconfig in *.yaml.py ; do
	# there are both python2 and python3 scripts here
518
        [ -e ./$metaconfig ] || continue
519
		./$metaconfig > $TMPFILE
520
521
		if ! sudo -u jenkins-adm cmp -s ${metaconfig%.py} - < $TMPFILE ; then
			sudo -u jenkins-adm tee ${metaconfig%.py} > /dev/null < $TMPFILE
522
523
		fi
	done
Holger Levsen's avatar
Holger Levsen committed
524
	rm -f $TMPFILE
525
	for config in *.yaml ; do
526
527
528
529
530
531
532
		# do update, if
		# no stamp file exist or
		# no .py file exists and config is newer than stamp or
		# a .py file exists and .py file is newer than stamp
		if [ ! -f $STAMP ] || \
		 ( [ ! -f $config.py ] && [ $config -nt $STAMP ] ) || \
		 ( [ -f $config.py ] && [ $config.py -nt $STAMP ] ) ; then
533
			$JJB update $config
534
535
536
537
		else
			echo "$config has not changed, nothing to do."
		fi
	done
Holger Levsen's avatar
Holger Levsen committed
538
	explain "jenkins jobs updated."
539
fi
540

541
#
Holger Levsen's avatar
Holger Levsen committed
542
# configure git for jenkins
543
#
Holger Levsen's avatar
Holger Levsen committed
544
545
546
547
if [ "$(sudo su - jenkins -c 'git config --get user.email')" != "jenkins@jenkins.debian.net" ] ; then
	sudo su - jenkins -c "git config --global user.email jenkins@jenkins.debian.net"
	sudo su - jenkins -c "git config --global user.name Jenkins"
fi
Holger Levsen's avatar
Holger Levsen committed
548

549
550
551
552
553
554
if [ "$HOSTNAME" = "jenkins" ] ; then
	#
	# creating LVM volume group for jobs
	#
	if [ "$PVNAME" = "" ]; then
	    figlet -f banner Error
Holger Levsen's avatar
Holger Levsen committed
555
	    explain "you must set \$PVNAME to physical volume pathname, exiting."
556
557
558
559
560
561
562
563
564
	    exit 1
	else
	    if ! sudo pvs $PVNAME >/dev/null 2>&1; then
	        sudo pvcreate $PVNAME
	    fi
	    if ! sudo vgs $VGNAME >/dev/null 2>&1; then
	        sudo vgcreate $VGNAME $PVNAME
	    fi
	fi
565
566
567
568
569
fi

#
# generate the kgb-client configurations
#
570
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "profitbricks-build3-amd64" ] || [ "$HOSTNAME" = "profitbricks-build4-amd64" ] ; then
571
572
573
574
575
576
577
578
579
580
	cd $BASEDIR
	KGB_SECRETS="/srv/jenkins/kgb/secrets.yml"
	if [ -f "$KGB_SECRETS" ] && [ $(stat -c "%a:%U:%G" "$KGB_SECRETS") = "640:jenkins-adm:jenkins-adm" ] ; then
	    # the last condition is to assure the files are owned by the right user/team
	    if [ "$KGB_SECRETS" -nt $STAMP ] || [ ! -f $STAMP ] ; then
	        sudo -u jenkins-adm "./deploy_kgb.py"
	    else
	        explain "kgb-client configuration unchanged, nothing to do."
	    fi
	else
Holger Levsen's avatar
Holger Levsen committed
581
	    figlet -f banner Warning
582
583
	    echo "Warning: $KGB_SECRETS either does not exist or has bad permissions. Please fix. KGB configs not generated"
	    echo "We expect the secrets file to be mode 640 and owned by jenkins-adm:jenkins-adm."
584
	    echo "/srv/jenkins/kbg should be mode 755 and owned by jenkins-adm:root."
585
	    echo "/srv/jenkins/kbg/client-status should be mode 755 and owned by jenkins:jenkins."
586
	fi
587
588
fi

Holger Levsen's avatar
Holger Levsen committed
589
590
591
592
#
# There's always some work left...
#	echo FIXME is ignored so check-jobs scripts can output templates requiring manual work
#
593
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
594
595
596
	rgrep FI[X]ME $BASEDIR/* | grep -v echo > $TMPFILE || true
	if [ -s $TMPFILE ] ; then
		echo
597
598
599
600
601
602
		# only show cucumber FIXMEs when deploying on jenkins-test-vm
		if [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
			cat $TMPFILE
		else
			cat $TMPFILE | grep -v cucumber
		fi
603
604
605
		echo
	fi
	rm -f $TMPFILE
Holger Levsen's avatar
Holger Levsen committed
606
fi
Holger Levsen's avatar
Holger Levsen committed
607

608
#
609
# almost finally…
610
#
611
sudo touch $STAMP	# so on the next run, only configs newer than this file will be updated
Holger Levsen's avatar
Holger Levsen committed
612
explain "$(date) - finished deployment."
613

614
# finally!
615
case $HOSTNAME in
616
	# set time back to the future
617
	profitbricks-build4-amd64|profitbricks-build5-amd64|profitbricks-build6-i386)
618
619
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
620
	jenkins)
621
		MESSAGE="jenkins.d.n updated to $(cd $BASEDIR ; git describe --always)."
622
		kgb-client --conf /srv/jenkins/kgb/debian-qa.conf --relay-msg "$MESSAGE"
Holger Levsen's avatar
Holger Levsen committed
623
		;;
624
625
	*)	;;
esac
626
627
628
629

echo
figlet ok
echo
Holger Levsen's avatar
Holger Levsen committed
630
631
echo "__$HOSTNAME=ok__"