]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add some more error checking to shell scripts (#2617)
authorMostyn Bramley-Moore <mostyn@antipode.se>
Tue, 20 May 2025 08:14:17 +0000 (10:14 +0200)
committerGitHub <noreply@github.com>
Tue, 20 May 2025 08:14:17 +0000 (10:14 +0200)
Exit immediately if a command exits with a non-zero status, and treat
unset variables as an error when substituting.

12 files changed:
.github/workflows/ci.yml
build/autogen.sh
build/bump-version.sh
build/ci/build.sh
build/ci/cirrus_ci/ci.sh
build/ci/github_actions/install-macos-dependencies.sh [new file with mode: 0755]
build/ci/github_actions/macos.sh [deleted file]
build/clean.sh
build/makerelease.sh
build/release/release.sh
build/utils/gen_archive_string_composition_h.sh
doc/update.sh

index adc19e43204733ac9aea85a5dc0191cfe922e4fd..4140cab15257849855fed35d78aae0d57991392f 100644 (file)
@@ -14,7 +14,7 @@ jobs:
     steps:
     - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
     - name: Install dependencies
-      run: ./build/ci/github_actions/macos.sh prepare
+      run: ./build/ci/github_actions/install-macos-dependencies.sh
     - name: Autogen
       run: ./build/ci/build.sh -a autogen
       env:
index e720e9b789b5c2bb4b5a9c16b3964f0ee42884c6..045ccc192bf4a6f790d098d956d334fd89f3bc06 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
+set -eu
 
 PATH=/usr/local/gnu-autotools/bin/:$PATH
-export PATH
 
 # Start from one level above the build directory
 if [ -f version ]; then
@@ -49,7 +49,7 @@ perl -p -i -e 's/(m4_define\(\[LIBARCHIVE_VERSION_S\]),.*\)/$1,['"$VS"'])/' conf
 perl -p -i -e 's/(m4_define\(\[LIBARCHIVE_VERSION_N\]),.*\)/$1,['"$VN"'])/' configure.ac
 
 # Remove developer CFLAGS if a release build is being made
-if [ -n "${MAKE_LIBARCHIVE_RELEASE}" ]; then
+if [ -n "${MAKE_LIBARCHIVE_RELEASE:-}" ]; then
   perl -p -i -e "s/^(DEV_CFLAGS.*)/# \$1/" Makefile.am
   perl -p -i -e 's/CMAKE_BUILD_TYPE "[A-Za-z]*"/CMAKE_BUILD_TYPE "Release"/' CMakeLists.txt
 fi
index eec42354fd4725a33534bf4ed6e7b3cfcef1d777..7cbe9e862dcf42674188e6ea7ec7db301bd37f27 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/sh +v
+set -eu
 
 # Start from the build directory, where the version file is located
 if [ -f build/version ]; then
index 3a15582640f16d8343d2a53659b221a5fb8a5fbe..9b983f64af8ca5befc9514bcd34545ecd510f7b0 100755 (executable)
 # MAKE_ARGS=           # make arguments
 # DEBUG=               # set -g -fsanitize=address flags
 
+set -eu
+
 ACTIONS=
-if [ -n "${BUILD_SYSTEM}" ]; then
+if [ -n "${BUILD_SYSTEM:-}" ]; then
        BS="${BUILD_SYSTEM}"
 fi
 
 BS="${BS:-autotools}"
 MAKE="${MAKE:-make}"
 CMAKE="${CMAKE:-cmake}"
+CMAKE_ARGS="${CMAKE_ARGS:-}"
+CONFIGURE_ARGS="${CONFIGURE_ARGS:-}"
 CURDIR=`pwd`
 SRCDIR="${SRCDIR:-`pwd`}"
 RET=0
@@ -74,7 +78,7 @@ while getopts a:b:c:d:s: opt; do
                ;;
        esac
 done
-case "${CRYPTO}" in
+case "${CRYPTO:-}" in
        mbedtls)
                CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPENSSL=OFF -DENABLE_MBEDTLS=ON"
                CONFIGURE_ARGS="${CONFIGURE_ARGS} --without-openssl --with-mbedtls"
@@ -84,7 +88,7 @@ case "${CRYPTO}" in
                CONFIGURE_ARGS="${CONFIGURE_ARGS} --without-openssl --with-nettle"
        ;;
 esac
-if [ -z "${MAKE_ARGS}" ]; then
+if [ -z "${MAKE_ARGS:-}" ]; then
        if [ "${BS}" = "autotools" ]; then
                MAKE_ARGS="V=1"
        elif [ "${BS}" = "cmake" ]; then
@@ -92,13 +96,13 @@ if [ -z "${MAKE_ARGS}" ]; then
        fi
 fi
 if [ -d /opt/homebrew/include ]; then
-       export CFLAGS="${CFLAGS} -I/opt/homebrew/include"
+       export CFLAGS="${CFLAGS:-} -I/opt/homebrew/include"
 fi
 if [ -d /opt/homebrew/lib ]; then
-       export LDFLAGS="${LDFLAGS} -L/opt/homebrew/lib"
+       export LDFLAGS="${LDFLAGS:-} -L/opt/homebrew/lib"
 fi
-if [ -n "${DEBUG}" ]; then
-       if [ -n "${CFLAGS}" ]; then
+if [ -n "${DEBUG:-}" ]; then
+       if [ -n "${CFLAGS:-}" ]; then
                export CFLAGS="${CFLAGS} -g -fsanitize=address"
        else
                export CFLAGS="-g -fsanitize=address"
@@ -110,7 +114,7 @@ fi
 if [ -z "${BS}" ]; then
        inputerror "Missing build system (-b) parameter"
 fi
-if [ -z "${BUILDDIR}" ]; then
+if [ -z "${BUILDDIR:-}" ]; then
        BUILDDIR="${CURDIR}/build_ci/${BS}"
 fi
 mkdir -p "${BUILDDIR}"
@@ -147,7 +151,7 @@ for action in ${ACTIONS}; do
                                        ;;
                        esac
                        RET="$?"
-                       find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \;
+                       find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \; 2>/dev/null || /bin/true
                ;;
                install)
                        ${MAKE} ${MAKE_ARGS} install DESTDIR="${BUILDDIR}/destdir"
@@ -159,7 +163,7 @@ for action in ${ACTIONS}; do
                        ${MAKE} ${MAKE_ARGS} distcheck || (
                                RET="$?"
                                find . -name 'test-suite.log' -print -exec cat {} \;
-                               find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \;
+                               find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \; 2>/dev/null || /bin/true
                                exit "${RET}"
                        )
                        RET="$?"
index d49c7277f985a171bfecbb8d64b211a72b8524a4..29425121ff49331c991399e272419920e737c90a 100755 (executable)
@@ -1,4 +1,12 @@
 #!/bin/sh
+set -eu
+
+if [ $# != 1 ]
+then
+       echo "Usage: $0 prepare | test"
+       exit 1
+fi
+
 UNAME=`uname`
 if [ "$1" = "prepare" ]
 then
@@ -53,6 +61,6 @@ then
                TMPDIR=/tmp_acl_nfsv4 ${BIN_SUBDIR}/libarchive_test -r "${CURDIR}/libarchive/test" -v test_acl_platform_nfs4
        fi
 else
-       echo "Usage $0 prepare | test_nfsv4_acls"
+       echo "Usage: $0 prepare | test"
        exit 1
 fi
diff --git a/build/ci/github_actions/install-macos-dependencies.sh b/build/ci/github_actions/install-macos-dependencies.sh
new file mode 100755 (executable)
index 0000000..2aa4823
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -eux
+
+# Uncommenting these adds a full minute to the CI time
+#brew update > /dev/null
+#brew upgrade > /dev/null
+
+# This does an upgrade if the package is already installed
+brew install \
+       autoconf \
+       automake \
+       libtool \
+       pkg-config \
+       cmake \
+       xz \
+       lz4 \
+       zstd \
+       libxml2 \
+       openssl
diff --git a/build/ci/github_actions/macos.sh b/build/ci/github_actions/macos.sh
deleted file mode 100755 (executable)
index b42ca05..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-if [ "$1" = "prepare" ]
-then
-       set -x -e
-       #Uncommenting these adds a full minute to the CI time
-       #brew update > /dev/null
-       #brew upgrade > /dev/null
-
-       # This does an upgrade if the package is already installed
-       brew install \
-               autoconf \
-               automake \
-               libtool \
-               pkg-config \
-               cmake \
-               xz \
-               lz4 \
-               zstd \
-               libxml2 \
-               openssl
-fi
index b669426ccb5ef8eeffb5f600b16cb8af02f849dd..904365f4012b4fd113dc0285226ab5f245b7dc86 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/sh
+set -eu
 
 #
 # Attempt to remove as many generated files as we can.
index f2869dfca5edc9e7848a2f99812045afeeb7ad52..82843d6773095cd089edd29ec1d0b285f2608f33 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/sh
+set -eu
 
 #
 # This script exists primarily to document some of the
@@ -8,7 +9,6 @@
 #
 
 PATH=/usr/local/gnu-autotools/bin/:$PATH
-export PATH
 
 # Start from one level above the build directory
 if [ -f version ]; then
@@ -24,7 +24,7 @@ fi
 # Makefile.  Effectively disable it.
 export MAKEOBJDIRPREFIX=/junk
 
-set -ex
+set -x
 
 #
 # Scrub the local tree before running the build tests below.
index 4d08038926877bb5e76f0e53ba2035de277883b0..50cdca5f720c738f0869adb6abbe9f3fa1fd7228 100755 (executable)
@@ -1,8 +1,10 @@
 #!/bin/sh
+set -eu
+
 ID=$(docker build -q -f build/release/Dockerfile .)
 if [ -z "$ID" ]; then
        echo "Failed to build docker image"
        exit 1
 else
-       docker run $ID sh -c "tar -c -f - libarchive-*" | tar -x -f -
+       docker run "$ID" sh -c "tar -c -f - libarchive-*" | tar -x -f -
 fi
index 93012fe68ff99e828b8baa76d09c9ae15531b8e7..6500de8df2f8c91b17897db16cbe4daf41a01236 100755 (executable)
@@ -1,4 +1,12 @@
 #!/bin/sh
+set -eu
+
+if [ $# != 1 ]
+then
+       echo "Usage: $0 path/to/UnicodeData.txt"
+       exit 1
+fi
+
 #
 # This needs http://unicode.org/Public/6.0.0/ucd/UnicodeData.txt
 #
index 1038da133f776deef2b2aa76acfe05ec4e11c8b5..bc0994b0d7d8e13a3e6c24f9c375947d8fcfe6c3 100755 (executable)
@@ -1,12 +1,14 @@
 #!/bin/sh
-
-set -e
+set -eu
 
 #
 # Simple script to repopulate the 'doc' tree from
 # the mdoc man pages stored in each project.
 #
 
+script_dir=`dirname $0`
+cd "$script_dir"
+
 # Collect list of man pages, relative to my subdirs
 test -d man || mkdir man
 cd man