From 762f6436137b6245e438836f03ae4233a2fe4ef7 Mon Sep 17 00:00:00 2001 From: plutoforever Date: Fri, 9 Feb 2018 11:33:20 -0800 Subject: [PATCH 1/3] removed bashisms from build scripts Co-authored-by: Jack Grigg --- test/lint/lint-shell.sh | 1 + zcutil/build.sh | 28 ++++++++++++++-------------- zcutil/fetch-params.sh | 28 +++++++++++++++------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/test/lint/lint-shell.sh b/test/lint/lint-shell.sh index 00523f66e..833e4cfcc 100755 --- a/test/lint/lint-shell.sh +++ b/test/lint/lint-shell.sh @@ -30,6 +30,7 @@ disabled=( SC2006 # Use $(..) instead of legacy `..`. SC2016 # Expressions don't expand in single quotes, use double quotes for that. SC2028 # echo won't expand escape sequences. Consider printf. + SC2039 # In POSIX sh, 'local' is undefined. SC2046 # Quote this to prevent word splitting. SC2048 # Use "$@" (with quotes) to prevent whitespace problems. SC2066 # Since you double quoted this, it will not word split, and the loop will only run once. diff --git a/zcutil/build.sh b/zcutil/build.sh index a2e12f5c0..6c157bd1f 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -1,11 +1,11 @@ -#!/usr/bin/env bash +#!/bin/sh export LC_ALL=C -set -eu -o pipefail +set -eu set +x -function cmd_pref() { - if type -p "$2" > /dev/null; then +cmd_pref() { + if command -v "$2" >/dev/null; then eval "$1=$2" else eval "$1=$3" @@ -13,7 +13,7 @@ function cmd_pref() { } # If a g-prefixed version of the command exists, use it preferentially. -function gprefix() { +gprefix() { cmd_pref "$1" "g$2" "$2" } @@ -22,21 +22,21 @@ cd "$(dirname "$("$READLINK" -f "$0")")/.." # Allow user overrides to $MAKE. Typical usage for users who need it: # MAKE=gmake ./zcutil/build.sh -j$(nproc) -if [[ -z "${MAKE-}" ]]; then +if [ -z "${MAKE-}" ]; then MAKE=make fi # Allow overrides to $BUILD and $HOST for porters. Most users will not need it. # BUILD=i686-pc-linux-gnu ./zcutil/build.sh -if [[ -z "${BUILD-}" ]]; then +if [ -z "${BUILD-}" ]; then BUILD="$(./depends/config.guess)" fi -if [[ -z "${HOST-}" ]]; then +if [ -z "${HOST-}" ]; then HOST="$BUILD" fi # Allow users to set arbitrary compile flags. Most users will not need this. -if [[ -z "${CONFIGURE_FLAGS-}" ]]; then +if [ -z "${CONFIGURE_FLAGS-}" ]; then CONFIGURE_FLAGS="" fi @@ -69,13 +69,13 @@ set -x eval "$MAKE" --version as --version -ENABLE_DEBUG_REGEX='^(.*\s)?--enable-debug(\s.*)?$' -if [[ "$CONFIGURE_FLAGS" =~ $ENABLE_DEBUG_REGEX ]] -then +case "$CONFIGURE_FLAGS" in +(*"--enable-debug"*) DEBUG=1 -else +;; +(*) DEBUG= -fi +;;esac HOST="$HOST" BUILD="$BUILD" "$MAKE" "$@" -C ./depends/ DEBUG="$DEBUG" diff --git a/zcutil/fetch-params.sh b/zcutil/fetch-params.sh index 25d961ab1..9d776787d 100755 --- a/zcutil/fetch-params.sh +++ b/zcutil/fetch-params.sh @@ -1,9 +1,11 @@ -#!/usr/bin/env bash +#!/bin/sh export LC_ALL=C set -eu -if [[ "$OSTYPE" == "darwin"* ]]; then +uname_S=$(uname -s 2>/dev/null || echo not) + +if [ "$uname_S" = "Darwin" ]; then PARAMS_DIR="$HOME/Library/Application Support/ZcashParams" else PARAMS_DIR="$HOME/.zcash-params" @@ -30,7 +32,7 @@ ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}" ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}" ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}" -function fetch_wget { +fetch_wget() { if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then return 1 fi @@ -51,7 +53,7 @@ EOF "$DOWNLOAD_URL/$filename" } -function fetch_ipfs { +fetch_ipfs() { if [ -z "$IPFSCMD" ] || ! [ -z "$ZC_DISABLE_IPFS" ]; then return 1 fi @@ -67,7 +69,7 @@ EOF ipfs get --output "$dlname" "$IPFS_HASH/$filename" } -function fetch_curl { +fetch_curl() { if [ -z "$CURLCMD" ] || ! [ -z "$ZC_DISABLE_CURL" ]; then return 1 fi @@ -87,7 +89,7 @@ EOF } -function fetch_failure { +fetch_failure() { cat >&2 <$lockfile" + eval "exec 9>$lockfile" # acquire the lock - flock -n 200 \ + flock -n 9 \ && return 0 \ || return 1 fi } -function exit_locked_error { +exit_locked_error() { echo "Only one instance of fetch-params.sh can be run at a time." >&2 exit 1 } -function main() { +main() { lock fetch-params.sh \ || exit_locked_error From a1903d2644ceddc68077e0608e448afa7e514a5b Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 1 Apr 2021 14:28:41 +1300 Subject: [PATCH 2/3] Remove usage of local from fetch-params.sh --- test/lint/lint-shell.sh | 1 - zcutil/fetch-params.sh | 49 ++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/test/lint/lint-shell.sh b/test/lint/lint-shell.sh index 833e4cfcc..00523f66e 100755 --- a/test/lint/lint-shell.sh +++ b/test/lint/lint-shell.sh @@ -30,7 +30,6 @@ disabled=( SC2006 # Use $(..) instead of legacy `..`. SC2016 # Expressions don't expand in single quotes, use double quotes for that. SC2028 # echo won't expand escape sequences. Consider printf. - SC2039 # In POSIX sh, 'local' is undefined. SC2046 # Quote this to prevent word splitting. SC2048 # Use "$@" (with quotes) to prevent whitespace problems. SC2066 # Since you double quoted this, it will not word split, and the loop will only run once. diff --git a/zcutil/fetch-params.sh b/zcutil/fetch-params.sh index 9d776787d..69d2e964d 100755 --- a/zcutil/fetch-params.sh +++ b/zcutil/fetch-params.sh @@ -32,25 +32,24 @@ ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}" ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}" ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}" +LOCKFILE=/tmp/fetch_params.lock + fetch_wget() { if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then return 1 fi - local filename="$1" - local dlname="$2" - cat <$lockfile" + eval "exec 9>$LOCKFILE" # acquire the lock flock -n 9 \ && return 0 \ @@ -234,5 +233,5 @@ then fi main -rm -f /tmp/fetch_params.lock +rm -f $LOCKFILE exit 0 From fb38cf0d90d3b2b7b888040a601d884262d05ca0 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 1 Apr 2021 14:30:35 +1300 Subject: [PATCH 3/3] lint: Fix false positive shellcheck interprets the single-quoted string as arguments to echo, not the string that echo echos. Switching to double quotes fixes the lint. --- zcutil/fetch-params.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcutil/fetch-params.sh b/zcutil/fetch-params.sh index 69d2e964d..fba5de078 100755 --- a/zcutil/fetch-params.sh +++ b/zcutil/fetch-params.sh @@ -21,7 +21,7 @@ DOWNLOAD_URL="https://download.z.cash/downloads" IPFS_HASH="/ipfs/QmXRHVGLQBiKwvNq7c2vPxAKz1zRVmMYbmt7G5TQss7tY7" SHA256CMD="$(command -v sha256sum || echo shasum)" -SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')" +SHA256ARGS="$(command -v sha256sum >/dev/null || echo \"-a 256\")" WGETCMD="$(command -v wget || echo '')" IPFSCMD="$(command -v ipfs || echo '')"