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

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

26
27
set -e

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

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

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


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

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

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

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

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

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

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



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

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

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

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

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

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

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

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

184
185
# configure sbuild:
case $HOSTNAME in
Jelmer Vernooij's avatar
Jelmer Vernooij committed
186
	profitbricks-build7-a*|osuosl-build167*) sudo sbuild-adduser jenkins ;;
187
188
189
	*) ;;
esac

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

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

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

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

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

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

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

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

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

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

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

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

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

755

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

774
if [ "$HOSTNAME" = "jenkins" ] ; then
Holger Levsen's avatar
Holger Levsen committed
775
	sudo cp -pr README INSTALL TODO CONTRIBUTING d-i-preseed-cfgs /var/lib/jenkins/userContent/
776
	TMPFILE=$(mktemp)
777
	git log | grep ^Author| cut -d " " -f2-|sort -u -f > $TMPFILE
778
	echo "----" >> $TMPFILE
779
	sudo tee /var/lib/jenkins/userContent/THANKS > /dev/null < THANKS.head
780
781
	# samuel, lunar, jelle, josch and phil committed with several committers, only display one
	grep -v -e "samuel.thibault@ens-lyon.org" -e Lunar -e "j.schauer@email.de" -e "mattia@mapreri.org" -e "phil@jenkins-test-vm" -e "jelle@vdwaa.nl" $TMPFILE | sudo tee -a /var/lib/jenkins/userContent/THANKS > /dev/null
782
	rm $TMPFILE
783
	TMPDIR=$(mktemp -d -t update-jdn-XXXXXXXX)
784
	sudo cp -pr userContent $TMPDIR/
Holger Levsen's avatar
Holger Levsen committed
785
786
787
	sudo chown -R jenkins.jenkins $TMPDIR
	sudo cp -pr $TMPDIR/userContent  /var/lib/jenkins/
	sudo rm -r $TMPDIR > /dev/null
788
789
790
791
792
793
794
795
796
	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
797
	sudo chown jenkins.jenkins /var/lib/jenkins/userContent/*html
Holger Levsen's avatar
Holger Levsen committed
798
	explain "user content for jenkins updated."
799
fi
800

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

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

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

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

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

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

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

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

Holger Levsen's avatar
Holger Levsen committed
901
#
902
# finally!
Holger Levsen's avatar
Holger Levsen committed
903
#
904
case $HOSTNAME in
905
	# set time back to the future
906
	profitbricks-build5-amd64|profitbricks-build6-i386|profitbricks-build15-amd64|profitbricks-build16-i386)
907
		disable_dsa_check_packages
908
909
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
910
	codethink-sled9*|codethink-sled11*|codethink-sled13*|codethink-sled15*)
911
		disable_dsa_check_packages
912
913
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
914
	osuosl-build170-amd64|osuosl-build172-amd64)
915
916
917
		disable_dsa_check_packages
		sudo date --set="+398 days +6 hours + 23 minutes"
		;;
918
	jenkins)
919
		# notify irc on updates of jenkins.d.n
920
921
		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
922
		;;
923
924
	*)	;;
esac
925
926
927
928

echo
figlet ok
echo
Holger Levsen's avatar
Holger Levsen committed
929
930
echo "__$HOSTNAME=ok__"