← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:shellcheck into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:shellcheck into launchpad-buildd:master.

Commit message:
Enforce shellcheck in pre-commit

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/437015

Most of launchpad-buildd's shell scripts have been rewritten in Python, but the ones that haven't tend to be weak spots in our testing, so it makes sense to apply some static analysis to them and bring them a bit closer to current standards.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:shellcheck into launchpad-buildd:master.
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 37ac7ca..f8186f4 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -29,3 +29,7 @@ repos:
     rev: 6.0.0
     hooks:
     -   id: flake8
+-   repo: https://github.com/shellcheck-py/shellcheck-py
+    rev: v0.9.0.2
+    hooks:
+    -   id: shellcheck
diff --git a/bin/builder-prep b/bin/builder-prep
index 7fc82fe..01fe154 100755
--- a/bin/builder-prep
+++ b/bin/builder-prep
@@ -5,7 +5,7 @@
 
 # Buildd initial preparation script
 
-export PATH=/usr/bin:/bin:/usr/sbin:/sbin:${PATH}
+export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
 
 NTPDATE=ntpdate
 SUDO=sudo
@@ -13,18 +13,17 @@ PACKAGES="launchpad-buildd python3-lpbuildd sbuild bzr-builder bzr git-build-rec
 KERNEL=$(uname -snrvm)
 
 echo "Kernel version: $KERNEL"
-echo -n "Buildd toolchain package versions:"
+printf "Buildd toolchain package versions:"
 for package in $PACKAGES; do
-  version=$(dpkg-query -W $package 2>/dev/null | awk '{print $2}')
-  [ -z "$version" ] || echo -n " ${package}_${version}"
+  version=$(dpkg-query -W "$package" 2>/dev/null | awk '{print $2}')
+  [ -z "$version" ] || printf " %s_%s" "$package" "$version"
 done
 echo "."
 
 if [ -f /etc/launchpad-buildd/default ]; then
-  eval `grep ntphost /etc/launchpad-buildd/default | sed 's/ //g'`
+  eval "$(grep ntphost /etc/launchpad-buildd/default | sed 's/ //g')"
 fi
 if [ -n "$ntphost" ]; then
   echo "Syncing the system clock with the buildd NTP service..."
-  $SUDO $NTPDATE -u $ntphost
+  $SUDO $NTPDATE -u "$ntphost"
 fi
-
diff --git a/bin/sbuild-package b/bin/sbuild-package
index b5fc862..4287850 100755
--- a/bin/sbuild-package
+++ b/bin/sbuild-package
@@ -39,11 +39,11 @@ NR_PROCESSORS=$ACTUAL_NR_PROCESSORS
 
 echo "Initiating build $BUILDID with $NR_PROCESSORS jobs across $ACTUAL_NR_PROCESSORS processor cores."
 
-if [ $NR_PROCESSORS -gt 1 ]; then
+if [ "$NR_PROCESSORS" -gt 1 ]; then
   export DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS:+$DEB_BUILD_OPTIONS }parallel=$NR_PROCESSORS"
 fi
 
-cd "$HOME/build-$BUILDID"
+cd "$HOME/build-$BUILDID" || exit 2
 
 # sbuild tries to do this itself, but can end up trying to mkdir in
 # /build too early.
@@ -51,8 +51,6 @@ getent group sbuild | sudo tee -a chroot-autobuild/etc/group > /dev/null || exit
 getent passwd sbuild | sudo tee -a chroot-autobuild/etc/passwd > /dev/null || exit 2
 sudo chown sbuild:sbuild chroot-autobuild/build || exit 2
 
-hostarch=$(dpkg --print-architecture)
-
 UNAME26=""
 case $SUITE in
   hardy*|lucid*|maverick*|natty*|oneiric*|precise*)
diff --git a/debian/changelog b/debian/changelog
index af71f9c..deeb0b4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,7 @@
 launchpad-buildd (230) UNRELEASED; urgency=medium
 
   * Apply black and isort.
+  * Enforce shellcheck in pre-commit.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 07 Feb 2023 20:02:04 +0000