From 4c445462511592aa2f7024a38872271b7c93294c Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Thu, 15 Dec 2022 06:19:01 +0000 Subject: [PATCH] LU-14707 tests: Prefer #!/bin/bash Change remaining #!/bin/sh to use bash. Add a warning to the git-hook about using sh in shebangs. Using bash allows scripts to freely use bash-isms and lowers the risks of bugs on Debian based platforms. Also, change remaining callers to use bash rather than sh. Signed-off-by: Timothy Day Change-Id: I10f3e8f71435c38cfc1650dd13168d7ed5d3b31f Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49479 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: jsimmons --- LUSTRE-VERSION-GEN | 2 +- autogen.sh | 5 +---- contrib/git-hooks/prepare-commit-msg | 7 +++++++ contrib/lbuild/lbuild | 2 +- debian/dkms.conf.in | 2 +- debian/lustre-client-modules-dkms.postinst | 2 +- debian/lustre-client-modules-dkms.prerm | 2 +- debian/postinst | 2 +- debian/postrm | 4 ++-- debian/rules | 2 +- lnet/utils/lnetunload | 2 +- lustre/BUILDING | 2 +- lustre/conf/resource/Lustre | 2 +- lustre/conf/resource/healthLNET | 2 +- lustre/conf/resource/healthLUSTRE | 2 +- lustre/scripts/dkms.mkconf | 2 +- lustre/scripts/ko2iblnd-probe | 2 +- lustre/scripts/lc_mon | 4 ++-- lustre/scripts/lustre_req_history | 2 +- lustre/tests/runiozone | 2 +- lustre/tests/runobdstat | 2 +- lustre/tests/runvmstat | 2 +- lustre/tests/test-framework.sh | 2 +- 23 files changed, 31 insertions(+), 27 deletions(-) diff --git a/LUSTRE-VERSION-GEN b/LUSTRE-VERSION-GEN index 9d34753..fecef2e 100755 --- a/LUSTRE-VERSION-GEN +++ b/LUSTRE-VERSION-GEN @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash DEFAULT_VERSION=2.15.53 LVF=LUSTRE-VERSION-FILE diff --git a/autogen.sh b/autogen.sh index f8b7741..40b05bf 100644 --- a/autogen.sh +++ b/autogen.sh @@ -1,7 +1,4 @@ -#!/bin/sh - -# NOTE: Please avoid bashisms (bash specific syntax) in this script - +#!/bin/bash set -e pw="$PWD" for dir in libcfs lnet lustre snmp ; do diff --git a/contrib/git-hooks/prepare-commit-msg b/contrib/git-hooks/prepare-commit-msg index 2178e9e..77caa69 100755 --- a/contrib/git-hooks/prepare-commit-msg +++ b/contrib/git-hooks/prepare-commit-msg @@ -54,6 +54,13 @@ if [[ -x "$SHELLCHECK" && "$SHELLCHECK_RUN" == "yes" ]]; then # Example End -- mod_files=($(awk '/modified:.*\.sh|new:.*\.sh/ { print $3 }' $1)) for cur_file in ${mod_files[@]}; do + # Shebangs should prefer bash over regular sh. This allows + # scripts to freely use bash-isms and lowers the risks of + # failures on Debian based platforms. Output a small warning + # if #!/bin/sh is found. + echo "#" $(grep -Hn "#\!/bin/sh" "$cur_file" && \ + echo " : Please don't use sh in shebangs.") >> "$1" + # Get start/end range of lines that needs to be reported # range presently not used will come in handy when dealing with # warnings reported by shellcheck diff --git a/contrib/lbuild/lbuild b/contrib/lbuild/lbuild index f6a750f..a21d17b 100755 --- a/contrib/lbuild/lbuild +++ b/contrib/lbuild/lbuild @@ -1072,7 +1072,7 @@ build_spl_zfs() { speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec" fi - sh autogen.sh || return 255 + bash autogen.sh || return 255 if ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \ ${spldir:+--with-spl="${spldir}"} 2>&1 || diff --git a/debian/dkms.conf.in b/debian/dkms.conf.in index 6a8a1b6..2cd63b0 100644 --- a/debian/dkms.conf.in +++ b/debian/dkms.conf.in @@ -8,7 +8,7 @@ PACKAGE_NAME="lustre-client-modules" PACKAGE_VERSION="@UPVERSION@" # We need to run autogen.sh between builds, see Ubuntu bug #952817 -MAKE="sh autogen.sh && ./configure --with-linux=$kernel_source_dir --with-linux-obj=$kernel_source_dir --disable-server --disable-quilt --disable-dependency-tracking --disable-doc --disable-utils --disable-iokit --disable-snmp --disable-tests --enable-quota --with-kmp-moddir=updates && make" +MAKE="bash autogen.sh && ./configure --with-linux=$kernel_source_dir --with-linux-obj=$kernel_source_dir --disable-server --disable-quilt --disable-dependency-tracking --disable-doc --disable-utils --disable-iokit --disable-snmp --disable-tests --enable-quota --with-kmp-moddir=updates && make" CLEAN="make distclean || true" AUTOINSTALL="yes" diff --git a/debian/lustre-client-modules-dkms.postinst b/debian/lustre-client-modules-dkms.postinst index 5fbf15c..0e4500b 100644 --- a/debian/lustre-client-modules-dkms.postinst +++ b/debian/lustre-client-modules-dkms.postinst @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e diff --git a/debian/lustre-client-modules-dkms.prerm b/debian/lustre-client-modules-dkms.prerm index a1565f5..79154d4 100644 --- a/debian/lustre-client-modules-dkms.prerm +++ b/debian/lustre-client-modules-dkms.prerm @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e diff --git a/debian/postinst b/debian/postinst index a05e2a5..28f069e 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash DEPMOD_DIR="/etc/depmod.d" LUSTRE_DEPMOD_FILE="${DEPMOD_DIR}/lustre.conf" diff --git a/debian/postrm b/debian/postrm index 2affdf0..476b60f 100755 --- a/debian/postrm +++ b/debian/postrm @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash DEPMOD_DIR="/etc/depmod.d" LUSTRE_DEPMOD_FILE="${DEPMOD_DIR}/lustre.conf" @@ -7,4 +7,4 @@ LUSTRE_DEPMOD_FILE="${DEPMOD_DIR}/lustre.conf" # If DEPMOD_DIR is empty, we also created it, thus remove it. [ ! "$(ls -A ${DEPMOD_DIR} 2>/dev/null)" ] && { rm -rf ${DEPMOD_DIR}; } -depmod -a \ No newline at end of file +depmod -a diff --git a/debian/rules b/debian/rules index 91db28f..377c042 100755 --- a/debian/rules +++ b/debian/rules @@ -130,7 +130,7 @@ autogen-stamp: patch-stamp cp /usr/share/misc/config.sub ldiskfs/config.sub; \ cp /usr/share/misc/config.guess config.guess; \ cp /usr/share/misc/config.guess ldiskfs/config.guess; \ - sh build/autogen.sh; \ + bash build/autogen.sh; \ fi; \ touch $@ diff --git a/lnet/utils/lnetunload b/lnet/utils/lnetunload index fdc64ba..b61f938 100755 --- a/lnet/utils/lnetunload +++ b/lnet/utils/lnetunload @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash lnds=$(echo k{sock,qsw,{open,i,v,o2,c}ib,ra,ptl,mx}lnd) diff --git a/lustre/BUILDING b/lustre/BUILDING index f652ca9..5bf0774 100644 --- a/lustre/BUILDING +++ b/lustre/BUILDING @@ -7,7 +7,7 @@ web sites below. Also consider downloading a pre-packaged Lustre kernel and utilities from https://downloads.whamcloud.com/ To build: - sh autogen.sh + bash autogen.sh ./configure --with-linux=/usr/src/lustre_patched_kernel_tree make diff --git a/lustre/conf/resource/Lustre b/lustre/conf/resource/Lustre index 91f15c4..6971a86 100755 --- a/lustre/conf/resource/Lustre +++ b/lustre/conf/resource/Lustre @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # License: GNU General Public License (GPL)v2 # Description: Manages Lustre server on a shared storage diff --git a/lustre/conf/resource/healthLNET b/lustre/conf/resource/healthLNET index 8ebf587..8631478 100755 --- a/lustre/conf/resource/healthLNET +++ b/lustre/conf/resource/healthLNET @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # # LNet OCF RA diff --git a/lustre/conf/resource/healthLUSTRE b/lustre/conf/resource/healthLUSTRE index 4ca2e5e..a184892 100755 --- a/lustre/conf/resource/healthLUSTRE +++ b/lustre/conf/resource/healthLUSTRE @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # # HealthLUSTRE OCF RA diff --git a/lustre/scripts/dkms.mkconf b/lustre/scripts/dkms.mkconf index 2cd7cb5..ae481d1 100755 --- a/lustre/scripts/dkms.mkconf +++ b/lustre/scripts/dkms.mkconf @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash PROG=$0 diff --git a/lustre/scripts/ko2iblnd-probe b/lustre/scripts/ko2iblnd-probe index 5d07886..7b7e1e2 100755 --- a/lustre/scripts/ko2iblnd-probe +++ b/lustre/scripts/ko2iblnd-probe @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # flags of IB devices which present HFI=0 diff --git a/lustre/scripts/lc_mon b/lustre/scripts/lc_mon index ac4be84e7..f3f2fb9 100644 --- a/lustre/scripts/lc_mon +++ b/lustre/scripts/lc_mon @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Given one or more Lustre objects, create a mon configuration file # naming the mon watches based on the Lustre object names @@ -136,4 +136,4 @@ do done echo "Mon config completed - new mon config is $TMPMONCFG" -exit 0 \ No newline at end of file +exit 0 diff --git a/lustre/scripts/lustre_req_history b/lustre/scripts/lustre_req_history index 0bbab70..e0d4681 100644 --- a/lustre/scripts/lustre_req_history +++ b/lustre/scripts/lustre_req_history @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. # Purpose: diff --git a/lustre/tests/runiozone b/lustre/tests/runiozone index b364abe..0403ab0 100755 --- a/lustre/tests/runiozone +++ b/lustre/tests/runiozone @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash [ -z "$SIZE" ] && SIZE=5g [ -z "$COUNT" ] && COUNT=100 [ -z "$VERIFY" ] && VERIFY="-+d" diff --git a/lustre/tests/runobdstat b/lustre/tests/runobdstat index 7fd61ee..7f9b78d 100644 --- a/lustre/tests/runobdstat +++ b/lustre/tests/runobdstat @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash PATH=`dirname $0`/../utils:$PATH llobdstat $1 1 | while read LINE; do diff --git a/lustre/tests/runvmstat b/lustre/tests/runvmstat index 8a5a7df..4371d38 100755 --- a/lustre/tests/runvmstat +++ b/lustre/tests/runvmstat @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash DELAY=1 null() { : diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 7970291..64d7f3d 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -827,7 +827,7 @@ load_modules_local() { [ ! -f "$sbin_mount" ] && touch "$sbin_mount" if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then cat <<- EOF > "$sbin_mount" - #!/bin/sh + #!/bin/bash #STUB MARK echo "This $sbin_mount just a mountpoint." 1>&2 echo "It is never supposed to be run." 1>&2 -- 1.8.3.1