update_jdn.sh 28.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','jenkins-test-vm']="$sudo_groups,libvirt,libvirt-qemu"
120
user_host_groups['phil','osuosl167-amd64']="$sudo_groups,libvirt,libvirt-qemu"
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"
Mattia Rizzolo's avatar
Mattia Rizzolo committed
131
user_host_groups['vagrant','*']="$sudo_groups"
132
user_host_groups['bernhard','osuosl174-amd64']="$sudo_groups"
133
user_host_groups['santiago','ionos3-amd64']="$sudo_groups"
134
135

u_shell['mattia']='/bin/zsh'
136
u_shell['lynxis']='/usr/bin/fish'
137

138
139
140
# 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)

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

148
149
	# 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
150
	if [ "$HOSTNAME" = jenkins ] || [ "$HOSTNAME" = "ionos7-amd64" ]; then
151
152
153
		if ! getent group letsencrypt > /dev/null ; then
			sudo addgroup --system letsencrypt
		fi
154
		if ! getent passwd letsencrypt > /dev/null ; then
155
156
157
158
159
160
161
162
163
164
165
			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

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

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

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

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

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

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

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

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

630
#
Holger Levsen's avatar
Holger Levsen committed
631
# deploy package configuration in /etc and /usr
632
#
Holger Levsen's avatar
Holger Levsen committed
633
cd $BASEDIR
634
635
636
637
638
639
640
641
642
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
643
644
	if [ -d "hosts/$h/etc/sudoers.d/" ]; then
		for f in "hosts/$h/etc/sudoers.d/"* ; do
645
			/usr/sbin/visudo -c -f "$f" > /dev/null
646
647
648
		done
	fi
	for d in etc usr ; do
Mattia Rizzolo's avatar
Mattia Rizzolo committed
649
		if [ -d "hosts/$h/$d" ]; then
650
			sudo cp --preserve=mode,timestamps -r "hosts/$h/$d/"* "/$d"
651
652
653
		fi
	done
done
654
# we ship one or two service files…
655
sudo systemctl daemon-reload
656
657
658
659
660

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

664
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ]; then
665
666
667
668
669
670
671
	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

672
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ] ; then
673
	if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/apache2 -nt $STAMP ]  ; then
674
675
676
677
678
679
680
681
682
		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
683
684
685
		if [ "$HOSTNAME" = "jenkins" ] ; then
			sudo a2ensite -q jenkins.debian.net
			sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/jenkins.debian.net.conf
686
			sudo a2enconf -q munin
687
		else # "$HOSTNAME" = "ionos7-amd64"
688
689
690
			sudo a2ensite -q buildinfos.debian.net
			sudo chown jenkins-adm.jenkins-adm /etc/apache2/sites-enabled/buildinfos.debian.net.conf
		fi
691
692
693
		# for reproducible.d.n url rewriting:
		[ -L /var/www/userContent ] || sudo ln -sf /var/lib/jenkins/userContent /var/www/userContent
		sudo service apache2 reload
694
695
696
	fi
fi

697
if ! $UP2DATE || [ $BASEDIR/hosts/$HOSTNAME/etc/munin -nt $STAMP ] ; then
698
	cd /etc/munin/plugins
699
	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
700
	case $HOSTNAME in
701
			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 ;;
702
703
			*)	;;
	esac
Holger Levsen's avatar
Holger Levsen committed
704
705
706
707
	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
708
709
710
	if [ "$HOSTNAME" != "jenkins" ] && [ -L /etc/munin/plugins/iostat ] ; then
		sudo rm /etc/munin/plugins/iostat
	fi
711
	if ( [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "ionos7-amd64" ] ) && [ ! -L /etc/munin/plugins/apache_accesses ] ; then
712
		for i in apache_accesses apache_volume ; do sudo ln -s /usr/share/munin/plugins/$i $i ; done
713
		sudo ln -s /usr/share/munin/plugins/loggrep jenkins_oom
714
	fi
715
716
	# 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
717
fi
718
719
720
721

# add some users to groups after packages have been installed
if ! $UP2DATE ; then
	case $HOSTNAME in
722
		jenkins|osuosl169-amd64|osuosl170-amd64|osuosl173-amd64)
723
			# for building Archlinux
724
725
726
			sudo addgroup --system --gid 300 abuild
			sudo adduser jenkins abuild
			;;
727
		osuosl173-amd64)		sudo adduser jenkins sbuild ;;
728
729
730
731
		*) 				;;
	esac
fi
# finally
Holger Levsen's avatar
Holger Levsen committed
732
explain "packages configured."
Holger Levsen's avatar
Holger Levsen committed
733
734
735
736

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

756

757
sudo mkdir -p -m 700 /var/lib/jenkins/.ssh
758
sudo chown jenkins.jenkins /var/lib/jenkins/.ssh
759
if [ "$HOSTNAME" = "jenkins" ] ; then
760
761
	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
762
	sudo -u jenkins cp jenkins-home/offline_nodes /var/lib/jenkins/offline_nodes
763
764
765
else
	sudo cp jenkins-nodes-home/authorized_keys /var/lib/jenkins/.ssh/authorized_keys
fi
766
if [ -f jenkins-nodes-home/authorized_keys.$HOSTNAME ] ; then
767
	cat jenkins-nodes-home/authorized_keys.$HOSTNAME | sudo tee -a /var/lib/jenkins/.ssh/authorized_keys
768
fi
769
sudo -u jenkins cp jenkins-home/gitconfig /var/lib/jenkins/.gitconfig
770
771
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
772
nodes/gen_known_host_file | sudo tee /etc/ssh/ssh_known_hosts > /dev/null
Holger Levsen's avatar
Holger Levsen committed
773
explain "scripts and configurations for jenkins updated."
774

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

803
if [ "$HOSTNAME" = "jenkins" ] || [ "$HOSTNAME" = "jenkins-test-vm" ] ; then
804
805
806
807
808
809
	#
	# 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
810
811
812
813
814
815
		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
816
817
818
		fi
	done
	for config in *.yaml ; do
819
820
821
822
823
824
825
		# 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
826
			echo "$config has changed, executing updates."
827
			$JJB update $config # FIXME: we should use sudo and run $JJB as jenkins or jenkins-adm
828
829
		fi
	done
Holger Levsen's avatar
Holger Levsen committed
830
	explain "jenkins jobs updated."
831
fi
832

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

858
859
860
#
# Create GPG key for jenkins user if they do not already exist (eg. to sign .buildinfo files)
#
861
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
862
	: # not generating GPG key as one already exists for jenkins user
863
else
Holger Levsen's avatar
Holger Levsen committed
864
	explain "$(date) - Generating GPG key for jenkins user."
865

866
	sudo -H -u jenkins gpg --no-tty --batch --gen-key <<EOF
867
868
869
Key-Type: RSA
Key-Length: 4096
Key-Usage: sign
870
Name-Real: $HOSTNAME
871
872
873
874
875
876
Name-Comment: Automatically generated key for signing .buildinfo files
Expire-Date: 0
%no-ask-passphrase
%no-protection
%commit
EOF
877

878
	GPG_KEY_ID="$(sudo -H -u jenkins gpg --with-colons --fixed-list-mode --list-secret-keys | grep '^sec' | cut -d: -f5 | tail -n1)"
879
880
881
882
883
884

	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"
885
		sudo -H -u jenkins gpg --send-keys $GPG_KEY_ID
886
	fi
887
888
fi

889
#
890
# almost finally…
891
#
892
sudo touch $STAMP	# so on the next run, only configs newer than this file will be updated
Holger Levsen's avatar
Holger Levsen committed
893
explain "$(date) - finished deployment."
894

895
896
897
898
#
# some final checks only for the jenkins
#
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
899
	jenkins_bugs_check
Holger Levsen's avatar
Holger Levsen committed
900
	explain "$(date) - done checking for known jenkins bugs."
901
902
fi

Holger Levsen's avatar
Holger Levsen committed
903
#
904
# finally!
Holger Levsen's avatar
Holger Levsen committed
905
#
906
case $HOSTNAME in
907
	# set time back to the future
908
	ionos5-amd64|ionos6-i386|ionos15-amd64|ionos16-i386)
909
		disable_dsa_check_packages
910
911
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
912
	codethink9*|codethink11*|codethink13*|codethink15*)
913
		disable_dsa_check_packages
914
915
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
916
	osuosl170-amd64|osuosl172-amd64)
917
918
919
		disable_dsa_check_packages
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
920
	jenkins)
921
		# notify irc on updates of jenkins.d.n
922
923
		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
924
		;;
925
926
	*)	;;
esac
927
928
929
930

echo
figlet ok
echo
Holger Levsen's avatar
Holger Levsen committed
931
932
echo "__$HOSTNAME=ok__"