[Qa-jenkins-scm] [Git][qa/jenkins.debian.net][master] 6 commits: schroot-create: make it pass shellcheck

Mattia Rizzolo gitlab at salsa.debian.org
Sun Aug 23 21:24:08 BST 2020



Mattia Rizzolo pushed to branch master at Debian QA / jenkins.debian.net


Commits:
a4a0b2f1 by Mattia Rizzolo at 2020-08-23T21:48:36+02:00
schroot-create: make it pass shellcheck

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -
e5373dd7 by Mattia Rizzolo at 2020-08-23T21:53:17+02:00
schroot-create: revert e6c13507

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -
768bc935 by Mattia Rizzolo at 2020-08-23T21:57:10+02:00
schroot-create: easier control flow for the diffoscope handling

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -
c3d62972 by Mattia Rizzolo at 2020-08-23T22:01:31+02:00
schroot-create: always set debconf/frontend noninteractive, not only when installing diffoscope..

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -
1e2e4eb9 by Mattia Rizzolo at 2020-08-23T22:20:52+02:00
schroot-create: check whether diffoscope is available before trying to install it

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -
93b6ffe1 by Mattia Rizzolo at 2020-08-23T22:23:55+02:00
schroot-create: move the code dealing with diffoscope to a separate function, for clearity

Signed-off-by: Mattia Rizzolo <mattia at debian.org>

- - - - -


1 changed file:

- bin/schroot-create.sh


Changes:

=====================================
bin/schroot-create.sh
=====================================
@@ -46,12 +46,12 @@ shift
 SUITE="$1"
 shift
 
-SCHROOT_TARGET=$(mktemp -d -p $SCHROOT_BASE/ schroot-install-$TARGET-XXXX)
+SCHROOT_TARGET=$(mktemp -d -p "$SCHROOT_BASE"/ "schroot-install-$TARGET-XXXX")
 if [ -z "$SCHROOT_TARGET" ]; then
 	echo "Could not create a directory to create the chroot in, aborting."
 	exit 1
 fi
-TMPLOG=$(mktemp --tmpdir=$TMPDIR schroot-create-XXXXXXXX)
+TMPLOG=$(mktemp --tmpdir="$TMPDIR" schroot-create-XXXXXXXX)
 cleanup() {
 	cd
 	if [ -d "$SCHROOT_TARGET" ]; then
@@ -65,7 +65,7 @@ cleanup() {
 }
 trap cleanup INT TERM EXIT
 
-sudo chmod +x $SCHROOT_TARGET	# workaround #844220 / #872812
+sudo chmod +x "$SCHROOT_TARGET"  # workaround #844220 / #872812
 
 if [ "$SUITE" = "experimental" ] ; then
 	# experimental cannot be bootstrapped
@@ -84,15 +84,47 @@ fi
 
 
 robust_chroot_apt() {
-	sudo chroot $SCHROOT_TARGET apt-get $@ | tee $TMPLOG
+	sudo chroot "$SCHROOT_TARGET" apt-get "$@" | tee "$TMPLOG"
 	local rt="${PIPESTATUS[0]}"
-	local RESULT=$(egrep 'Failed to fetch.*(Unable to connect to|Connection failed|Size mismatch|Cannot initiate the connection to|Bad Gateway|Service Unavailable)' $TMPLOG || true)
-	if [ ! -z "$RESULT" ] || [ "$rt" -ne 0 ] ; then
-		echo "$(date -u) - 'apt-get $@' failed, sleeping 5min before retrying..."
+	local RESULT
+	RESULT=$(grep -E 'Failed to fetch.*(Unable to connect to|Connection failed|Size mismatch|Cannot initiate the connection to|Bad Gateway|Service Unavailable)' "$TMPLOG" || true)
+	if [ -n "$RESULT" ] || [ "$rt" -ne 0 ] ; then
+		echo "$(date -u) - 'apt-get $*' failed, sleeping 5min before retrying..."
 		sleep 5m
-		sudo chroot $SCHROOT_TARGET apt-get $@ || ( echo "$(date -u ) - 2nd 'apt-get $@' failed, giving up..." ; exit 1 )
+		sudo chroot "$SCHROOT_TARGET" apt-get "$@" || ( echo "$(date -u ) - 2nd 'apt-get $*' failed, giving up..." ; exit 1 )
 	fi
-	rm -f $TMPLOG
+	rm -f "$TMPLOG"
+}
+
+install_diffoscope() {
+	local diffoscope_installed
+	# check if diffoscope is available in the current release;
+	# else, no sweat: we'll try to install it from unstable/experimental
+	if [ -n "$(sudo chroot "$SCHROOT_TARGET" apt-cache madison diffoscope)" ]; then
+		robust_chroot_apt install -y --install-recommends diffoscope
+		diffoscope_installed=true
+	else
+		echo "diffoscope is not available in the base distribution.  Not installing, hoping it will be installed later from unstable/experimental."
+	fi
+
+	# try to use diffoscope from unstable if available
+	if [ "$SUITE" != "unstable" ] && [ "$SUITE" != "experimental" ]; then
+		# always try to use diffoscope from unstable on stretch/buster
+		echo "deb $MIRROR unstable main" | sudo tee -a "$SCHROOT_TARGET/etc/apt/sources.list" > /dev/null
+		robust_chroot_apt update
+		# install diffoscope from unstable without re-adding all recommends...
+		sudo chroot "$SCHROOT_TARGET" apt-get install -y -t unstable ${diffoscope_installed+--no-install-recommends} diffoscope || echo "Warning: diffoscope from unstable is uninstallable at the moment."
+	fi
+
+	if [ "$SUITE" != "experimental" ]; then
+		echo "deb $MIRROR experimental main" | sudo tee -a "$SCHROOT_TARGET/etc/apt/sources.list" > /dev/null
+		robust_chroot_apt update
+		# install diffoscope from experimental without re-adding all recommends...
+		sudo chroot "$SCHROOT_TARGET" apt-get install -y -t experimental ${diffoscope_installed+--no-install-recommends} diffoscope || echo "Warning: diffoscope from experimental is uninstallable at the moment."
+	fi
+
+	# if diffoscope is still not installed, the next apt-get install
+	# after this function is going to fail, so no need to handle it.
 }
 
 bootstrap() {
@@ -129,21 +161,22 @@ bootstrap() {
 	sudo -- "${DEBOOTSTRAP[@]}" "$SUITE" "$SCHROOT_TARGET" "$MIRROR" | tee "$TMPLOG"
 	local rt="${PIPESTATUS[0]}"
 	if ! "$DEBUG" ; then set +x ; fi
-	local RESULT=$(egrep "E: (Couldn't download packages|Invalid Release signature)" $TMPLOG || true)
-	if [ ! -z "$RESULT" ] || [ "$rt" -ne 0 ]; then
+	local RESULT
+	RESULT=$(grep -E "E: (Couldn't download packages|Invalid Release signature)" "$TMPLOG" || true)
+	if [ -n "$RESULT" ] || [ "$rt" -ne 0 ]; then
 		echo "$(date -u) - initial bootstrap failed, sleeping 5min before retrying..."
-		sudo rm -rf --one-file-system $SCHROOT_TARGET
+		sudo rm -rf --one-file-system "$SCHROOT_TARGET"
 		sleep 5m
 		sudo -- "${DEBOOTSTRAP[@]}" "$SUITE" "$SCHROOT_TARGET" "$MIRROR" || ( echo "$(date -u ) - 2nd bootstrap failed, giving up..." ; exit 1 )
 	fi
-	rm -f $TMPLOG
+	rm -f "$TMPLOG"
 
 	# configure policy-rc.d to not start services
-	echo -e '#!/bin/sh\nexit 101' | sudo tee $SCHROOT_TARGET/usr/sbin/policy-rc.d >/dev/null
-	sudo chmod +x $SCHROOT_TARGET/usr/sbin/policy-rc.d
+	echo -e '#!/bin/sh\nexit 101' | sudo tee "$SCHROOT_TARGET/usr/sbin/policy-rc.d" >/dev/null
+	sudo chmod +x "$SCHROOT_TARGET/usr/sbin/policy-rc.d"
 	# configure proxy
-	if [ ! -z "$http_proxy" ] ; then
-		echo "Acquire::http::Proxy \"$http_proxy\";" | sudo tee $SCHROOT_TARGET/etc/apt/apt.conf.d/80proxy >/dev/null
+	if [ -n "$http_proxy" ] ; then
+		echo "Acquire::http::Proxy \"$http_proxy\";" | sudo tee "$SCHROOT_TARGET/etc/apt/apt.conf.d/80proxy" >/dev/null
 	fi
 	# configure dpkg to be faster
 	echo force-unsafe-io | sudo tee "$SCHROOT_TARGET/etc/dpkg/dpkg.cfg.d/02dpkg-unsafe-io"
@@ -155,7 +188,7 @@ bootstrap() {
 	deb-src $MIRROR $SUITE main
 	__END__
 	for i in $(seq 0 7) ; do
-		[ -z "${EXTRA_SOURCES[$i]}" ] || echo "${EXTRA_SOURCES[$i]}" | sudo tee -a $SCHROOT_TARGET/etc/apt/sources.list >/dev/null
+		[ -z "${EXTRA_SOURCES[$i]}" ] || echo "${EXTRA_SOURCES[$i]}" | sudo tee -a "$SCHROOT_TARGET/etc/apt/sources.list" >/dev/null
 	done
 
 	# Misc configuration for a building-aimed chroot
@@ -176,53 +209,35 @@ bootstrap() {
 
 	robust_chroot_apt update
 	if [ -n "$1" ] ; then
-		sudo mount --bind /proc $SCHROOT_TARGET/proc
+		sudo mount --bind /proc "$SCHROOT_TARGET/proc"
 		set -x
+		# we could also use $SCRIPT_HEADER (set in bin/common-functions.sh) in our generated scripts
+		# instead of using the next line, maybe we should…
+		echo 'debconf debconf/frontend select noninteractive' | sudo chroot "$SCHROOT_TARGET" debconf-set-selections
 		robust_chroot_apt update
-		# first, (if), install diffoscope with all recommends...
-		if [ "$1" = "diffoscope" ] ; then
-			# we could also use $SCRIPT_HEADER (set in bin/common-functions.sh) in our generated scripts
-			# instead of using the next line, maybe we should…
-			echo 'debconf debconf/frontend select noninteractive' | sudo chroot $SCHROOT_TARGET debconf-set-selections
-			robust_chroot_apt install -y --install-recommends diffoscope || true # || true is a workaround for diffoscope not in testing
-		fi
 		robust_chroot_apt install -y --no-install-recommends sudo
-		robust_chroot_apt install -y --no-install-recommends $@
-		# try to use diffoscope from unstable if available
-		if ([ "$SUITE" != "unstable" ] && [ "$SUITE" != "experimental" ]) && [ "$1" = "diffoscope" ] ; then
-			# always try to use diffoscope from unstable on stretch/buster
-			echo "deb $MIRROR unstable main" | sudo tee -a $SCHROOT_TARGET/etc/apt/sources.list > /dev/null
-			robust_chroot_apt update
-			if [ "$SUITE" = "bullseye" ] ; then
-				# workaround diffoscope not in testing:
-				# install diffoscope from unstablle with recommends
-				sudo chroot $SCHROOT_TARGET apt-get install -y -t unstable diffoscope
-			else
-				# install diffoscope from unstable without re-adding all recommends...
-				sudo chroot $SCHROOT_TARGET apt-get install -y -t unstable --no-install-recommends diffoscope || echo "Warning: diffoscope from unstable is uninstallable at the moment."
-			fi
-		fi
-		if [ "$SUITE" != "experimental" ] && [ "$1" = "diffoscope" ] ; then
-			echo "deb $MIRROR experimental main" | sudo tee -a $SCHROOT_TARGET/etc/apt/sources.list > /dev/null
-			robust_chroot_apt update
-			# install diffoscope from experimental without re-adding all recommends...
-			sudo chroot $SCHROOT_TARGET apt-get install -y -t experimental --no-install-recommends diffoscope || echo "Warning: diffoscope from experimental is uninstallable at the moment."
+
+		# extra handling specific for diffoscope
+		if [ "$1" = "diffoscope" ] ; then
+			install_diffoscope
 		fi
+
+		robust_chroot_apt install -y --no-install-recommends "$@"
 		if ! $DEBUG ; then set +x ; fi
 		if [ "$1" = "diffoscope" ] ; then
 			echo
-			sudo chroot $SCHROOT_TARGET dpkg -l diffoscope
+			sudo chroot "$SCHROOT_TARGET" dpkg -l diffoscope
 			echo
 		fi
-		sudo umount -l $SCHROOT_TARGET/proc
+		sudo umount -l "$SCHROOT_TARGET/proc"
 		# configure sudo inside just like outside
-		echo "jenkins    ALL=NOPASSWD: ALL" | sudo tee -a $SCHROOT_TARGET/etc/sudoers.d/jenkins >/dev/null
-		sudo chroot $SCHROOT_TARGET chown root.root /etc/sudoers.d/jenkins
-		sudo chroot $SCHROOT_TARGET chmod 700 /etc/sudoers.d/jenkins
+		echo "jenkins    ALL=NOPASSWD: ALL" | sudo tee -a "$SCHROOT_TARGET/etc/sudoers.d/jenkins" >/dev/null
+		sudo chroot "$SCHROOT_TARGET" chown root.root /etc/sudoers.d/jenkins
+		sudo chroot "$SCHROOT_TARGET" chmod 700 /etc/sudoers.d/jenkins
 	fi
 }
 
-bootstrap $@
+bootstrap "$@"
 
 # pivot the new schroot in place
 rand="$(date -u +%Y%m%d)-$RANDOM"



View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/-/compare/f5d604d71734d2ad3d983e4aaed9cd05143257cc...93b6ffe1ad8930887989683a1ebb1c5e9be1ca21

-- 
View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/-/compare/f5d604d71734d2ad3d983e4aaed9cd05143257cc...93b6ffe1ad8930887989683a1ebb1c5e9be1ca21
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/qa-jenkins-scm/attachments/20200823/034af646/attachment-0001.html>


More information about the Qa-jenkins-scm mailing list