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
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"

View File

@ -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"
@ -19,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 '')"
@ -30,64 +32,57 @@ ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}"
ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}"
ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}"
function fetch_wget {
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 <<EOF
Retrieving (wget): $DOWNLOAD_URL/$filename
Retrieving (wget): $DOWNLOAD_URL/$1
EOF
wget \
--progress=dot:giga \
--output-document="$dlname" \
--output-document="$2" \
--continue \
--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
return 1
fi
local filename="$1"
local dlname="$2"
cat <<EOF
Retrieving (ipfs): $IPFS_HASH/$filename
Retrieving (ipfs): $IPFS_HASH/$1
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
return 1
fi
local filename="$1"
local dlname="$2"
cat <<EOF
Retrieving (curl): $DOWNLOAD_URL/$filename
Retrieving (curl): $DOWNLOAD_URL/$1
EOF
curl \
--output "$dlname" \
--output "$2" \
-# -L -C - \
"$DOWNLOAD_URL/$filename"
"$DOWNLOAD_URL/$1"
}
function fetch_failure {
fetch_failure() {
cat >&2 <<EOF
Failed to fetch the Zcash zkSNARK parameters!
@ -101,11 +96,13 @@ EOF
exit 1
}
function fetch_params {
local filename="$1"
local output="$2"
local dlname="${output}.dl"
local expectedhash="$3"
fetch_params() {
# We only set these variables inside this function,
# and unset them at the end of the function.
filename="$1"
output="$2"
dlname="${output}.dl"
expectedhash="$3"
if ! [ -f "$output" ]
then
@ -143,33 +140,37 @@ EOF
exit 1
fi
fi
unset -v filename
unset -v output
unset -v dlname
unset -v expectedhash
}
# Use flock to prevent parallel execution.
function lock() {
local lockfile=/tmp/fetch_params.lock
if [[ "$OSTYPE" == "darwin"* ]]; then
if shlock -f ${lockfile} -p $$; then
lock() {
if [ "$uname_S" = "Darwin" ]; then
if shlock -f ${LOCKFILE} -p $$; then
return 0
else
return 1
fi
else
# create lock file
eval "exec 200>$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
@ -232,5 +233,5 @@ then
fi
main
rm -f /tmp/fetch_params.lock
rm -f $LOCKFILE
exit 0