jenkins_node_wrapper.sh 10.8 KB
Newer Older
Holger Levsen's avatar
Holger Levsen committed
1
#!/usr/bin/env bash
2
# vim: set noexpandtab:
Holger Levsen's avatar
Holger Levsen committed
3
4

# Copyright (c) 2009, 2010, 2012, 2015 Peter Palfrader
5
#               2015-2022 Holger Levsen
6
#               2017-2018 Mattia Rizzolo <mattia@debian.org>
Holger Levsen's avatar
Holger Levsen committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

set -e
set -u

MYLOGNAME="`basename "$0"`[$$]"

usage() {
	echo "local Usage: $0"
	echo "via ssh orig command:"
	echo "                      <allowed command>"
}

info() {
	echo >&2 "$MYLOGNAME $1"
	echo > ~/jenkins-ssh-wrap.log "$MYLOGNAME $1"
}

croak() {
	echo >&2 "$MYLOGNAME $1"
	echo > ~/jenkins-ssh-wrap.log "$MYLOGNAME $1"
	exit 1
}

if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
	usage
	exit 0
fi

# check/parse remote command line
if [ -z "${SSH_ORIGINAL_COMMAND:-}" ] ; then
	croak "Did not find SSH_ORIGINAL_COMMAND"
fi
set "dummy" ${SSH_ORIGINAL_COMMAND}
shift

61
if [[ "$*" = "/bin/true" ]] ; then
62
	exec /bin/true ; croak "Exec failed";
63
64
65
66
67
68
69
70
71
72
73
74
75
76
elif [ "$1" = scp ]; then
	case "$#" in
		3)
			if [ "$2" = -f ]; then
				exec scp -f "$3"; croak "Exec failed";
			fi
			;;
		4)
			if [ "$2" = -p ] && [ "$3" = -f ]; then
				exec scp -p -f "$4"; croak "Exec failed";
			fi
			;;
	esac
	croak "Unknown scp command: $# $*"
77
elif [[ "$*" = 'rm -v $(mktemp --tmpdir=/tmp read-only-fs-test-XXXXXX)' ]] ; then
78
	exec rm -v $(mktemp --tmpdir=/tmp read-only-fs-test-XXXXXX) ; croak "Exec failed";
79
elif [[ "$*" = "cleanup_nodes /srv/jenkins/bin/reproducible_slay.sh" ]] ; then
80
	exec /srv/jenkins/bin/reproducible_slay.sh ; croak "Exec failed";
81
elif [[ "$*" =~ ^/bin/nc\ localhost\ 4949 ]] ; then
Holger Levsen's avatar
Holger Levsen committed
82
	exec /bin/nc localhost 4949 ; croak "Exec failed";
83
elif [[ "$*" =~ ^rebootstrap_.* ]] ; then
84
	shift
85
	REBOOTSTRAPSH="/srv/jenkins/bin/rebootstrap.sh $@"
86
	export LC_ALL=C
Holger Levsen's avatar
Holger Levsen committed
87
	exec $REBOOTSTRAPSH; croak "Exec failed";
88
elif [[ "$1" =~ ^chroot-installation_.*maintenance$ ]]; then
89
	shift ; exec /srv/jenkins/bin/maintenance.sh $@ ; croak "Exec failed"
90
elif [[ "$1" =~ ^chroot-installation_.* ]]; then
91
	shift ; exec /srv/jenkins/bin/chroot-installation.sh $@ ; croak "Exec failed"
92
elif [ "$*" = "reproducible_nodes_info" ] ; then
93
	exec /srv/jenkins/bin/reproducible_info.sh ; croak "Exec failed";
94
95
elif [ "$1" = "reproducible_pool_buildinfos" ] ; then
	exec /srv/jenkins/bin/reproducible_pool_buildinfos.sh ; croak "Exec failed";
96
elif [ "$1" = "reproducible_html_builtin-pho" ] ; then
Holger Levsen's avatar
Holger Levsen committed
97
	exec /srv/jenkins/bin/reproducible_html_builtin-pho.sh ; croak "Exec failed";
98
elif [[ "$*" =~ reproducible_.*strap.* ]] ; then
99
	exec /srv/jenkins/bin/reproducible_debstrap.sh "$2" "$3" ; croak "Exec failed";
100
101
102
elif [ "$1" = "janitor-setup-worker" ] ; then
	shift ; exec /srv/jenkins/bin/janitor_setup_worker.sh ; croak "Exec failed";
elif [ "$1" = "janitor-worker" ] ; then
103
104
105
	export BUILD_URL="$2"
	export NODE_NAME="$3"
	shift 3; exec /srv/jenkins/bin/janitor_worker.sh ; croak "Exec failed";
106
107
elif [ "$1" = "fakeroot-foreign-worker" ] ; then
	shift ; exec /srv/jenkins/bin/fakeroot_foreign_worker.sh ; croak "Exec failed";
108
elif [ "$1" = "haskell-package-plan" ] ; then
109
	shift ; exec /srv/jenkins/bin/chroot-run.sh $@ ; croak "Exec failed";
110
elif [ "$1" = "/srv/jenkins/bin/reproducible_build.sh" ] && ( [ "$2" = "1" ] || [ "$2" = "2" ] ) ; then
111
	exec /srv/jenkins/bin/reproducible_build.sh "$2" "$3" "$4" "$5" "$6" ; croak "Exec failed";
112
113
elif [[ "$*" =~ ^rsync\ --server\ --sender\ .*\ \.\ /srv/workspace/chroots/.* ]] ; then
	exec rsync --server --sender "$4" . "$6" ; croak "Exec failed";
114
elif [[ "$*" =~ ^rsync\ --server\ --sender\ .*\ \.\ /srv/reproducible-results/.* ]] ; then
Holger Levsen's avatar
Holger Levsen committed
115
	exec rsync --server --sender "$4" . "$6" ; croak "Exec failed";
116
elif [[ "$*" =~ ^rsync\ --server\ --sender\ .*\ \.\ /var/lib/jenkins/userContent/reproducible/.* ]] ; then
117
	exec rsync --server --sender "$4" . "$6" ; croak "Exec failed";
118
elif [[ "$*" =~ ^rsync\ --server\ --sender\ .*\ \.\ /var/lib/jenkins/jobs/.*/workspace/results/.* ]] ; then
119
	exec rsync --server --sender "$4" . "$6" ; croak "Exec failed";
120
elif [[ "$*" =~ ^rsync\ --server\ .*\ \.\ /srv/d-i/isos/ ]] ; then
121
	exec rsync --server "$3" . "$5" ; croak "Exec failed";
122
elif [[ "$*" =~ ^rsync\ --server\ .*\ \.\ /srv/workspace/chroots/.* ]] ; then
123
	# OpenWrt is using this to share files between master node1 node2.
124
	exec rsync --server "$3" . "$5" ; croak "Exec failed";
125
126
127
elif [[ "$*" =~ ^rsync\ --server\ .*\ \.\ /srv/reproducible-results/.* ]] ; then
	# allow to push files to /srv/reproducible-results/
	exec rsync --server "$3" . "$5" ; croak "Exec failed";
128
129
130
elif [[ "$*" =~ ^rsync\ --server\ .*\ \.\ /var/lib/jenkins/userContent/reproducible/debian/ftp-master.debian.org/buildinfo/.* ]] ; then
	# allow to push buildinfo files from coccia
	exec rsync --server "$3" . "$5" ; croak "Exec failed";
131
elif [[ "$*" =~ ^rsync\ --server\ --sender\ .*\ \.\ /var/lib/jenkins/builtin-pho-html/debian/.* ]] ; then
132
	exec rsync --server --sender "$4" . "$6" ; croak "Exec failed";
133
elif [[ "$*" =~ ^mkdir\ -p\ /srv/d-i/isos.* ]] ; then
134
	exec mkdir -p "$3"  ; croak "Exec failed";
135
elif [[ "$*" =~ ^rm\ -r\ /srv/reproducible-results/tmp.* ]] ; then
Holger Levsen's avatar
Holger Levsen committed
136
	exec rm -r "$3" ; croak "Exec failed";
137
elif [[ "$*" =~ ^rm\ -r\ /srv/reproducible-results/rbuild.* ]] ; then
138
	exec rm -r "$3" ; croak "Exec failed";
139
140
elif [[ "$*" =~ ^rm\ -r\ /srv/reproducible-results/archlinuxrb-build.* ]] ; then
	exec rm -r "$3" ; croak "Exec failed";
141
elif [[ "$*" =~ ^rm\ -r\ /var/lib/jenkins/jobs/.*/workspace/results ]] ; then
142
	exec rm -r "$3" ; croak "Exec failed";
143
144
elif [[ "$*" =~ ^reproducible_setup_pbuilder_stretch_.*_.* ]] ; then
	exec /srv/jenkins/bin/reproducible_setup_pbuilder.sh stretch ; croak "Exec failed";
145
146
elif [[ "$*" =~ ^reproducible_setup_pbuilder_buster_.*_.* ]] ; then
	exec /srv/jenkins/bin/reproducible_setup_pbuilder.sh buster ; croak "Exec failed";
147
148
elif [[ "$*" =~ ^reproducible_setup_pbuilder_bullseye_.*_.* ]] ; then
	exec /srv/jenkins/bin/reproducible_setup_pbuilder.sh bullseye ; croak "Exec failed";
149
150
elif [[ "$*" =~ ^reproducible_setup_pbuilder_bookworm_.*_.* ]] ; then
	exec /srv/jenkins/bin/reproducible_setup_pbuilder.sh bookworm ; croak "Exec failed";
151
elif [[ "$*" =~ ^reproducible_setup_pbuilder_unstable_.*_.* ]] ; then
152
	exec /srv/jenkins/bin/reproducible_setup_pbuilder.sh unstable ; croak "Exec failed";
153
elif [[ "$*" =~ ^reproducible_setup_pbuilder_experimental_.*_.* ]] ; then
Holger Levsen's avatar
Holger Levsen committed
154
	exec /srv/jenkins/bin/reproducible_setup_pbuilder.sh experimental ; croak "Exec failed";
155
elif [[ "$*" =~ ^reproducible_maintenance_.*_.* ]] ; then
Holger Levsen's avatar
Holger Levsen committed
156
	exec /srv/jenkins/bin/reproducible_maintenance.sh ; croak "Exec failed";
157
158
elif [[ "$*" =~ ^reproducible_node_health_check_.*_.* ]] ; then
	exec /srv/jenkins/bin/reproducible_node_health_check.sh ; croak "Exec failed";
159
elif [[ "$*" =~ ^reproducible_setup_schroot_buster_diffoscope_.*_.* ]] ; then
160
	exec /srv/jenkins/bin/schroot-create.sh reproducible reproducible-buster-diffoscope buster diffoscope locales-all ; croak "Exec failed";
161
162
163
164
elif [[ "$*" =~ ^reproducible_setup_schroot_bullseye_diffoscope_.*_.* ]] ; then
	exec /srv/jenkins/bin/schroot-create.sh reproducible reproducible-bullseye-diffoscope bullseye diffoscope locales-all ; croak "Exec failed";
elif [[ "$*" =~ ^reproducible_setup_schroot_bookworm_diffoscope_.*_.* ]] ; then
	exec /srv/jenkins/bin/schroot-create.sh reproducible reproducible-bookworm-diffoscope bookworm diffoscope locales-all ; croak "Exec failed";
165
elif [[ "$*" =~ ^reproducible_setup_schroot_unstable_diffoscope_.*_.* ]] ; then
166
	exec /srv/jenkins/bin/schroot-create.sh reproducible reproducible-unstable-diffoscope unstable diffoscope locales-all ; croak "Exec failed";
167
elif [[ "$*" =~ ^reproducible_coreboot ]] ; then
168
	exec /srv/jenkins/bin/reproducible_coreboot.sh ; croak "Exec failed";
169
elif [[ "$*" =~ ^reproducible_openwrt ]] ; then
170
	shift ; exec /srv/jenkins/bin/reproducible_openwrt.sh $@ ; croak "Exec failed";
171
elif [[ "$*" =~ ^reproducible_netbsd ]] ; then
172
	exec /srv/jenkins/bin/reproducible_netbsd.sh ; croak "Exec failed";
173
elif [[ "$*" =~ ^reproducible_freebsd ]] ; then
174
	exec /srv/jenkins/bin/reproducible_freebsd.sh ; croak "Exec failed";
175
176
elif [[ "$*" =~ ^reproducible_setup_schroot_alpine ]] ; then
	exec /srv/jenkins/bin/reproducible_setup_alpine_schroot.sh ; croak "Exec failed";
177
elif [[ "$*" =~ ^reproducible_setup_schroot_archlinux ]] ; then
178
	exec /srv/jenkins/bin/reproducible_setup_archlinux_schroot.sh ; croak "Exec failed";
179
180
elif [[ "$*" =~ ^reproducible_fdroid_build_apps ]] ; then
	exec /srv/jenkins/bin/reproducible_fdroid_build_apps.sh ; croak "Exec failed";
181
182
elif [[ "$*" =~ ^reproducible_fdroid_test ]] ; then
	exec /srv/jenkins/bin/reproducible_fdroid_test.sh ; croak "Exec failed";
183
elif [[ "$*" =~ ^reproducible_setup_fdroid_build_environment ]] ; then
184
	exec /srv/jenkins/bin/reproducible_setup_fdroid_build_environment.sh ; croak "Exec failed";
185
elif [[ "$*" =~ ^reproducible_setup_mock_fedora-23_x86_64 ]] ; then
186
	exec /srv/jenkins/bin/reproducible_setup_mock.sh fedora-23 x86_64 ; croak "Exec failed";
187
188
elif [ "$1" = "/srv/jenkins/bin/reproducible_openwrt_rebuild.py" ] ; then
	exec /srv/jenkins/bin/reproducible_openwrt_rebuild.py ; croak "Exec failed";
189
190
elif [ "$1" = "/srv/jenkins/bin/reproducible_build_alpine_pkg.sh" ] && ( [ "$2" = "1" ] || [ "$2" = "2" ] ) ; then
	exec /srv/jenkins/bin/reproducible_build_alpine_pkg.sh "$2" "$3" "$4" "$5" "$6" ; croak "Exec failed";
191
elif [ "$1" = "/srv/jenkins/bin/reproducible_build_archlinux_pkg.sh" ] && ( [ "$2" = "1" ] || [ "$2" = "2" ] ) ; then
192
	exec /srv/jenkins/bin/reproducible_build_archlinux_pkg.sh "$2" "$3" "$4" "$5" "$6" ; croak "Exec failed";
193
elif [ "$1" = "/srv/jenkins/bin/reproducible_build_rpm.sh" ] && ( [ "$2" = "1" ] || [ "$2" = "2" ] ) ; then
194
	exec /srv/jenkins/bin/reproducible_build_rpm.sh "$2" "$3" "$4" "$5" "$6" "$7" ; croak "Exec failed";
195
elif [[ "$*" =~ ^reproducible_debian_live_build.* ]] ; then
196
197
198
199
200
	# would be nice to generalize this so that all remote jobs have these variables
	export BUILD_TAG="$2"
	export BUILD_URL="$3"
	shift 3
	exec /srv/jenkins/bin/reproducible_debian_live_build.sh $@; croak "Exec failed";
201
202
elif [ "$*" = "some_jenkins_job_name" ] ; then
	exec echo run any commands here ; croak "Exec failed";
Holger Levsen's avatar
Holger Levsen committed
203
204
205
fi

croak "Command '$*' not found in allowed commands."