update_jdn.sh 28.9 KB
Newer Older
1
#!/bin/bash
2
# vim: set noexpandtab:
3
# Copyright 2012-2022 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
# Add your username and the hostname
# Place your public key in 'authorized_keys/<username>@<something_identifiable>.pub'
# The port number of the ssh server is listed in 'nodes/list.yml'
117
118
119
120
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"
121
user_host_groups['mattia','jenkins']="reproducible,${user_host_groups['mattia','*']}"
122
user_host_groups['phil','osuosl167-amd64']="$sudo_groups"
123
user_host_groups['jelmer','osuosl167-amd64']="$sudo_groups"
124
user_host_groups['phil','jenkins']="$sudo_groups"
125
user_host_groups['lunar','jenkins']='reproducible'
126
127
user_host_groups['lynxis','osuosl171-amd64']="$sudo_groups"
user_host_groups['lynxis','osuosl172-amd64']="$sudo_groups"
128
user_host_groups['lynxis','jenkins']="jenkins"
129
user_host_groups['kpcyrd','osuosl184-amd64']="$sudo_groups"
130
user_host_groups['kpcyrd','osuosl170-amd64']="$sudo_groups"
131
user_host_groups['kpcyrd','jenkins']="jenkins"
132
133
user_host_groups['bubu','osuosl168-amd64']="$sudo_groups"
user_host_groups['hans','osuosl168-amd64']="$sudo_groups"
134
user_host_groups['flx','osuosl168-amd64']="$sudo_groups"
135
user_host_groups['jspricke','osuosl168-amd64']="$sudo_groups"
Mattia Rizzolo's avatar
Mattia Rizzolo committed
136
user_host_groups['vagrant','*']="$sudo_groups"
137
user_host_groups['bernhard','osuosl174-amd64']="$sudo_groups"
138
user_host_groups['santiago','ionos3-amd64']="$sudo_groups"
139
user_host_groups['fpierret','snapshot']="$sudo_groups"
140
user_host_groups['rclobus','osuosl173-amd64']="$sudo_groups"
141
142

u_shell['mattia']='/bin/zsh'
143
u_shell['lynxis']='/usr/bin/fish'
144

145
146
147
# 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)

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

155
156
	# 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
157
	if [ "$HOSTNAME" = jenkins ] || [ "$HOSTNAME" = "ionos7-amd64" ]; then
158
159
160
		if ! getent group letsencrypt > /dev/null ; then
			sudo addgroup --system letsencrypt
		fi
161
		if ! getent passwd letsencrypt > /dev/null ; then
162
163
164
165
166
167
168
169
170
171
172
			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

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

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

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

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

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

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#
# 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
293
294
# 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
295
296
297
298
299


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

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

661
# we ship one or two service files…
662
sudo systemctl daemon-reload
663
664
665
666
667

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

671
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ]; then
672
673
674
675
676
677
678
	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

679
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ] ; then
680
	if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/apache2 -nt $STAMP ]  ; then
681
682
683
684
685
686
687
688
689
		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
690
691
692
693
694
695
696
697
698
699
700
		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
701
702
703
		# for reproducible.d.n url rewriting:
		[ -L /var/www/userContent ] || sudo ln -sf /var/lib/jenkins/userContent /var/www/userContent
		sudo service apache2 reload
704
705
706
	fi
fi

707
if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/munin -nt $STAMP ] ; then
708
	cd /etc/munin/plugins
709
	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
710
	case $HOSTNAME in
711
			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 ;;
712
713
			*)	;;
	esac
Holger Levsen's avatar
Holger Levsen committed
714
715
716
717
	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
718
719
720
	if [ "$HOSTNAME" != "jenkins" ] && [ -L /etc/munin/plugins/iostat ] ; then
		sudo rm /etc/munin/plugins/iostat
	fi
721
	if ( [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ] ) && [ ! -L /etc/munin/plugins/apache_accesses ] ; then
722
		for i in apache_accesses apache_volume ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done
723
		sudo ln -s /usr/share/munin/plugins/loggrep jenkins_oom
724
	fi
725
726
	# 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
727
fi
728
729
730
731

# add some users to groups after packages have been installed
if ! $UP2DATE ; then
	case $HOSTNAME in
732
		jenkins|osuosl184-amd64|osuosl170-amd64|osuosl173-amd64)
733
			# for building Archlinux
734
735
736
			sudo addgroup --system --gid 300 abuild
			sudo adduser jenkins abuild
			;;
737
		osuosl173-amd64)		sudo adduser jenkins sbuild ;;
738
739
740
741
		*) 				;;
	esac
fi
# finally
Holger Levsen's avatar
Holger Levsen committed
742
explain "packages configured."
Holger Levsen's avatar
Holger Levsen committed
743
744
745
746

#
# install the heart of jenkins.debian.net
#
Holger Levsen's avatar
Holger Levsen committed
747
cd $BASEDIR
748
[ -d /srv/jenkins/features ] && sudo rm -rf /srv/jenkins/features
749
# check for bash syntax *before* actually deploying anything
750
shopt -s nullglob
751
for f in bin/*.sh bin/**/*.sh ; do bash -n "$f" ; done
752
shopt -u nullglob
753
for dir in bin logparse mustache-templates ; do
754
755
	sudo mkdir -p /srv/jenkins/$dir
	sudo rsync -rpt --delete $dir/ /srv/jenkins/$dir/
Holger Levsen's avatar
Holger Levsen committed
756
	sudo chown -R jenkins-adm.jenkins-adm /srv/jenkins/$dir
757
done
758
759
HOST_JOBS="hosts/$HOSTNAME/job-cfg"
if [ -e "$HOST_JOBS" ] ; then
760
	sudo -u jenkins-adm rsync -rpt --copy-links --delete "$HOST_JOBS/" /srv/jenkins/job-cfg/
761
else
Philip Hands's avatar
Philip Hands committed
762
763
	# tidying up ... assuming that we don't want clutter on peripheral servers
	[ -d /srv/jenkins/job-cfg ] && sudo rm -rf /srv/jenkins/job-cfg
764
765
fi

766

767
sudo mkdir -p -m 700 /var/lib/jenkins/.ssh
768
sudo chown jenkins.jenkins /var/lib/jenkins/.ssh
769
if [ "$HOSTNAME" = "jenkins" ] ; then
770
771
	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
772
	sudo -u jenkins cp jenkins-home/offline_nodes /var/lib/jenkins/offline_nodes
773
774
775
else
	sudo cp jenkins-nodes-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
fi
776
if [ -f jenkins-nodes-home/authorized_keys.$HOSTNAME ] ; then
777
	cat jenkins-nodes-home/authorized_keys.$HOSTNAME | sudo tee -a /var/lib/jenkins/.ssh/authorized_keys
778
fi
779
sudo -u jenkins cp jenkins-home/gitconfig /var/lib/jenkins/.gitconfig
780
781
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
782
nodes/gen_known_host_file | sudo tee /etc/ssh/ssh_known_hosts > /dev/null
Holger Levsen's avatar
Holger Levsen committed
783
explain "scripts and configurations for jenkins updated."
784

785
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
786
	sudo cp -pr README INSTALL TODO CONTRIBUTING d-i-preseed-cfgs /var/lib/jenkins/userContent/
787
	TMPFILE=$(mktemp)
788
	git log | grep ^Author| cut -d " " -f2-|sort -u -f > $TMPFILE
789
	echo "----" >> $TMPFILE
790
	sudo tee /var/lib/jenkins/userContent/THANKS > /dev/null < THANKS.head
Holger Levsen's avatar
Holger Levsen committed
791
	# several people committed with several committers, only display one
792
	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
793
	grep -E -v "$DUPLICATES" $TMPFILE | sudo tee -a /var/lib/jenkins/userContent/THANKS > /dev/null
794
	rm $TMPFILE
795
	TMPDIR=$(mktemp -d -t update-jdn-XXXXXXXX)
796
	sudo cp -pr userContent $TMPDIR/
Holger Levsen's avatar
Holger Levsen committed
797
798
799
	sudo chown -R jenkins.jenkins $TMPDIR
	sudo cp -pr $TMPDIR/userContent  /var/lib/jenkins/
	sudo rm -r $TMPDIR > /dev/null
800
801
802
803
804
805
806
807
808
	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
809
	sudo chown jenkins.jenkins /var/lib/jenkins/userContent/*html
Holger Levsen's avatar
Holger Levsen committed
810
	explain "user content for jenkins updated."
811
fi
812

813
if [ "$HOSTNAME" = "jenkins" ] ; then
814
815
816
817
818
819
	#
	# 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
820
821
822
823
824
825
		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
826
827
828
		fi
	done
	for config in *.yaml ; do
829
830
831
832
833
834
835
		# 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
836
			echo "$config has changed, executing updates."
837
			$JJB update $config # FIXME: we should use sudo and run $JJB as jenkins or jenkins-adm
838
839
		fi
	done
Holger Levsen's avatar
Holger Levsen committed
840
	explain "jenkins jobs updated."
841
fi
842

843
844
845
#
# generate the kgb-client configurations
#
846
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "osuosl168-amd64" ] || [ "$HOSTNAME" = "osuosl171-amd64" ] || [ "$HOSTNAME" = "osuosl172-amd64" ] || [ "$HOSTNAME" = "ionos2-i386" ] || [ "$HOSTNAME" = "ionos12-i386" ] ; then
847
848
849
	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
850
		# the last condition is to assure the files are owned by the right user/team
851
852
		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
853
854
855
		else
			explain "kgb-client configuration unchanged, nothing to do."
		fi
856
	else
Philip Hands's avatar
Philip Hands committed
857
858
859
		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
860
861
		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."
862
	fi
863
	KGB_STATUS="/srv/jenkins/kgb/client-status"
864
865
	sudo mkdir -p $KGB_STATUS
	sudo chown jenkins:jenkins $KGB_STATUS
866
867
fi

868
869
870
#
# Create GPG key for jenkins user if they do not already exist (eg. to sign .buildinfo files)
#
871
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
872
	: # not generating GPG key as one already exists for jenkins user
873
else
Holger Levsen's avatar
Holger Levsen committed
874
	explain "$(date) - Generating GPG key for jenkins user."
875

876
	sudo -H -u jenkins gpg --no-tty --batch --gen-key <<EOF
877
878
879
Key-Type: RSA
Key-Length: 4096
Key-Usage: sign
880
Name-Real: $HOSTNAME
881
882
883
884
885
886
Name-Comment: Automatically generated key for signing .buildinfo files
Expire-Date: 0
%no-ask-passphrase
%no-protection
%commit
EOF
887

888
	GPG_KEY_ID="$(sudo -H -u jenkins gpg --with-colons --fixed-list-mode --list-secret-keys | grep '^sec' | cut -d: -f5 | tail -n1)"
889
890
891
892
893
894

	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"
895
		sudo -H -u jenkins gpg --send-keys $GPG_KEY_ID
896
	fi
897
898
fi

899

900
#
901
# almost finally…
902
#
903
sudo touch $STAMP	# so on the next run, only configs newer than this file will be updated
Holger Levsen's avatar
Holger Levsen committed
904
explain "$(date) - finished deployment."
905

906
907
908
909
#
# some final checks only for the jenkins
#
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
910
	jenkins_bugs_check
Holger Levsen's avatar
Holger Levsen committed
911
	explain "$(date) - done checking for known jenkins bugs."
912
913
fi

Holger Levsen's avatar
Holger Levsen committed
914
#
915
# finally!
Holger Levsen's avatar
Holger Levsen committed
916
#
917
case $HOSTNAME in
918
	# set time back to the future
919
	ionos5-amd64|ionos6-i386|ionos15-amd64|ionos16-i386)
920
		disable_dsa_check_packages
921
922
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
923
	codethink9*|codethink11*|codethink13*|codethink15*)
924
		disable_dsa_check_packages
925
926
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
927
	osuosl170-amd64|osuosl172-amd64)
928
929
930
		disable_dsa_check_packages
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
931
	jenkins)
932
		# notify irc on updates of jenkins.d.n
933
934
		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
935
		;;
936
937
	*)	;;
esac
938
939
940
941

echo
figlet ok
echo
Holger Levsen's avatar
Holger Levsen committed
942
943
echo "__$HOSTNAME=ok__"