update_jdn.sh 26.2 KB
Newer Older
1
#!/bin/bash
2
# vim: set noexpandtab:
3
# Copyright 2012-2019 Holger Levsen <holger@layer-acht.org>
4
#         ©      2018 Mattia Rizzolo <mattia@debian.org>
Holger Levsen's avatar
Holger Levsen committed
5
# released under the GPLv2
6

Holger Levsen's avatar
Holger Levsen committed
7
# puppet / salt / ansible / fai / chef / deployme.app - disclaimer
Holger Levsen's avatar
Holger Levsen committed
8
9
10
11
12
13
14
15
16
17
18
# (IOW: this script has been grown in almost 500 commits and it shows…)
#
# yes, we know… and: "it" should probably still be done.
#
# It just unclear, how/what, and what we have actually mostly works.
#
# Switching to jenkins.debian.org is probably an opportunity
# to write (refactor this into) *yet another deployment script*
# (interacting with the DSA machine setup which is in puppet…),
# thus obsoleting this script gradually, though this is used on
# 47 hosts currently (of which quite some were initially installed
Edward Betts's avatar
Edward Betts committed
19
# manually…)
Holger Levsen's avatar
Holger Levsen committed
20
21
22
#
# so, yes, patches welcome. saying this is crap alone is not helpful,
# nor is just suggesting some new or old technology. patches most welcome!
23
24
#
# that said, there's a new one: init_node ;)
Holger Levsen's avatar
Holger Levsen committed
25

26
27
set -e

Holger Levsen's avatar
Holger Levsen committed
28
# prevent failure on first run...
Holger Levsen's avatar
Holger Levsen committed
29
[ ! -f /srv/jenkins/bin/common-functions.sh ] || . /srv/jenkins/bin/common-functions.sh
Holger Levsen's avatar
Holger Levsen committed
30

31
BASEDIR="$(dirname "$(readlink -e $0)")"
32
STAMP=/var/log/jenkins/update-jenkins.stamp
33
34
# The $@ below means that command line args get passed on to j-j-b
# which allows one to specify --flush-cache or --ignore-cache
35
JJB="jenkins-jobs $@"
36
DPKG_ARCH="$(dpkg --print-architecture)"
Holger Levsen's avatar
Holger Levsen committed
37

38
# so we can later run some commands only if $0 has been updated…
Philip Hands's avatar
Philip Hands committed
39
if [ -f $STAMP ] && [ $STAMP -nt $BASEDIR/$0 ] ; then
Holger Levsen's avatar
Holger Levsen committed
40
	UP2DATE=true
Holger Levsen's avatar
Holger Levsen committed
41
	echo $HOSTNAME is up2date.
Philip Hands's avatar
Philip Hands committed
42
43
else
	UP2DATE=false
Holger Levsen's avatar
Holger Levsen committed
44
	echo $HOSTNAME needs to be updated.
45
46
47
fi


Holger Levsen's avatar
Holger Levsen committed
48
explain() {
Holger Levsen's avatar
Holger Levsen committed
49
	echo "$HOSTNAME: $1"
Holger Levsen's avatar
Holger Levsen committed
50
51
}

52
53
54
set_correct_date() {
		# set correct date
		sudo service ntp stop || true
55
		sudo ntpdate -b $1
56
}
57

58
disable_dsa_check_packages() {
59
	# disable check for outdated packages as someday in the future
60
	# packages from security.d.o will appear outdated always…
61
62
	echo -e "#!/bin/sh\n# disabled dsa-check by update_jdn.sh\nexit 0" | sudo tee /usr/local/bin/dsa-check-packages
	sudo chmod a+rx /usr/local/bin/dsa-check-packages
63
64
}

65
echo "--------------------------------------------"
Holger Levsen's avatar
Holger Levsen committed
66
explain "$(date) - begin deployment update."
67

68
69
70
71
#
# temporarily test to check which hosts don't use systemd
#
if [ -z "$(dpkg -l|grep systemd-sysv||true)" ] ; then 
72
	echo "no systemd-sysv installed on $(hostname), please enter to continue…"
73
74
75
	read
fi

76
# some nodes need special treatment…
77
case $HOSTNAME in
78
	profitbricks-build5-amd64|profitbricks-build6-i386|profitbricks-build15-amd64|profitbricks-build16-i386)
Holger Levsen's avatar
Holger Levsen committed
79
		# set correct date
80
		set_correct_date de.pool.ntp.org
81
		;;
82
	codethink-sled9*|codethink-sled11*|codethink-sled13*|codethink-sled15*)
83
		# set correct date
84
		set_correct_date de.pool.ntp.org
Holger Levsen's avatar
Holger Levsen committed
85
		;;
86
	osuosl-build170-amd64|osuosl-build172-amd64)
87
		# set correct date
88
		set_correct_date time.osuosl.org
89
		;;
90
91
92
	*)	;;
esac

93
94
95
96
97
98
99
100
101
102
103
# ubuntu decided to change kernel perms in the middle of LTS…
case $HOSTNAME in
	codethink-sled*)
		# fixup perms
		sudo chmod +r /boot/vmlinuz-*
		;;
	*)	;;
esac



104
105
106
#
# set up users and groups
#
107
declare -A user_host_groups u_shell
108
sudo_groups='jenkins,jenkins-adm,sudo,adm'
109
110
111

# if there's a need for host groups, a case statement on $HOSTNAME here that sets $GROUPNAME, say, should do the trick
# then you can define user_host_groups['phil','lvm_group']=... below
112
# and add checks for the GROUP version where ever the HOSTNAME is checked in the following code
113
114
115
116
117

user_host_groups['helmut','*']="$sudo_groups"
user_host_groups['holger','*']="$sudo_groups"
user_host_groups['holger','jenkins']="reproducible,${user_host_groups['holger','*']}"
user_host_groups['mattia','*']="$sudo_groups"
118
user_host_groups['mattia','jenkins']="reproducible,${user_host_groups['mattia','*']}"
119
user_host_groups['phil','jenkins-test-vm']="$sudo_groups,libvirt,libvirt-qemu"
120
user_host_groups['phil','jenkins']="$sudo_groups"
121
user_host_groups['lunar','jenkins']='reproducible'
122
123
user_host_groups['lynxis','osuosl-build171-amd64']="$sudo_groups"
user_host_groups['lynxis','osuosl-build172-amd64']="$sudo_groups"
124
user_host_groups['lynxis','jenkins']="jenkins"
125
126
user_host_groups['kpcyrd','osuosl-build169-amd64']="$sudo_groups"
user_host_groups['kpcyrd','osuosl-build170-amd64']="$sudo_groups"
127
user_host_groups['kpcyrd','jenkins']="jenkins"
128
user_host_groups['hans','osuosl-build168-amd64']="$sudo_groups"
Mattia Rizzolo's avatar
Mattia Rizzolo committed
129
user_host_groups['vagrant','*']="$sudo_groups"
130
user_host_groups['bernhard','osuosl-build174-amd64']="$sudo_groups"
131
132

u_shell['mattia']='/bin/zsh'
133
u_shell['lynxis']='/usr/bin/fish'
134
u_shell['kpcyrd']='/bin/bash'
135
u_shell['jenkins-adm']='/bin/bash'
136

137
138
139
# get the users out of the user_host_groups array's index
users=$(for i in ${!user_host_groups[@]}; do echo ${i%,*} ; done | sort -u)

140
141
( $UP2DATE && [ -z "$(find $BASEDIR/authorized_keys -newer $0)" ] ) || for user in ${users}; do
	cd $BASEDIR
142
	# -v is a bashism to check for set variables, used here to see if this user is active on this host
143
	if [ ! -v user_host_groups["$user","$HOSTNAME"] ] && [ ! -v user_host_groups["$user",'*'] ] && [ ! -v user_host_groups["$user","$DPKG_ARCH"] ] ; then
Holger Levsen's avatar
Holger Levsen committed
144
145
		continue
	fi
146

147
148
149
150
151
152
	# create the user
	if ! getent passwd $user > /dev/null ; then
		# adduser, defaulting to /bin/bash as shell
		sudo adduser --gecos "" --shell "${u_shell[$user]:-/bin/bash}" --disabled-password $user
	fi
	# add groups: first try the specific host, or if unset fall-back to default '*' setting
153
	for h in "$HOSTNAME" "$DPKG_ARCH" '*' ; do
154
		if [ -v user_host_groups["$user","$h"] ] ; then
Holger Levsen's avatar
Holger Levsen committed
155
			sudo usermod -G "${user_host_groups["$user","$h"]}" $user
156
			break
157
		fi
158
159
160
161
162
	done
	# add the user's keys (if any)
	if ls authorized_keys/${user}@*.pub >/dev/null 2>&1 ; then
		[ -d /var/lib/misc/userkeys ] || sudo mkdir -p /var/lib/misc/userkeys
		cat authorized_keys/${user}@*.pub | sudo tee /var/lib/misc/userkeys/${user} > /dev/null
163
	fi
164
165
done

166
167
168
169
170
sudo mkdir -p /srv/workspace
[ -d /srv/schroots ] || sudo mkdir -p /srv/schroots
[ -h /chroots ] || sudo ln -s /srv/workspace/chroots /chroots
[ -h /schroots ] || sudo ln -s /srv/schroots /schroots

171
172
# prepare tmpfs on some hosts
case $HOSTNAME in
Mattia Rizzolo's avatar
Mattia Rizzolo committed
173
174
175
176
	jenkins)
		TMPFSSIZE=100
		TMPSIZE=15
		;;
Holger Levsen's avatar
Holger Levsen committed
177
	profitbricks-build9-amd64)
178
		TMPFSSIZE=40
Mattia Rizzolo's avatar
Mattia Rizzolo committed
179
180
		TMPSIZE=8
		;;
Holger Levsen's avatar
Holger Levsen committed
181
	profitbricks-build*)
Mattia Rizzolo's avatar
Mattia Rizzolo committed
182
183
184
		TMPFSSIZE=200
		TMPSIZE=15
		;;
185
186
187
188
	codethink*)
		TMPFSSIZE=100
		TMPSIZE=15
		;;
189
190
191
192
	osuosl*)
		TMPFSSIZE=400
		TMPSIZE=50
		;;
193
194
195
	*) ;;
esac
case $HOSTNAME in
196
197
198
199
200
201
	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
		;;
202
	jenkins|profitbricks-build*amd64|codethink*|osuosl*)
203
		if ! grep -q '^tmpfs\s\+/srv/workspace\s' /etc/fstab; then
204
			echo "tmpfs		/srv/workspace	tmpfs	defaults,size=${TMPFSSIZE}g	0	0" | sudo tee -a /etc/fstab >/dev/null  
205
		fi
Mattia Rizzolo's avatar
Mattia Rizzolo committed
206
207
208
		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
209
210
		if ! mountpoint -q /srv/workspace; then
			if test -z "$(ls -A /srv/workspace)"; then
211
				sudo mount /srv/workspace
212
			else
213
				explain "WARNING: mountpoint /srv/workspace is non-empty."
214
215
216
217
218
			fi
		fi
		;;
	*) ;;
esac
219

220
# make sure needed directories exists - some directories will not be needed on all hosts...
221
for directory in /schroots /srv/reproducible-results /srv/d-i /srv/udebs /var/log/jenkins/ /srv/jenkins /srv/jenkins/pseudo-hosts /srv/workspace/chroots ; do
222
223
224
	if [ ! -d $directory ] ; then
		sudo mkdir $directory
	fi
Holger Levsen's avatar
Holger Levsen committed
225
	sudo chown jenkins.jenkins $directory
226
done
Holger Levsen's avatar
Holger Levsen committed
227
for directory in /srv/jenkins ; do
228
229
230
231
232
	if [ ! -d $directory ] ; then
		sudo mkdir $directory
		sudo chown jenkins-adm.jenkins-adm $directory
	fi
done
233

234
if ! test -h /chroots; then
Holger Levsen's avatar
Holger Levsen committed
235
	sudo rmdir /chroots || sudo rm -f /chroots # do not recurse
236
	if test -e /chroots; then
Holger Levsen's avatar
Holger Levsen committed
237
		explain "/chroots could not be cleared."
238
	else
239
		sudo ln -s /srv/workspace/chroots /chroots
240
241
242
	fi
fi

243
244
245
246
247
# only on Debian systems
if [ -f /etc/debian_version ] ; then
	#
	# install packages we need
	#
248
	if [ $BASEDIR/$0 -nt $STAMP ] || [ ! -f $STAMP ] ; then
249
		DEBS="
Holger Levsen's avatar
Holger Levsen committed
250
			bash-completion 
251
252
			bc
			bsd-mailx
253
254
			curl
			debian-archive-keyring
255
			cdebootstrap-
256
			debootstrap
257
258
			devscripts
			eatmydata
259
			etckeeper
260
			figlet
Holger Levsen's avatar
Holger Levsen committed
261
			git
Holger Levsen's avatar
Holger Levsen committed
262
			gnupg
263
			haveged
Holger Levsen's avatar
Holger Levsen committed
264
			htop
265
			less
266
			locales-all
Mattia Rizzolo's avatar
Mattia Rizzolo committed
267
			lsof
268
269
			molly-guard
			moreutils
Holger Levsen's avatar
Holger Levsen committed
270
			mosh
271
272
273
			munin-node
			munin-plugins-core
			munin-plugins-extra
Holger Levsen's avatar
Holger Levsen committed
274
			needrestart
275
			netcat-traditional
276
277
			ntp
			ntpdate
278
			pbuilder
279
			pigz 
280
			postfix
281
			procmail
282
			psmisc
283
			python3-psycopg2 
284
			python3-yaml
Holger Levsen's avatar
Holger Levsen committed
285
			schroot 
286
287
			screen
			slay
288
			stunnel
Holger Levsen's avatar
Holger Levsen committed
289
290
291
			subversion 
			subversion-tools 
			sudo 
292
			systemd-sysv
Holger Levsen's avatar
Holger Levsen committed
293
294
			unzip 
			vim 
295
			zsh
296
			"
297
		case $HOSTNAME in
298
299
300
			codethink*)
				# install debootstrap from stretch-backports on ubuntu nodes as since 20180927 debootstrap 1.0.78+nmu1ubuntu1.6 cannot install sid anymore
				DEBS="$DEBS
301
302
303
304
305
306
307
				debootstrap/stretch-backports
				munin-node/stretch-backports
				munin-plugins-core/stretch-backports
				munin-plugins-extra/stretch-backports
				pbuilder/stretch-backports
				" ;;
		esac
308
		case $HOSTNAME in
309
			# needed for rebuilding Debian (using .buildinfo files)
310
			osuosl-build173-amd64) DEBS="$DEBS libdpkg-perl libwww-mechanize-perl sbuild" ;;
311
312
			# needed for opensuse openbuildservice
			osuosl-build174-amd64) DEBS="$DEBS osc obs-build qemu-kvm libjson-perl libxml-simple-perl bsdtar" ;;
313
314
			*) ;;
		esac
315
		# install squid / apache2 on a few nodes only
316
		case $HOSTNAME in
317
			profitbricks-build1-a*|profitbricks-build10*|codethink-sled16*|osuosl-build167*) DEBS="$DEBS
318
				squid" ;;
319
320
			profitbricks-build7-a*) DEBS="$DEBS
				apache2" ;;
321
322
323
324
325
			*) ;;
		esac
		# notifications are only done from a view nodes
		case $HOSTNAME in
			jenkins|jenkins-test-vm|profitbricks-build*) DEBS="$DEBS
326
327
				kgb-client
				python3-yaml" ;;
328
329
			*) ;;
		esac
330
331
		# needed to run the 2nd reproducible builds nodes in the future...
		case $HOSTNAME in
332
			profitbricks-build5-amd64|profitbricks-build6-i386|profitbricks-build15-amd64|profitbricks-build16-i386) DEBS="$DEBS ntpdate" ;;
333
			codethink-sled9*|codethink-sled11*|codethink-sled13*|codethink-sled15*) DEBS="$DEBS ntpdate" ;;
334
			osuosl-build170-amd64|osuosl-build172-amd64) DEBS="$DEBS ntpdate" ;;
335
336
			*) ;;
		esac
337
		# needed to run coreboot/openwrt/netbsd/fedora jobs
338
		case $HOSTNAME in
339
		osuosl-build171-amd64|osuosl-build172-amd64) DEBS="$DEBS
Holger Levsen's avatar
Holger Levsen committed
340
				bison
341
				ca-certificates
Holger Levsen's avatar
Holger Levsen committed
342
343
344
				cmake
				diffutils
				findutils
345
				fish
Holger Levsen's avatar
Holger Levsen committed
346
347
348
349
				flex
				g++
				gawk
				gcc
350
				gnat
Holger Levsen's avatar
Holger Levsen committed
351
352
353
354
355
356
357
358
				grep
				libc6-dev
				libncurses5-dev
				libssl-dev
				locales-all
				kgb-client
				m4
				make
359
360
				python3-clint
				python3-git
361
				python3-pystache
362
				python3-requests
Holger Levsen's avatar
Holger Levsen committed
363
364
				python3-yaml
				subversion
365
				tree
Holger Levsen's avatar
Holger Levsen committed
366
367
				unzip
				util-linux
368
369
				zlib1g-dev
				"
370
371
372
			;;
			*) ;;
		esac
373
374
		# needed to run fdroid jobs
		case $HOSTNAME in
375
			osuosl-build168-amd64) DEBS="$DEBS
376
				androguard
377
				android-sdk
378
379
				bzr
				git-svn
380
				fdroidserver
381
				linux-headers-amd64
382
				mercurial
383
				python3-asn1crypto
384
				python3-babel
385
				python3-mwclient
386
				python3-setuptools
387
				subversion
388
				vagrant
389
				virtualbox virtualbox-dkms
390
				"
391
			;;
392
			*) ;;
393
		esac
394
395
396
		if [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
			# for phil only
			DEBS="$DEBS postfix-pcre"
397
398
			# only needed on the main node
		elif [ "$HOSTNAME" = "jenkins" ] ; then
399
			DEBS="$DEBS ffmpeg python3-popcon dose-extra"
400
401
402
403
		fi
		# mock is needed to build fedora
		if [ "$HOSTNAME" = "osuosl-build171-amd64" ] || [ "$HOSTNAME" = "osuosl-build172-amd64" ] || [ "$HOSTNAME" = "jenkins" ] ; then
			DEBS="$DEBS mock"
404
		fi
405
		# only on main node
406
		if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
Holger Levsen's avatar
Holger Levsen committed
407
408
409
410
			MASTERDEBS=" 
				apache2 
				apt-file 
				apt-listchanges 
411
				asciidoc
Holger Levsen's avatar
Holger Levsen committed
412
				binfmt-support 
413
414
				bison
				botch
Holger Levsen's avatar
Holger Levsen committed
415
416
417
418
419
420
421
				build-essential 
				cmake 
				cron-apt 
				csvtool 
				dnsmasq-base 
				dstat 
				figlet 
Holger Levsen's avatar
Holger Levsen committed
422
				flex
Holger Levsen's avatar
Holger Levsen committed
423
				gawk 
424
				ghc
425
				git-lfs
426
				git-notifier 
Holger Levsen's avatar
Holger Levsen committed
427
428
429
430
				gocr 
				graphviz 
				iasl 
				imagemagick 
431
432
				ip2host
				jekyll
433
				jenkins-job-builder
434
				jq
435
				kgb-client
Holger Levsen's avatar
Holger Levsen committed
436
437
438
439
440
441
442
443
444
				libcap2-bin 
				libfile-touch-perl 
				libguestfs-tools 
				libjson-rpc-perl 
				libsoap-lite-perl 
				libxslt1-dev 
				moreutils 
				mr 
				mtr-tiny 
445
				munin
Holger Levsen's avatar
Holger Levsen committed
446
				ntp 
447
				obfs4proxy
Holger Levsen's avatar
Holger Levsen committed
448
449
				openbios-ppc 
				openbios-sparc 
450
				openjdk-11-jre-headless
451
				pandoc
452
				postgresql
453
				postgresql-autodoc
454
				postgresql-client 
Holger Levsen's avatar
Holger Levsen committed
455
456
457
				poxml 
				procmail 
				python3-debian 
458
				python3-pystache
459
				python3-requests
460
				python3-rpy2 
461
462
463
				python3-sqlalchemy
				python3-xdg
				python3-yaml
Holger Levsen's avatar
Holger Levsen committed
464
465
466
				python-arpy 
				python-hachoir-metadata 
				python-lzma 
467
				python-pil
Holger Levsen's avatar
Holger Levsen committed
468
469
470
471
472
473
474
475
476
				python-pip 
				python-setuptools 
				python-twisted 
				python-yaml 
				qemu 
				qemu-kvm 
				qemu-system-x86 
				qemu-user-static 
				radvd 
477
478
				ruby-rspec
				rustc
Holger Levsen's avatar
Holger Levsen committed
479
480
481
482
				seabios 
				shorewall 
				shorewall6 
				sqlite3 
483
				syslinux
484
				systemd
485
				thin-provisioning-tools
486
				tor
Holger Levsen's avatar
Holger Levsen committed
487
				vncsnapshot 
488
489
				vnstat
				whohas
Holger Levsen's avatar
Holger Levsen committed
490
				x11-apps 
491
				xtightvncviewer
492
				xvfb
493
				xvkbd
494
495
				zutils
				"
496
497
498
		else
			MASTERDEBS=""
		fi
499
		$UP2DATE || sudo apt-get update
500
		$UP2DATE || sudo apt-get install $DEBS $MASTERDEBS
501
502
503
504
505
506
		# for varying kernels:
		# - we use bpo kernels on pb-build5+15 (and the default amd64 kernel on pb-build6+16-i386)
		# - we also use the bpo kernel on osuosl-build172 (but not osuosl-build171)
		# - this is done as a seperate step as bpo kernels are frequently uninstallable when upgraded on bpo
		if [ "$HOSTNAME" = "profitbricks-build5-amd64" ] || [ "$HOSTNAME" = "profitbricks-build15-amd64" ] \
			|| [ "$HOSTNAME" = "osuosl-build172-amd64" ] ; then
507
			sudo apt install linux-image-amd64/buster-backports || true # backport kernels are frequently uninstallable...
508
			:
509
510
511
512
513
514
		elif [ "$HOSTNAME" = "profitbricks-build6-i386" ] || [ "$HOSTNAME" = "profitbricks-build16-i386" ] \
			|| [ "$HOSTNAME" = "profitbricks-build2-i386" ] || [ "$HOSTNAME" = "profitbricks-build12-i386" ] ; then
			# we dont vary the kernel on i386 atm, see #875990 + #876035
			sudo apt install linux-image-amd64:amd64
		elif [ "$HOSTNAME" = "osuosl-build169-amd64" ] || [ "$HOSTNAME" = "osuosl-build170-amd64" ] ; then
			# Arch Linux builds latest stuff which sometimes (eg, currentlt Qt) needs newer kernel to build...
515
			sudo apt install linux-image-amd64/buster-backports || true # backport kernels are frequently uninstallable...
516
			:
517
		fi
Edward Betts's avatar
Edward Betts committed
518
		# don't (re-)install pbuilder if it's on hold
519
		if [ "$(dpkg-query -W -f='${db:Status-Abbrev}\n' pbuilder)" != "hi " ] ; then
520
			$UP2DATE || sudo apt-get install pbuilder
521
		fi
522
		# remove unattended-upgrades if it's installed
523
		if [ "$(dpkg-query -W -f='${db:Status-Abbrev}\n' unattended-upgrades 2>/dev/null || true)" = "ii "  ] ; then
524
			 sudo apt-get -y purge unattended-upgrades
525
		fi
526
		sudo apt-get clean
Holger Levsen's avatar
Holger Levsen committed
527
		explain "packages installed."
528
	else
Holger Levsen's avatar
Holger Levsen committed
529
		explain "no new packages to be installed."
530
	fi
531
fi
532

533
#
Holger Levsen's avatar
Holger Levsen committed
534
# deploy package configuration in /etc and /usr
535
#
Holger Levsen's avatar
Holger Levsen committed
536
cd $BASEDIR
537
538
539
540
541
542
543
544
545
for h in common common-amd64 common-i386 common-arm64 common-armhf "$HOSTNAME" ; do
	# $HOSTNAME has precedence over common-$DPKG_ARCH over common
	case $h in
		common-amd64) [ $DPKG_ARCH = "amd64" ] || continue ;;
		common-i386)  [ $DPKG_ARCH = "i386" ] || continue ;;
		common-arm64) [ $DPKG_ARCH = "arm64" ] || continue ;;
		common-armhf) [ $DPKG_ARCH = "armhf" ] || continue ;;
		*) ;;
	esac
546
547
	if [ -d "hosts/$h/etc/sudoers.d/" ]; then
		for f in "hosts/$h/etc/sudoers.d/"* ; do
548
			/usr/sbin/visudo -c -f "$f" > /dev/null
549
550
551
		done
	fi
	for d in etc usr ; do
Mattia Rizzolo's avatar
Mattia Rizzolo committed
552
		if [ -d "hosts/$h/$d" ]; then
553
			sudo cp --preserve=mode,timestamps -r "hosts/$h/$d/"* "/$d"
554
555
556
		fi
	done
done
557
558
# we ship one or two service files…
sudo systemctl daemon-reload &
559
560
561
562
563

#
# more configuration than a simple cp can do
#
sudo chown root.root /etc/sudoers.d/jenkins ; sudo chmod 700 /etc/sudoers.d/jenkins
564
sudo chown root.root /etc/sudoers.d/jenkins-adm ; sudo chmod 700 /etc/sudoers.d/jenkins-adm
Holger Levsen's avatar
Holger Levsen committed
565
[ -f /etc/mailname ] || ( echo $HOSTNAME.debian.net | sudo tee /etc/mailname )
566

567
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "profitbricks-build7-amd64" ] ; then
568
	if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/apache2 -nt $STAMP ]  ; then
569
570
571
572
573
574
575
576
577
		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
578
579
580
		if [ "$HOSTNAME" = "jenkins" ] ; then
			sudo a2ensite -q jenkins.debian.net
			sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/jenkins.debian.net.conf
581
			sudo a2enconf -q munin
582
583
584
585
		else # "$HOSTNAME" = "profitbricks-build7-amd64"
			sudo a2ensite -q buildinfos.debian.net
			sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/buildinfos.debian.net.conf
		fi
586
587
588
		# for reproducible.d.n url rewriting:
		[ -L /var/www/userContent ] || sudo ln -sf /var/lib/jenkins/userContent /var/www/userContent
		sudo service apache2 reload
589
590
591
	fi
fi

592
if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/munin -nt $STAMP ] ; then
593
	cd /etc/munin/plugins
594
	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 ntp* df_abs 2>/dev/null
595
	case $HOSTNAME in
596
			profitbricks-build1-a*|profitbricks-build10*|codethink-sled16*|osuosl-build167*) [ -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 ;;
597
598
			*)	;;
	esac
Holger Levsen's avatar
Holger Levsen committed
599
600
601
602
	case $HOSTNAME in
			jenkins) [ -L /etc/munin/plugins/postfix_mailstats ] || for i in postfix_mailstats postfix_mailvolume postfix_mailqueue ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done ;;
			*)	;;
	esac
603
604
605
	if [ "$HOSTNAME" != "jenkins" ] && [ -L /etc/munin/plugins/iostat ] ; then
		sudo rm /etc/munin/plugins/iostat
	fi
606
	if ( [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "profitbricks-build7-amd64" ] ) && [ ! -L /etc/munin/plugins/apache_accesses ] ; then
607
		for i in apache_accesses apache_volume ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done
608
		sudo ln -s /usr/share/munin/plugins/loggrep jenkins_oom
609
	fi
610
611
	# this is a hack to work around (rare) problems with restarting munin-node...
	sudo service munin-node restart || sudo service munin-node restart || sudo service munin-node restart
612
fi
613
614
615
616

# add some users to groups after packages have been installed
if ! $UP2DATE ; then
	case $HOSTNAME in
617
		jenkins|osuosl-build169-amd64|osuosl-build170-amd64)
618
619
620
			sudo addgroup --system --gid 300 abuild
			sudo adduser jenkins abuild
			;;
621
622
623
624
625
		osuosl-build173-amd64)		sudo adduser jenkins sbuild ;;
		*) 				;;
	esac
fi
# finally
Holger Levsen's avatar
Holger Levsen committed
626
explain "packages configured."
Holger Levsen's avatar
Holger Levsen committed
627
628
629
630

#
# install the heart of jenkins.debian.net
#
Holger Levsen's avatar
Holger Levsen committed
631
cd $BASEDIR
632
[ -d /srv/jenkins/features ] && sudo rm -rf /srv/jenkins/features
633
# check for bash syntax *before* actually deploying anything
634
shopt -s nullglob
635
for f in bin/*.sh bin/**/*.sh ; do bash -n "$f" ; done
636
shopt -u nullglob
637
for dir in bin logparse mustache-templates ; do
638
639
	sudo mkdir -p /srv/jenkins/$dir
	sudo rsync -rpt --delete $dir/ /srv/jenkins/$dir/
Holger Levsen's avatar
Holger Levsen committed
640
	sudo chown -R jenkins-adm.jenkins-adm /srv/jenkins/$dir
641
done
642
643
HOST_JOBS="hosts/$HOSTNAME/job-cfg"
if [ -e "$HOST_JOBS" ] ; then
644
	sudo -u jenkins-adm rsync -rpt --copy-links --delete "$HOST_JOBS/" /srv/jenkins/job-cfg/
645
else
Philip Hands's avatar
Philip Hands committed
646
647
	# tidying up ... assuming that we don't want clutter on peripheral servers
	[ -d /srv/jenkins/job-cfg ] && sudo rm -rf /srv/jenkins/job-cfg
648
649
fi

650

651
sudo mkdir -p -m 700 /var/lib/jenkins/.ssh
652
sudo chown jenkins.jenkins /var/lib/jenkins/.ssh
653
if [ "$HOSTNAME" = "jenkins" ] ; then
654
655
	sudo -u jenkins install -m 600 jenkins-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
	sudo -u jenkins cp jenkins-home/procmailrc /var/lib/jenkins/.procmailrc
656
	sudo -u jenkins cp jenkins-home/offline_nodes /var/lib/jenkins/offline_nodes
657
658
659
else
	sudo cp jenkins-nodes-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
fi
660
if [ -f jenkins-nodes-home/authorized_keys.$HOSTNAME ] ; then
661
	cat jenkins-nodes-home/authorized_keys.$HOSTNAME | sudo tee -a /var/lib/jenkins/.ssh/authorized_keys
662
fi
663
sudo -u jenkins cp jenkins-home/gitconfig /var/lib/jenkins/.gitconfig
664
665
sudo -u jenkins cp jenkins-home/ssh_config.in /var/lib/jenkins/.ssh/config
nodes/gen_ssh_config | sudo -u jenkins tee -a /var/lib/jenkins/.ssh/config > /dev/null
666
nodes/gen_known_host_file | sudo tee /etc/ssh/ssh_known_hosts > /dev/null
Holger Levsen's avatar
Holger Levsen committed
667
explain "scripts and configurations for jenkins updated."
668

669
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
670
	sudo cp -pr README INSTALL TODO CONTRIBUTING d-i-preseed-cfgs /var/lib/jenkins/userContent/
671
	TMPFILE=$(mktemp)
672
	git log | grep ^Author| cut -d " " -f2-|sort -u -f > $TMPFILE
673
	echo "----" >> $TMPFILE
674
	sudo tee /var/lib/jenkins/userContent/THANKS > /dev/null < THANKS.head
675
676
	# samuel, lunar, jelle, josch and phil committed with several committers, 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" -e "jelle@vdwaa.nl" $TMPFILE | sudo tee -a /var/lib/jenkins/userContent/THANKS > /dev/null
677
	rm $TMPFILE
678
	TMPDIR=$(mktemp -d -t update-jdn-XXXXXXXX)
679
	sudo cp -pr userContent $TMPDIR/
Holger Levsen's avatar
Holger Levsen committed
680
681
682
	sudo chown -R jenkins.jenkins $TMPDIR
	sudo cp -pr $TMPDIR/userContent  /var/lib/jenkins/
	sudo rm -r $TMPDIR > /dev/null
683
684
685
686
687
688
689
690
691
	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
692
	sudo chown jenkins.jenkins /var/lib/jenkins/userContent/*html
Holger Levsen's avatar
Holger Levsen committed
693
	explain "user content for jenkins updated."
694
fi
695

696
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
697
698
699
700
701
702
	#
	# 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
Holger Levsen's avatar
Holger Levsen committed
703
704
705
706
707
708
		if [ -f $metaconfig ] ; then
			TMPFILE=$(sudo -u jenkins-adm mktemp)
			./$metaconfig | sudo -u jenkins-adm tee "$TMPFILE" >/dev/null
			if ! sudo -u jenkins-adm cmp -s ${metaconfig%.py} "$TMPFILE" ; then
				sudo -u jenkins-adm mv "$TMPFILE" "${metaconfig%.py}"
			fi
709
710
711
		fi
	done
	for config in *.yaml ; do
712
713
714
715
716
717
718
		# 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
719
			echo "$config has changed, executing updates."
720
			$JJB update $config
721
722
		fi
	done
Holger Levsen's avatar
Holger Levsen committed
723
	explain "jenkins jobs updated."
724
fi
725

726
727
728
#
# generate the kgb-client configurations
#
729
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "osuosl-build168-amd64" ] || [ "$HOSTNAME" = "osuosl-build171-amd64" ] || [ "$HOSTNAME" = "osuosl-build172-amd64" ] || [ "$HOSTNAME" = "profitbricks-build2-i386" ] || [ "$HOSTNAME" = "profitbricks-build12-i386" ] ; then
730
731
732
	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
Philip Hands's avatar
Philip Hands committed
733
		# the last condition is to assure the files are owned by the right user/team
734
		if [ "$KGB_SECRETS" -nt $STAMP ] || [ "deploy_kgb.py" -nt "$STAMP" ] || [ ! -f $STAMP ] ; then
Philip Hands's avatar
Philip Hands committed
735
736
737
738
			sudo -u jenkins-adm "./deploy_kgb.py"
		else
			explain "kgb-client configuration unchanged, nothing to do."
		fi
739
	else
Philip Hands's avatar
Philip Hands committed
740
741
742
		figlet -f banner Warning
		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."
Holger Levsen's avatar
Holger Levsen committed
743
744
		echo "/srv/jenkins/kgb should be mode 755 and owned by jenkins-adm:root."
		echo "/srv/jenkins/kgb/client-status should be mode 755 and owned by jenkins:jenkins."
745
	fi
746
	KGB_STATUS="/srv/jenkins/kgb/client-status"
747
748
	sudo mkdir -p $KGB_STATUS
	sudo chown jenkins:jenkins $KGB_STATUS
749
750
fi

751
752
753
#
# Create GPG key for jenkins user if they do not already exist (eg. to sign .buildinfo files)
#
754
if sudo -H -u jenkins gpg --with-colons --fixed-list-mode --list-secret-keys | cut -d: -f1 | grep -qsFx 'sec' >/dev/null 2>&1 ; then
Holger Levsen's avatar
Holger Levsen committed
755
	: # not generating GPG key as one already exists for jenkins user
756
else
Holger Levsen's avatar
Holger Levsen committed
757
	explain "$(date) - Generating GPG key for jenkins user."
758

759
	sudo -H -u jenkins gpg --no-tty --batch --gen-key <<EOF
760
761
762
Key-Type: RSA
Key-Length: 4096
Key-Usage: sign
763
Name-Real: $HOSTNAME
764
765
766
767
768
769
Name-Comment: Automatically generated key for signing .buildinfo files
Expire-Date: 0
%no-ask-passphrase
%no-protection
%commit
EOF
770

771
	GPG_KEY_ID="$(sudo -H -u jenkins gpg --with-colons --fixed-list-mode --list-secret-keys | grep '^sec' | cut -d: -f5 | tail -n1)"
772
773
774
775
776
777

	if [ "$GPG_KEY_ID" = "" ]
	then
		explain "$(date) - Generated GPG key but could not parse key ID"
	else
		explain "$(date) - Generated GPG key $GPG_KEY_ID - submitting to keyserver"
778
		sudo -H -u jenkins gpg --send-keys $GPG_KEY_ID
779
	fi
780
781
fi

Holger Levsen's avatar
Holger Levsen committed
782
783
784
785
786
#
# There's always some work left...
#	echo FIXME is ignored so check-jobs scripts can output templates requiring manual work
#
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
787
	TMPFILE=$(mktemp)
788
	rgrep FI[X]ME $BASEDIR/* | grep -v $BASEDIR/TODO | grep -v echo > $TMPFILE || true
Holger Levsen's avatar
Holger Levsen committed
789
790
	if [ -s $TMPFILE ] ; then
		echo
791
		cat $TMPFILE
Holger Levsen's avatar
Holger Levsen committed
792
793
		echo
	fi
794
	rm -f $TMPFILE
Holger Levsen's avatar
Holger Levsen committed
795
796
fi

797
#
798
# almost finally…
799
#
800
sudo touch $STAMP	# so on the next run, only configs newer than this file will be updated
Holger Levsen's avatar
Holger Levsen committed
801
explain "$(date) - finished deployment."
802

803
804
805
806
#
# some final checks only for the jenkins
#
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
807
	jenkins_bugs_check
Holger Levsen's avatar
Holger Levsen committed
808
	explain "$(date) - done checking for known jenkins bugs."
809
810
fi

Holger Levsen's avatar
Holger Levsen committed
811
#
812
# finally!
Holger Levsen's avatar
Holger Levsen committed
813
#
814
case $HOSTNAME in
815
	# set time back to the future
816
	profitbricks-build5-amd64|profitbricks-build6-i386|profitbricks-build15-amd64|profitbricks-build16-i386)
817
		disable_dsa_check_packages
818
819
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
820
	codethink-sled9*|codethink-sled11*|codethink-sled13*|codethink-sled15*)
821
		disable_dsa_check_packages
822
823
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
824
	osuosl-build170-amd64|osuosl-build172-amd64)
825
826
827
		disable_dsa_check_packages
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
828
	jenkins)
829
		# notify irc on updates of jenkins.d.n
830
831
		MESSAGE="jenkins.d.n updated to $(cd $BASEDIR ; git describe --always)."
		kgb-client --conf /srv/jenkins/kgb/debian-qa.conf --relay-msg "$MESSAGE"
Holger Levsen's avatar
Holger Levsen committed
832
		;;
833
834
	*)	;;
esac
835
836
837
838

echo
figlet ok
echo
Holger Levsen's avatar
Holger Levsen committed
839
840
echo "__$HOSTNAME=ok__"