update_jdn.sh 29.1 KB
Newer Older
1
#!/bin/bash
2
# vim: set noexpandtab:
3
# Copyright 2012-2021 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
	ionos5-amd64|ionos6-i386|ionos15-amd64|ionos16-i386)
Holger Levsen's avatar
Holger Levsen committed
79
		# set correct date
80
		set_correct_date de.pool.ntp.org
81
		;;
82
	codethink9*|codethink11*|codethink13*|codethink15*)
83
		# set correct date
84
		set_correct_date de.pool.ntp.org
Holger Levsen's avatar
Holger Levsen committed
85
		;;
86
	osuosl170-amd64|osuosl172-amd64)
87
		# set correct date
88
		set_correct_date time.osuosl.org
89
		;;
90
91
92
	*)	;;
esac

93
94
# ubuntu decided to change kernel perms in the middle of LTS…
case $HOSTNAME in
95
	codethink*)
96
97
98
99
100
101
102
103
		# 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','osuosl167-amd64']="$sudo_groups"
120
user_host_groups['jelmer','osuosl167-amd64']="$sudo_groups"
121
user_host_groups['phil','jenkins']="$sudo_groups"
122
user_host_groups['lunar','jenkins']='reproducible'
123
124
user_host_groups['lynxis','osuosl171-amd64']="$sudo_groups"
user_host_groups['lynxis','osuosl172-amd64']="$sudo_groups"
125
user_host_groups['lynxis','jenkins']="jenkins"
126
127
user_host_groups['kpcyrd','osuosl169-amd64']="$sudo_groups"
user_host_groups['kpcyrd','osuosl170-amd64']="$sudo_groups"
128
user_host_groups['kpcyrd','jenkins']="jenkins"
129
130
user_host_groups['bubu','osuosl168-amd64']="$sudo_groups"
user_host_groups['hans','osuosl168-amd64']="$sudo_groups"
131
user_host_groups['flx','osuosl168-amd64']="$sudo_groups"
Mattia Rizzolo's avatar
Mattia Rizzolo committed
132
user_host_groups['vagrant','*']="$sudo_groups"
133
user_host_groups['bernhard','osuosl174-amd64']="$sudo_groups"
134
user_host_groups['santiago','ionos3-amd64']="$sudo_groups"
135
user_host_groups['fpierret','snapshot']="$sudo_groups"
136
137

u_shell['mattia']='/bin/zsh'
138
u_shell['lynxis']='/usr/bin/fish'
139

140
141
142
# 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)

143
144
( $UP2DATE && [ -z "$(find $BASEDIR/authorized_keys -newer $0)" ] ) || for user in ${users}; do
	cd $BASEDIR
145
	# -v is a bashism to check for set variables, used here to see if this user is active on this host
146
	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
147
148
		continue
	fi
149

150
151
	# create the letsencrypt group and user in jenkins if needed
	# doing it here instead of using the array above as we have to use --system
152
	if [ "$HOSTNAME" = jenkins ] || [ "$HOSTNAME" = "ionos7-amd64" ]; then
153
154
155
		if ! getent group letsencrypt > /dev/null ; then
			sudo addgroup --system letsencrypt
		fi
156
		if ! getent passwd letsencrypt > /dev/null ; then
157
158
159
160
161
162
163
164
165
166
167
			sudo adduser --system \
				--gecos "Let's Encrypt role account" \
				--shell /usr/sbin/nologin \
				--disabled-login \
				--home /var/lib/dehydrated \
				--no-create-home \
				--ingroup letsencrypt \
				letsencrypt
		fi
	fi

168
169
170
171
172
173
	# 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
174
	for h in "$HOSTNAME" "$DPKG_ARCH" '*' ; do
175
		if [ -v user_host_groups["$user","$h"] ] ; then
Holger Levsen's avatar
Holger Levsen committed
176
			sudo usermod -G "${user_host_groups["$user","$h"]}" $user
177
			break
178
		fi
179
180
181
182
183
	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
184
	fi
185
186
done

187
188
# configure sbuild:
case $HOSTNAME in
189
	ionos7-a*|osuosl167*) sudo sbuild-adduser jenkins ;;
190
191
192
	*) ;;
esac

193
194
195
196
197
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

198
199
# prepare tmpfs on some hosts
case $HOSTNAME in
Mattia Rizzolo's avatar
Mattia Rizzolo committed
200
201
202
203
	jenkins)
		TMPFSSIZE=100
		TMPSIZE=15
		;;
204
	ionos9-amd64)
205
		TMPFSSIZE=40
Mattia Rizzolo's avatar
Mattia Rizzolo committed
206
207
		TMPSIZE=8
		;;
208
	ionos*)
Mattia Rizzolo's avatar
Mattia Rizzolo committed
209
210
211
		TMPFSSIZE=200
		TMPSIZE=15
		;;
212
213
214
215
	codethink*)
		TMPFSSIZE=100
		TMPSIZE=15
		;;
216
217
218
219
	osuosl*)
		TMPFSSIZE=400
		TMPSIZE=50
		;;
220
221
222
	*) ;;
esac
case $HOSTNAME in
223
	ionos*i386)
224
225
226
227
228
		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
		;;
229
	jenkins|ionos*amd64|codethink*|osuosl*)
230
		if ! grep -q '^tmpfs\s\+/srv/workspace\s' /etc/fstab; then
231
			echo "tmpfs		/srv/workspace	tmpfs	defaults,size=${TMPFSSIZE}g	0	0" | sudo tee -a /etc/fstab >/dev/null  
232
		fi
Mattia Rizzolo's avatar
Mattia Rizzolo committed
233
234
235
		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
236
237
		if ! mountpoint -q /srv/workspace; then
			if test -z "$(ls -A /srv/workspace)"; then
238
				sudo mount /srv/workspace
239
			else
240
				explain "WARNING: mountpoint /srv/workspace is non-empty."
241
242
243
244
245
			fi
		fi
		;;
	*) ;;
esac
246

247
# make sure needed directories exists - some directories will not be needed on all hosts...
248
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
249
250
251
	if [ ! -d $directory ] ; then
		sudo mkdir $directory
	fi
Holger Levsen's avatar
Holger Levsen committed
252
	sudo chown jenkins.jenkins $directory
253
done
Holger Levsen's avatar
Holger Levsen committed
254
for directory in /srv/jenkins ; do
255
256
257
258
259
	if [ ! -d $directory ] ; then
		sudo mkdir $directory
		sudo chown jenkins-adm.jenkins-adm $directory
	fi
done
260

261
if ! test -h /chroots; then
Holger Levsen's avatar
Holger Levsen committed
262
	sudo rmdir /chroots || sudo rm -f /chroots # do not recurse
263
	if test -e /chroots; then
Holger Levsen's avatar
Holger Levsen committed
264
		explain "/chroots could not be cleared."
265
	else
266
		sudo ln -s /srv/workspace/chroots /chroots
267
268
269
	fi
fi

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#
# deploy package configuration in /etc and /usr
#
cd $BASEDIR
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
	if [ -d "hosts/$h/etc/sudoers.d/" ]; then
		for f in "hosts/$h/etc/sudoers.d/"* ; do
			/usr/sbin/visudo -c -f "$f" > /dev/null
		done
	fi
	for d in etc usr ; do
		if [ -d "hosts/$h/$d" ]; then
			sudo cp --preserve=mode,timestamps -r "hosts/$h/$d/"* "/$d"
		fi
	done
done
294
295
# We really don't need the man database here, save time.
$UP2DATE || echo "man-db man-db/auto-update boolean false" | sudo debconf-set-selections
296
297
298
299
300


#
# install packages we need
#
301
# only on Debian-based systems
302
if [ -f /etc/debian_version ] ; then
303
	if [ $BASEDIR/$0 -nt $STAMP ] || [ ! -f $STAMP ] ; then
304
		DEBS="
305
			apt-utils
Holger Levsen's avatar
Holger Levsen committed
306
			bash-completion 
307
308
			bc
			bsd-mailx
309
310
			curl
			debian-archive-keyring
311
			cdebootstrap-
312
			debootstrap
313
			devscripts
314
			eatmydata
315
			etckeeper
316
			figlet
Holger Levsen's avatar
Holger Levsen committed
317
			git
Holger Levsen's avatar
Holger Levsen committed
318
			gnupg
319
			haveged
Holger Levsen's avatar
Holger Levsen committed
320
			htop
321
			less
322
			liquidprompt
323
			locales-all
Mattia Rizzolo's avatar
Mattia Rizzolo committed
324
			lsof
325
326
			molly-guard
			moreutils
Holger Levsen's avatar
Holger Levsen committed
327
			mosh
328
329
330
			munin-node
			munin-plugins-core
			munin-plugins-extra
Holger Levsen's avatar
Holger Levsen committed
331
			needrestart
332
			netcat-traditional
333
334
			ntp
			ntpdate
335
			pbuilder
336
			pigz 
337
			postfix
338
			procmail
339
			psmisc
340
			python3-psycopg2 
341
			python3-yaml
Holger Levsen's avatar
Holger Levsen committed
342
			schroot 
343
344
			screen
			slay
345
			stunnel
Holger Levsen's avatar
Holger Levsen committed
346
347
348
			subversion 
			subversion-tools 
			sudo 
349
			systemd-sysv
350
			tmux
Holger Levsen's avatar
Holger Levsen committed
351
352
			unzip 
			vim 
353
			zsh
354
			"
355
		case $HOSTNAME in
356
			codethink*)
357
358
				# the apt_preferences(5) file will cause some packages to come
				# from Debian backports
359
360
				# munin-node from buster-backports requires init-system-helpers>=1.54
				# which is available in bionic-backports, we only need to convince apt
361
362
363
364
				DEBS="$DEBS
				init-system-helpers/bionic-backports
				" ;;
			*)	# packages to be installed on all Debian systems but which are not available in Ubuntu 18.04:
365
				DEBS="$DEBS
366
				fasttrack-archive-keyring
367
368
				ripgrep
				mmdebstrap
369
370
				" ;;
		esac
371
		# special case bullseye-backports:
372
		case $HOSTNAME in
373
			X)
374
				DEBS="$DEBS
375
				devscripts/bullseye-backports
376
				" ;;
377
			*)	;;
378
		esac
379
		case $HOSTNAME in
380
			# needed for rebuilding Debian (using .buildinfo files)
381
382
			osuosl173-amd64) DEBS="$DEBS libdpkg-perl libwww-mechanize-perl sbuild" 
					 DEBS="$DEBS live-build" ;; # needed for live-build
383
			# needed for opensuse openbuildservice
384
			osuosl174-amd64) DEBS="$DEBS osc obs-build qemu-kvm libarchive-tools libjson-perl libxml-simple-perl" ;;
385
386
			*) ;;
		esac
387
388
		# install stuff for bremner's builtin-pho stuff
		# and building html pages there too
389
		# and for the rebuilder 'thing' too
390
		case $HOSTNAME in
391
			ionos7-a*) DEBS="$DEBS
392
				postgresql
393
				postgresql-13-debversion
394
				python3-pystache
395
				python3-apt
396
397
				python3-psycopg2
				sbuild" ;;
398
399
			*) ;;
		esac
400
		# install squid / apache2 on a few nodes only
401
		case $HOSTNAME in
402
			ionos1-a*|ionos10*|codethink16*|osuosl*) DEBS="$DEBS
403
				squid" ;;
404
			ionos7-a*) DEBS="$DEBS
405
406
				dehydrated
				dehydrated-apache2
407
				apache2" ;;
408
409
			*) ;;
		esac
Jelmer Vernooij's avatar
Jelmer Vernooij committed
410
411
		# install lintian-brush dependencies for debian-janitor
		case $HOSTNAME in
412
			# TODO(jelmer): Add python3-tr once it hits backports
413
			osuosl167*) DEBS="$DEBS
414
				cargo
415
				cython3
Jelmer Vernooij's avatar
Jelmer Vernooij committed
416
417
				devscripts
				python3-aiohttp
418
				python3-all-dev
419
420
				dpkg-source-gitarchive
				python3-asyncpg
421
				python3-bs4
422
423
				python3-certifi
				python3-configobj
Jelmer Vernooij's avatar
Jelmer Vernooij committed
424
				python3-debian
425
				python3-docutils
Jelmer Vernooij's avatar
Jelmer Vernooij committed
426
427
				python3-dulwich
				python3-distro-info
428
				python3-fastimport
Jelmer Vernooij's avatar
Jelmer Vernooij committed
429
				python3-iniparse
430
				python3-jinja2
431
				python3-launchpadlib
Jelmer Vernooij's avatar
Jelmer Vernooij committed
432
				python3-levenshtein
433
				python3-lz4
434
				python3-markdown
435
				python3-merge3
436
				python3-paramiko
437
				python3-patiencediff
Jelmer Vernooij's avatar
Jelmer Vernooij committed
438
				python3-pkginfo
439
				python3-prometheus-client
440
				python3-pyinotify
441
				python3-requirement-parser
Jelmer Vernooij's avatar
Jelmer Vernooij committed
442
				python3-ruamel.yaml
443
				python3-semver
444
445
446
447
				python3-setuptools
				python3-six
				python3-subunit
				python3-testtools
448
				python3-toml
449
				python3-tomlkit
Holger Levsen's avatar
Holger Levsen committed
450
				python3-urllib3
451
				python3-yaml
452
				rustc
Holger Levsen's avatar
Holger Levsen committed
453
				sbuild
Jelmer Vernooij's avatar
Jelmer Vernooij committed
454
455
456
457
458
				gnome-pkg-tools
				postgresql-server-dev-all
				lintian
				dos2unix
				gpg
459
				libdebhelper-perl
460
				quilt
461
				debcargo
Jelmer Vernooij's avatar
Jelmer Vernooij committed
462
				cme
463
				debhelper
Jelmer Vernooij's avatar
Jelmer Vernooij committed
464
				decopy
Jelmer Vernooij's avatar
Jelmer Vernooij committed
465
466
				" ;;
		esac
467
		# notifications are only done from a few nodes
468
		case $HOSTNAME in
469
			jenkins|ionos*|osuosl167-amd64) DEBS="$DEBS
470
471
				kgb-client
				python3-yaml" ;;
472
473
			*) ;;
		esac
474
475
		# needed to run the 2nd reproducible builds nodes in the future...
		case $HOSTNAME in
476
			ionos5-amd64|ionos6-i386|ionos15-amd64|ionos16-i386) DEBS="$DEBS ntpdate" ;;
477
			codethink9*|codethink11*|codethink13*|codethink15*) DEBS="$DEBS ntpdate" ;;
478
			osuosl170-amd64|osuosl172-amd64) DEBS="$DEBS ntpdate" ;;
479
480
			*) ;;
		esac
481
		# needed to run coreboot/openwrt/netbsd/fedora jobs
482
		case $HOSTNAME in
483
		osuosl171-amd64|osuosl172-amd64) DEBS="$DEBS
Holger Levsen's avatar
Holger Levsen committed
484
				bison
485
				ca-certificates
Holger Levsen's avatar
Holger Levsen committed
486
487
488
				cmake
				diffutils
				findutils
489
				fish
Holger Levsen's avatar
Holger Levsen committed
490
491
492
493
				flex
				g++
				gawk
				gcc
494
				gnat
Holger Levsen's avatar
Holger Levsen committed
495
496
497
498
499
500
501
502
				grep
				libc6-dev
				libncurses5-dev
				libssl-dev
				locales-all
				kgb-client
				m4
				make
503
504
				python3-clint
				python3-git
505
				python3-pystache
506
				python3-requests
Holger Levsen's avatar
Holger Levsen committed
507
508
				python3-yaml
				subversion
509
				tree
Holger Levsen's avatar
Holger Levsen committed
510
511
				unzip
				util-linux
512
513
				zlib1g-dev
				"
514
515
516
			;;
			*) ;;
		esac
517
518
		# needed to run fdroid jobs
		case $HOSTNAME in
519
			osuosl168-amd64) DEBS="$DEBS
520
				androguard
521
				android-sdk
522
523
				bzr
				git-svn
524
				fdroidserver
525
				linux-headers-amd64
526
				mercurial
527
				python3-asn1crypto
528
				python3-babel
529
				python3-mwclient
530
				python3-setuptools
531
				subversion
532
				vagrant
Mattia Rizzolo's avatar
Mattia Rizzolo committed
533
				virtualbox/bullseye-fasttrack virtualbox-dkms/bullseye-fasttrack
534
				"
535
				;;
536
			*) ;;
537
		esac
538
		if [ "$HOSTNAME" = "osuosl167-amd64" ]; then
539
540
			# for phil only
			DEBS="$DEBS postfix-pcre"
541
			# OpenQA worker -- currently installed with help from:
Philip Hands's avatar
Philip Hands committed
542
543
544
545
			#   hosts/osuosl167-amd64/etc/apt/sources.list.d/philh-openqa.list
			DEBS="$DEBS
				openqa-worker
				"
546
547
			# only needed on the main node
		elif [ "$HOSTNAME" = "jenkins" ] ; then
548
			DEBS="$DEBS ffmpeg python3-popcon dose-extra"
549
		fi
550
551
552
553
554
555
556
		# packages needed for snapshot.reproducible-builds.org
		case $HOSTNAME in
			snapshot*)	DEBS="$DEBS
					xfsprogs
					" ;;
						*) ;;
		esac
557
		# mock is needed to build fedora
558
559
560
		#if [ "$HOSTNAME" = "osuosl171-amd64" ] || [ "$HOSTNAME" = "osuosl172-amd64" ] || [ "$HOSTNAME" = "jenkins" ] ; then
		#	DEBS="$DEBS mock"
		#fi
561
		# only on main node
562
		if [ "$HOSTNAME" = "jenkins" ] ; then
563
564
			# required by _db_backup, but not available in bullseye.  https://bugs.debian.org/970870
			#postgresql-autodoc
Holger Levsen's avatar
Holger Levsen committed
565
566
567
568
			MASTERDEBS=" 
				apache2 
				apt-file 
				apt-listchanges 
569
				asciidoc
Holger Levsen's avatar
Holger Levsen committed
570
				binfmt-support 
571
572
				bison
				botch
Holger Levsen's avatar
Holger Levsen committed
573
574
575
576
				build-essential 
				cmake 
				cron-apt 
				csvtool 
577
578
				dehydrated
				dehydrated-apache2
Holger Levsen's avatar
Holger Levsen committed
579
580
581
				dnsmasq-base 
				dstat 
				figlet 
Holger Levsen's avatar
Holger Levsen committed
582
				flex
Holger Levsen's avatar
Holger Levsen committed
583
				gawk 
584
				ghc
585
				git-lfs
Holger Levsen's avatar
Holger Levsen committed
586
587
588
589
				gocr 
				graphviz 
				iasl 
				imagemagick 
590
591
				ip2host
				jekyll
592
				jenkins-job-builder
593
				jq
594
				kgb-client
Holger Levsen's avatar
Holger Levsen committed
595
				libcap2-bin 
596
				libarchive-tools
Holger Levsen's avatar
Holger Levsen committed
597
598
599
600
601
602
603
604
				libfile-touch-perl 
				libguestfs-tools 
				libjson-rpc-perl 
				libsoap-lite-perl 
				libxslt1-dev 
				moreutils 
				mr 
				mtr-tiny 
605
				munin
Holger Levsen's avatar
Holger Levsen committed
606
				ntp 
607
				obfs4proxy
Holger Levsen's avatar
Holger Levsen committed
608
609
				openbios-ppc 
				openbios-sparc 
610
				openjdk-11-jre-headless
611
				pandoc
612
				postgresql
613
				postgresql-client 
Holger Levsen's avatar
Holger Levsen committed
614
615
616
				poxml 
				procmail 
				python3-debian 
617
				python3-pystache
618
				python3-requests
619
				python3-rpy2 
620
621
622
				python3-sqlalchemy
				python3-xdg
				python3-yaml
Holger Levsen's avatar
Holger Levsen committed
623
624
625
626
				qemu 
				qemu-kvm 
				qemu-system-x86 
				qemu-user-static 
627
				radvd
628
				ruby-jekyll-polyglot
629
				ruby-jekyll-redirect-from
630
631
				ruby-rspec
				rustc
Holger Levsen's avatar
Holger Levsen committed
632
633
634
635
				seabios 
				shorewall 
				shorewall6 
				sqlite3 
636
				syslinux
637
				systemd
638
				thin-provisioning-tools
639
				tor
Holger Levsen's avatar
Holger Levsen committed
640
				vncsnapshot 
641
642
				vnstat
				whohas
Holger Levsen's avatar
Holger Levsen committed
643
				x11-apps 
644
				xtightvncviewer
645
				xvfb
646
				xvkbd
647
648
				zutils
				"
649
650
651
		else
			MASTERDEBS=""
		fi
652
		$UP2DATE || sudo apt-get update
653
		$UP2DATE || sudo apt-get install $DEBS $MASTERDEBS
654
		# for varying kernels:
655
		# - we use bpo kernels on ionos5+15 (and the default amd64 kernel on ionos6+16-i386)
656
		# - we also use the bpo kernel on osuosl172 (but not osuosl171)
657
		# - this is done as a seperate step as bpo kernels are frequently uninstallable when upgraded on bpo
658
		if [ "$HOSTNAME" = "ionos5-amd64" ] || [ "$HOSTNAME" = "ionos15-amd64" ] \
659
			|| [ "$HOSTNAME" = "osuosl172-amd64" ] ; then
660
			sudo apt install linux-image-amd64/bullseye-backports || true # backport kernels are frequently uninstallable...
661
			:
662
663
664
665
666
667
		elif [ "$HOSTNAME" = "ionos6-i386" ] || [ "$HOSTNAME" = "ionos16-i386" ] ; then
			# run with the amd64 kernel in these i386 nodes
			sudo apt install linux-image-amd64 linux-image-686-pae-
		elif [ "$HOSTNAME" = "ionos2-i386" ] || [ "$HOSTNAME" = "ionos12-i386" ] ; then
			# run with the i386 kernel in these i386 nodes
			sudo apt install linux-image-686-pae linux-image-amd64-
668
		elif [ "$HOSTNAME" = "osuosl169-amd64" ] || [ "$HOSTNAME" = "osuosl170-amd64" ] || [ "$HOSTNAME" = "osuosl173-amd64" ]; then
669
			# Arch Linux builds latest stuff which sometimes (eg, currentlt Qt) needs newer kernel to build...
670
			sudo apt install linux-image-amd64/bullseye-backports || true # backport kernels are frequently uninstallable...
671
			:
672
		fi
Edward Betts's avatar
Edward Betts committed
673
		# don't (re-)install pbuilder if it's on hold
674
		if [ "$(dpkg-query -W -f='${db:Status-Abbrev}\n' pbuilder)" != "hi " ] ; then
675
			$UP2DATE || sudo apt-get install pbuilder
676
		fi
677
		# remove unattended-upgrades if it's installed
678
		if [ "$(dpkg-query -W -f='${db:Status-Abbrev}\n' unattended-upgrades 2>/dev/null || true)" = "ii "  ] ; then
679
			 sudo apt-get -y purge unattended-upgrades
680
		fi
681
		sudo apt-get clean
Holger Levsen's avatar
Holger Levsen committed
682
		explain "packages installed."
683
	else
Holger Levsen's avatar
Holger Levsen committed
684
		explain "no new packages to be installed."
685
	fi
686
fi
687

688
# remove munin-async (if it's installed which happens during setup as it's a recommends)
Holger Levsen's avatar
Holger Levsen committed
689
# harmless but has a service which can fail and thus can make maintenance jobs unstable
690
( dpkg -l munin-async 2>/dev/null && sudo apt-get remove munin-async ) || true
Holger Levsen's avatar
Holger Levsen committed
691

692
# we ship one or two service files…
693
sudo systemctl daemon-reload
694
695
696
697
698

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

702
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ]; then
703
704
705
706
707
708
709
	for path in /var/lib/dehydrated /var/lib/dehydrated/acme-challenges; do
		if ! dpkg-statoverride --list "$path" > /dev/null; then
			sudo dpkg-statoverride --update --add letsencrypt letsencrypt 755 "$path"
		fi
	done
fi

710
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ] ; then
711
	if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/apache2 -nt $STAMP ]  ; then
712
713
714
715
716
717
718
719
720
		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
721
722
723
724
725
726
727
728
729
730
731
		case "$HOSTNAME" in
			jenkins)
				sudo a2ensite -q jenkins.debian.net
				sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/jenkins.debian.net.conf
				sudo a2enconf -q munin
				;;
			ionos7-amd64)
				sudo a2ensite -q buildinfos.debian.net
				sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/buildinfos.debian.net.conf
				;;
		esac
732
733
734
		# for reproducible.d.n url rewriting:
		[ -L /var/www/userContent ] || sudo ln -sf /var/lib/jenkins/userContent /var/www/userContent
		sudo service apache2 reload
735
736
737
	fi
fi

738
if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/munin -nt $STAMP ] ; then
739
	cd /etc/munin/plugins
740
	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
741
	case $HOSTNAME in
742
			ionos1-a*|ionos10*|codethink16*|osuosl*) [ -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 ;;
743
744
			*)	;;
	esac
Holger Levsen's avatar
Holger Levsen committed
745
746
747
748
	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
749
750
751
	if [ "$HOSTNAME" != "jenkins" ] && [ -L /etc/munin/plugins/iostat ] ; then
		sudo rm /etc/munin/plugins/iostat
	fi
752
	if ( [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ] ) && [ ! -L /etc/munin/plugins/apache_accesses ] ; then
753
		for i in apache_accesses apache_volume ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done
754
		sudo ln -s /usr/share/munin/plugins/loggrep jenkins_oom
755
	fi
756
757
	# 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
758
fi
759
760
761
762

# add some users to groups after packages have been installed
if ! $UP2DATE ; then
	case $HOSTNAME in
763
		jenkins|osuosl169-amd64|osuosl170-amd64|osuosl173-amd64)
764
			# for building Archlinux
765
766
767
			sudo addgroup --system --gid 300 abuild
			sudo adduser jenkins abuild
			;;
768
		osuosl173-amd64)		sudo adduser jenkins sbuild ;;
769
770
771
772
		*) 				;;
	esac
fi
# finally
Holger Levsen's avatar
Holger Levsen committed
773
explain "packages configured."
Holger Levsen's avatar
Holger Levsen committed
774
775
776
777

#
# install the heart of jenkins.debian.net
#
Holger Levsen's avatar
Holger Levsen committed
778
cd $BASEDIR
779
[ -d /srv/jenkins/features ] && sudo rm -rf /srv/jenkins/features
780
# check for bash syntax *before* actually deploying anything
781
shopt -s nullglob
782
for f in bin/*.sh bin/**/*.sh ; do bash -n "$f" ; done
783
shopt -u nullglob
784
for dir in bin logparse mustache-templates ; do
785
786
	sudo mkdir -p /srv/jenkins/$dir
	sudo rsync -rpt --delete $dir/ /srv/jenkins/$dir/
Holger Levsen's avatar
Holger Levsen committed
787
	sudo chown -R jenkins-adm.jenkins-adm /srv/jenkins/$dir
788
done
789
790
HOST_JOBS="hosts/$HOSTNAME/job-cfg"
if [ -e "$HOST_JOBS" ] ; then
791
	sudo -u jenkins-adm rsync -rpt --copy-links --delete "$HOST_JOBS/" /srv/jenkins/job-cfg/
792
else
Philip Hands's avatar
Philip Hands committed
793
794
	# tidying up ... assuming that we don't want clutter on peripheral servers
	[ -d /srv/jenkins/job-cfg ] && sudo rm -rf /srv/jenkins/job-cfg
795
796
fi

797

798
sudo mkdir -p -m 700 /var/lib/jenkins/.ssh
799
sudo chown jenkins.jenkins /var/lib/jenkins/.ssh
800
if [ "$HOSTNAME" = "jenkins" ] ; then
801
802
	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
803
	sudo -u jenkins cp jenkins-home/offline_nodes /var/lib/jenkins/offline_nodes
804
805
806
else
	sudo cp jenkins-nodes-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
fi
807
if [ -f jenkins-nodes-home/authorized_keys.$HOSTNAME ] ; then
808
	cat jenkins-nodes-home/authorized_keys.$HOSTNAME | sudo tee -a /var/lib/jenkins/.ssh/authorized_keys
809
fi
810
sudo -u jenkins cp jenkins-home/gitconfig /var/lib/jenkins/.gitconfig
811
812
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
813
nodes/gen_known_host_file | sudo tee /etc/ssh/ssh_known_hosts > /dev/null
Holger Levsen's avatar
Holger Levsen committed
814
explain "scripts and configurations for jenkins updated."
815

816
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
817
	sudo cp -pr README INSTALL TODO CONTRIBUTING d-i-preseed-cfgs /var/lib/jenkins/userContent/
818
	TMPFILE=$(mktemp)
819
	git log | grep ^Author| cut -d " " -f2-|sort -u -f > $TMPFILE
820
	echo "----" >> $TMPFILE
821
	sudo tee /var/lib/jenkins/userContent/THANKS > /dev/null < THANKS.head
Holger Levsen's avatar
Holger Levsen committed
822
	# several people committed with several committers, only display one
823
	DUPLICATES="samuel.thibault@ens-lyon.org|Jérémy Bobbio|j.schauer@email.de|mattia@mapreri.org|phil@jenkins-test-vm|jelle@vdwaa.nl|<kpcyrd>|vagrant@debian.org"
Holger Levsen's avatar
Holger Levsen committed
824
	grep -E -v "$DUPLICATES" $TMPFILE | sudo tee -a /var/lib/jenkins/userContent/THANKS > /dev/null
825
	rm $TMPFILE
826
	TMPDIR=$(mktemp -d -t update-jdn-XXXXXXXX)
827
	sudo cp -pr userContent $TMPDIR/
Holger Levsen's avatar
Holger Levsen committed
828
829
830
	sudo chown -R jenkins.jenkins $TMPDIR
	sudo cp -pr $TMPDIR/userContent  /var/lib/jenkins/
	sudo rm -r $TMPDIR > /dev/null
831
832
833
834
835
836
837
838
839
	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
840
	sudo chown jenkins.jenkins /var/lib/jenkins/userContent/*html
Holger Levsen's avatar
Holger Levsen committed
841
	explain "user content for jenkins updated."
842
fi
843

844
if [ "$HOSTNAME" = "jenkins" ] ; then
845
846
847
848
849
850
	#
	# 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
851
852
853
854
855
856
		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
857
858
859
		fi
	done
	for config in *.yaml ; do
860
861
862
863
864
865
866
		# 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
867
			echo "$config has changed, executing updates."
868
			$JJB update $config # FIXME: we should use sudo and run $JJB as jenkins or jenkins-adm
869
870
		fi
	done
Holger Levsen's avatar
Holger Levsen committed
871
	explain "jenkins jobs updated."
872
fi
873

874
875
876
#
# generate the kgb-client configurations
#
877
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "osuosl168-amd64" ] || [ "$HOSTNAME" = "osuosl171-amd64" ] || [ "$HOSTNAME" = "osuosl172-amd64" ] || [ "$HOSTNAME" = "ionos2-i386" ] || [ "$HOSTNAME" = "ionos12-i386" ] ; then
878
879
880
	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
881
		# the last condition is to assure the files are owned by the right user/team
882
883
		if [ "$KGB_SECRETS" -nt $STAMP ] || [ "/srv/jenkins/bin/deploy_kgb.py" -nt "$STAMP" ] || [ ! -f $STAMP ] ; then
			sudo -u jenkins-adm "/srv/jenkins/bin/deploy_kgb.py"
Philip Hands's avatar
Philip Hands committed
884
885
886
		else
			explain "kgb-client configuration unchanged, nothing to do."
		fi
887
	else
Philip Hands's avatar
Philip Hands committed
888
889
890
		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
891
892
		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."
893
	fi
894
	KGB_STATUS="/srv/jenkins/kgb/client-status"
895
896
	sudo mkdir -p $KGB_STATUS
	sudo chown jenkins:jenkins $KGB_STATUS
897
898
fi

899
900
901
#
# Create GPG key for jenkins user if they do not already exist (eg. to sign .buildinfo files)
#
902
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
903
	: # not generating GPG key as one already exists for jenkins user
904
else
Holger Levsen's avatar
Holger Levsen committed
905
	explain "$(date) - Generating GPG key for jenkins user."
906

907
	sudo -H -u jenkins gpg --no-tty --batch --gen-key <<EOF
908
909
910
Key-Type: RSA
Key-Length: 4096
Key-Usage: sign
911
Name-Real: $HOSTNAME
912
913
914
915
916
917
Name-Comment: Automatically generated key for signing .buildinfo files
Expire-Date: 0
%no-ask-passphrase
%no-protection
%commit
EOF
918

919
	GPG_KEY_ID="$(sudo -H -u jenkins gpg --with-colons --fixed-list-mode --list-secret-keys | grep '^sec' | cut -d: -f5 | tail -n1)"
920
921
922
923
924
925

	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"
926
		sudo -H -u jenkins gpg --send-keys $GPG_KEY_ID
927
	fi
928
929
fi

930

931
#
932
# almost finally…
933
#
934
sudo touch $STAMP	# so on the next run, only configs newer than this file will be updated
Holger Levsen's avatar
Holger Levsen committed
935
explain "$(date) - finished deployment."
936

937
938
939
940
#
# some final checks only for the jenkins
#
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
941
	jenkins_bugs_check
Holger Levsen's avatar
Holger Levsen committed
942
	explain "$(date) - done checking for known jenkins bugs."
943
944
fi

Holger Levsen's avatar
Holger Levsen committed
945
#
946
# finally!
Holger Levsen's avatar
Holger Levsen committed
947
#
948
case $HOSTNAME in
949
	# set time back to the future
950
	ionos5-amd64|ionos6-i386|ionos15-amd64|ionos16-i386)
951
		disable_dsa_check_packages
952
953
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
954
	codethink9*|codethink11*|codethink13*|codethink15*)
955
		disable_dsa_check_packages
956
957
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
958
	osuosl170-amd64|osuosl172-amd64)
959
960
961
		disable_dsa_check_packages
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
962
	jenkins)
963
		# notify irc on updates of jenkins.d.n
964
965
		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
966
		;;
967
968
	*)	;;
esac
969
970
971
972

echo
figlet ok
echo
Holger Levsen's avatar
Holger Levsen committed
973
974
echo "__$HOSTNAME=ok__"