removed bashisms from build scripts

Co-authored-by: Jack Grigg <jack@electriccoin.co>
This commit is contained in:
plutoforever 2018-02-09 11:33:20 -08:00 committed by Jack Grigg
parent 49d76cf3f6
commit 762f643613
3 changed files with 30 additions and 27 deletions

View File

@ -30,6 +30,7 @@ disabled=(
SC2006 # Use $(..) instead of legacy `..`. SC2006 # Use $(..) instead of legacy `..`.
SC2016 # Expressions don't expand in single quotes, use double quotes for that. SC2016 # Expressions don't expand in single quotes, use double quotes for that.
SC2028 # echo won't expand escape sequences. Consider printf. SC2028 # echo won't expand escape sequences. Consider printf.
SC2039 # In POSIX sh, 'local' is undefined.
SC2046 # Quote this to prevent word splitting. SC2046 # Quote this to prevent word splitting.
SC2048 # Use "$@" (with quotes) to prevent whitespace problems. 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. SC2066 # Since you double quoted this, it will not word split, and the loop will only run once.

View File

@ -1,11 +1,11 @@
#!/usr/bin/env bash #!/bin/sh
export LC_ALL=C export LC_ALL=C
set -eu -o pipefail set -eu
set +x set +x
function cmd_pref() { cmd_pref() {
if type -p "$2" > /dev/null; then if command -v "$2" >/dev/null; then
eval "$1=$2" eval "$1=$2"
else else
eval "$1=$3" eval "$1=$3"
@ -13,7 +13,7 @@ function cmd_pref() {
} }
# If a g-prefixed version of the command exists, use it preferentially. # If a g-prefixed version of the command exists, use it preferentially.
function gprefix() { gprefix() {
cmd_pref "$1" "g$2" "$2" 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: # Allow user overrides to $MAKE. Typical usage for users who need it:
# MAKE=gmake ./zcutil/build.sh -j$(nproc) # MAKE=gmake ./zcutil/build.sh -j$(nproc)
if [[ -z "${MAKE-}" ]]; then if [ -z "${MAKE-}" ]; then
MAKE=make MAKE=make
fi fi
# Allow overrides to $BUILD and $HOST for porters. Most users will not need it. # Allow overrides to $BUILD and $HOST for porters. Most users will not need it.
# BUILD=i686-pc-linux-gnu ./zcutil/build.sh # BUILD=i686-pc-linux-gnu ./zcutil/build.sh
if [[ -z "${BUILD-}" ]]; then if [ -z "${BUILD-}" ]; then
BUILD="$(./depends/config.guess)" BUILD="$(./depends/config.guess)"
fi fi
if [[ -z "${HOST-}" ]]; then if [ -z "${HOST-}" ]; then
HOST="$BUILD" HOST="$BUILD"
fi fi
# Allow users to set arbitrary compile flags. Most users will not need this. # 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="" CONFIGURE_FLAGS=""
fi fi
@ -69,13 +69,13 @@ set -x
eval "$MAKE" --version eval "$MAKE" --version
as --version as --version
ENABLE_DEBUG_REGEX='^(.*\s)?--enable-debug(\s.*)?$' case "$CONFIGURE_FLAGS" in
if [[ "$CONFIGURE_FLAGS" =~ $ENABLE_DEBUG_REGEX ]] (*"--enable-debug"*)
then
DEBUG=1 DEBUG=1
else ;;
(*)
DEBUG= DEBUG=
fi ;;esac
HOST="$HOST" BUILD="$BUILD" "$MAKE" "$@" -C ./depends/ DEBUG="$DEBUG" HOST="$HOST" BUILD="$BUILD" "$MAKE" "$@" -C ./depends/ DEBUG="$DEBUG"

View File

@ -1,9 +1,11 @@
#!/usr/bin/env bash #!/bin/sh
export LC_ALL=C export LC_ALL=C
set -eu 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" PARAMS_DIR="$HOME/Library/Application Support/ZcashParams"
else else
PARAMS_DIR="$HOME/.zcash-params" PARAMS_DIR="$HOME/.zcash-params"
@ -30,7 +32,7 @@ ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}"
ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}" ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}"
ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}" ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}"
function fetch_wget { fetch_wget() {
if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then
return 1 return 1
fi fi
@ -51,7 +53,7 @@ EOF
"$DOWNLOAD_URL/$filename" "$DOWNLOAD_URL/$filename"
} }
function fetch_ipfs { fetch_ipfs() {
if [ -z "$IPFSCMD" ] || ! [ -z "$ZC_DISABLE_IPFS" ]; then if [ -z "$IPFSCMD" ] || ! [ -z "$ZC_DISABLE_IPFS" ]; then
return 1 return 1
fi fi
@ -67,7 +69,7 @@ EOF
ipfs get --output "$dlname" "$IPFS_HASH/$filename" ipfs get --output "$dlname" "$IPFS_HASH/$filename"
} }
function fetch_curl { fetch_curl() {
if [ -z "$CURLCMD" ] || ! [ -z "$ZC_DISABLE_CURL" ]; then if [ -z "$CURLCMD" ] || ! [ -z "$ZC_DISABLE_CURL" ]; then
return 1 return 1
fi fi
@ -87,7 +89,7 @@ EOF
} }
function fetch_failure { fetch_failure() {
cat >&2 <<EOF cat >&2 <<EOF
Failed to fetch the Zcash zkSNARK parameters! Failed to fetch the Zcash zkSNARK parameters!
@ -101,7 +103,7 @@ EOF
exit 1 exit 1
} }
function fetch_params { fetch_params() {
local filename="$1" local filename="$1"
local output="$2" local output="$2"
local dlname="${output}.dl" local dlname="${output}.dl"
@ -146,9 +148,9 @@ EOF
} }
# Use flock to prevent parallel execution. # Use flock to prevent parallel execution.
function lock() { lock() {
local lockfile=/tmp/fetch_params.lock local lockfile=/tmp/fetch_params.lock
if [[ "$OSTYPE" == "darwin"* ]]; then if [ "$uname_S" = "Darwin" ]; then
if shlock -f ${lockfile} -p $$; then if shlock -f ${lockfile} -p $$; then
return 0 return 0
else else
@ -156,20 +158,20 @@ function lock() {
fi fi
else else
# create lock file # create lock file
eval "exec 200>$lockfile" eval "exec 9>$lockfile"
# acquire the lock # acquire the lock
flock -n 200 \ flock -n 9 \
&& return 0 \ && return 0 \
|| return 1 || return 1
fi fi
} }
function exit_locked_error { exit_locked_error() {
echo "Only one instance of fetch-params.sh can be run at a time." >&2 echo "Only one instance of fetch-params.sh can be run at a time." >&2
exit 1 exit 1
} }
function main() { main() {
lock fetch-params.sh \ lock fetch-params.sh \
|| exit_locked_error || exit_locked_error