Auto merge of #2939 - plutoforever:master, r=str4d

removed bashisms from build scripts

Closes https://github.com/zcash/zcash/issues/2677
This commit is contained in:
Homu 2021-04-01 01:37:37 +00:00
commit 51ca3b955a
2 changed files with 53 additions and 52 deletions

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"
@ -19,7 +21,7 @@ DOWNLOAD_URL="https://download.z.cash/downloads"
IPFS_HASH="/ipfs/QmXRHVGLQBiKwvNq7c2vPxAKz1zRVmMYbmt7G5TQss7tY7" IPFS_HASH="/ipfs/QmXRHVGLQBiKwvNq7c2vPxAKz1zRVmMYbmt7G5TQss7tY7"
SHA256CMD="$(command -v sha256sum || echo shasum)" 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 '')" WGETCMD="$(command -v wget || echo '')"
IPFSCMD="$(command -v ipfs || echo '')" IPFSCMD="$(command -v ipfs || echo '')"
@ -30,64 +32,57 @@ 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 { LOCKFILE=/tmp/fetch_params.lock
fetch_wget() {
if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then
return 1 return 1
fi fi
local filename="$1"
local dlname="$2"
cat <<EOF cat <<EOF
Retrieving (wget): $DOWNLOAD_URL/$filename Retrieving (wget): $DOWNLOAD_URL/$1
EOF EOF
wget \ wget \
--progress=dot:giga \ --progress=dot:giga \
--output-document="$dlname" \ --output-document="$2" \
--continue \ --continue \
--retry-connrefused --waitretry=3 --timeout=30 \ --retry-connrefused --waitretry=3 --timeout=30 \
"$DOWNLOAD_URL/$filename" "$DOWNLOAD_URL/$1"
} }
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
local filename="$1"
local dlname="$2"
cat <<EOF cat <<EOF
Retrieving (ipfs): $IPFS_HASH/$filename Retrieving (ipfs): $IPFS_HASH/$1
EOF EOF
ipfs get --output "$dlname" "$IPFS_HASH/$filename" ipfs get --output "$2" "$IPFS_HASH/$1"
} }
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
local filename="$1"
local dlname="$2"
cat <<EOF cat <<EOF
Retrieving (curl): $DOWNLOAD_URL/$filename Retrieving (curl): $DOWNLOAD_URL/$1
EOF EOF
curl \ curl \
--output "$dlname" \ --output "$2" \
-# -L -C - \ -# -L -C - \
"$DOWNLOAD_URL/$filename" "$DOWNLOAD_URL/$1"
} }
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,11 +96,13 @@ EOF
exit 1 exit 1
} }
function fetch_params { fetch_params() {
local filename="$1" # We only set these variables inside this function,
local output="$2" # and unset them at the end of the function.
local dlname="${output}.dl" filename="$1"
local expectedhash="$3" output="$2"
dlname="${output}.dl"
expectedhash="$3"
if ! [ -f "$output" ] if ! [ -f "$output" ]
then then
@ -143,33 +140,37 @@ EOF
exit 1 exit 1
fi fi
fi fi
unset -v filename
unset -v output
unset -v dlname
unset -v expectedhash
} }
# Use flock to prevent parallel execution. # Use flock to prevent parallel execution.
function lock() { lock() {
local lockfile=/tmp/fetch_params.lock if [ "$uname_S" = "Darwin" ]; then
if [[ "$OSTYPE" == "darwin"* ]]; then if shlock -f ${LOCKFILE} -p $$; then
if shlock -f ${lockfile} -p $$; then
return 0 return 0
else else
return 1 return 1
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
@ -232,5 +233,5 @@ then
fi fi
main main
rm -f /tmp/fetch_params.lock rm -f $LOCKFILE
exit 0 exit 0