From: Mostyn Bramley-Moore Date: Tue, 20 May 2025 08:14:17 +0000 (+0200) Subject: Add some more error checking to shell scripts (#2617) X-Git-Tag: v3.8.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d80d734190f79a74a870e3f2f9a2ab80071a4a49;p=thirdparty%2Flibarchive.git Add some more error checking to shell scripts (#2617) Exit immediately if a command exits with a non-zero status, and treat unset variables as an error when substituting. --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index adc19e432..4140cab15 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/build/autogen.sh b/build/autogen.sh index e720e9b78..045ccc192 100755 --- a/build/autogen.sh +++ b/build/autogen.sh @@ -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 diff --git a/build/bump-version.sh b/build/bump-version.sh index eec42354f..7cbe9e862 100755 --- a/build/bump-version.sh +++ b/build/bump-version.sh @@ -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 diff --git a/build/ci/build.sh b/build/ci/build.sh index 3a1558264..9b983f64a 100755 --- a/build/ci/build.sh +++ b/build/ci/build.sh @@ -12,14 +12,18 @@ # 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="$?" diff --git a/build/ci/cirrus_ci/ci.sh b/build/ci/cirrus_ci/ci.sh index d49c7277f..29425121f 100755 --- a/build/ci/cirrus_ci/ci.sh +++ b/build/ci/cirrus_ci/ci.sh @@ -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 index 000000000..2aa4823fc --- /dev/null +++ b/build/ci/github_actions/install-macos-dependencies.sh @@ -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 index b42ca0529..000000000 --- a/build/ci/github_actions/macos.sh +++ /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 diff --git a/build/clean.sh b/build/clean.sh index b669426cc..904365f40 100755 --- a/build/clean.sh +++ b/build/clean.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -eu # # Attempt to remove as many generated files as we can. diff --git a/build/makerelease.sh b/build/makerelease.sh index f2869dfca..82843d677 100755 --- a/build/makerelease.sh +++ b/build/makerelease.sh @@ -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. diff --git a/build/release/release.sh b/build/release/release.sh index 4d0803892..50cdca5f7 100755 --- a/build/release/release.sh +++ b/build/release/release.sh @@ -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 diff --git a/build/utils/gen_archive_string_composition_h.sh b/build/utils/gen_archive_string_composition_h.sh index 93012fe68..6500de8df 100755 --- a/build/utils/gen_archive_string_composition_h.sh +++ b/build/utils/gen_archive_string_composition_h.sh @@ -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 # diff --git a/doc/update.sh b/doc/update.sh index 1038da133..bc0994b0d 100755 --- a/doc/update.sh +++ b/doc/update.sh @@ -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