From 4d46f4bbf26481034dc863e0fab294779d909bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20P=C3=B6chtrager?= Date: Fri, 10 Apr 2020 19:46:06 +0200 Subject: [PATCH] Build scripts & osxcross-macports: Tweak tarball download code --- build_binutils.sh | 4 +-- build_clang.sh | 5 ++-- build_gcc.sh | 6 ++--- tools/osxcross-macports | 59 +++++++++++++++++++++++++++++++---------- tools/tools.sh | 40 ++++++++++++++++++---------- 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/build_binutils.sh b/build_binutils.sh index 2907096..648940f 100755 --- a/build_binutils.sh +++ b/build_binutils.sh @@ -28,8 +28,6 @@ fi # mirror MIRROR="https://ftp.gnu.org/gnu" -require wget - pushd $BUILD_DIR &>/dev/null function remove_locks() @@ -41,7 +39,7 @@ function build_and_install() { if [ ! -f "have_$1_$2_${TARGET}" ]; then pushd $TARBALL_DIR &>/dev/null - wget -c "$MIRROR/$1/$1-$2.tar.gz" + download "$MIRROR/$1/$1-$2.tar.gz" popd &>/dev/null echo "cleaning up ..." diff --git a/build_clang.sh b/build_clang.sh index 86a78c2..5790fec 100755 --- a/build_clang.sh +++ b/build_clang.sh @@ -28,7 +28,6 @@ if [ -z "$INSTALLPREFIX" ]; then INSTALLPREFIX="/usr/local" fi -require wget require cmake function warn_if_installed() @@ -71,8 +70,8 @@ LLVM_PKG+="llvm-${CLANG_VERSION}.src.${PKGCOMPRESSOR}" CLANG_PKG="$MIRROR/${CLANG_VERSION}/" CLANG_PKG+="cfe-${CLANG_VERSION}.src.${PKGCOMPRESSOR}" -wget -c $LLVM_PKG -wget -c $CLANG_PKG +download $LLVM_PKG +download $CLANG_PKG popd &>/dev/null diff --git a/build_gcc.sh b/build_gcc.sh index 70619c6..b7a3a88 100755 --- a/build_gcc.sh +++ b/build_gcc.sh @@ -30,8 +30,6 @@ fi # GCC mirror GCC_MIRROR="https://mirror.koddos.net/gcc" -require wget - pushd $BUILD_DIR &>/dev/null function remove_locks() @@ -45,9 +43,9 @@ if [ ! -f "have_gcc_${GCC_VERSION}_${TARGET}" ]; then pushd $TARBALL_DIR &>/dev/null if [[ $GCC_VERSION != *-* ]]; then - wget -c "$GCC_MIRROR/releases/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" + download "$GCC_MIRROR/releases/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" else - wget -c "$GCC_MIRROR/snapshots/$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" + download "$GCC_MIRROR/snapshots/$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" fi popd &>/dev/null diff --git a/tools/osxcross-macports b/tools/osxcross-macports index 174d835..3b00685 100755 --- a/tools/osxcross-macports +++ b/tools/osxcross-macports @@ -21,11 +21,6 @@ PUBKEYSHA1="214baa965af76ff71187e6c1ac91c559547f48ab" PLATFORM=$(uname -s) ARCH="x86_64" -if [ $PLATFORM == "FreeBSD" ]; then - WGETOPTS="--ca-certificate=" - WGETOPTS+="/usr/local/share/certs/ca-root-nss.crt" -fi - if [ -z "$BASHPID" ]; then BASHPID=$(sh -c 'echo $PPID') fi @@ -72,7 +67,6 @@ unsupportedDepTarget() exit 1 } -require "wget" require "openssl" case $MACOSX_DEPLOYMENT_TARGET in @@ -182,26 +176,63 @@ selectMirror() MIRROR=$(cat $SELECTEDMIRROR) } +function download() +{ + local uri=$1 + local filename + + if [ $# -eq 2 ]; then + filename=$2 + else + filename=$(basename $1) + fi + + if which curl &>/dev/null; then + ## cURL ## + local curl_opts="-L -C - " + if [ -z "$VERBOSE" ]; then + curl_opts+="-s " + fi + if [ $filename != "-" ]; then + curl_opts+="-o $filename " + fi + curl $curl_opts $uri + elif which wget &>/dev/null; then + ## wget ## + local wget_opts="-c -O $filename " + local output=$(wget --no-config 2>&1) + if [[ $output != *--no-config* ]]; then + wget_opts+="--no-config " + fi + if [ $PLATFORM == "FreeBSD" ]; then + wget_opts="--ca-certificate=" + wget_opts+="/usr/local/share/certs/ca-root-nss.crt " + fi + if [ -z "$VERBOSE" ]; then + wget_opts+="--quiet " + fi + wget $wget_opts $uri + else + echo "Required dependency 'curl or wget' not installed" 1>&2 + exit 1 + fi +} + getFileStdout() { verbosePlaceHolder - local xargs="" - [ -z "$VERBOSE" ] && xargs+="--quiet" - wget $WGETOPTS "$1" -O- $xargs + download $1 - #verbosePlaceHolder } getFile() { verbosePlaceHolder - local xargs="" if [ $# -ge 2 ]; then - xargs+="-O $2 " + download $1 $2 else - xargs+="-P $CACHE " + download $1 "$CACHE/$(basename $1)" fi - [ -z "$VERBOSE" ] && xargs+="--quiet" - wget $WGETOPTS -c "$1" $xargs #verbosePlaceHolder } diff --git a/tools/tools.sh b/tools/tools.sh index d72b7c7..71562dc 100644 --- a/tools/tools.sh +++ b/tools/tools.sh @@ -53,20 +53,10 @@ fi function require() { - set +e - which $1 &>/dev/null - while [ $? -ne 0 ] - do - if [ -z "$UNATTENDED" ]; then - echo "" - read -p "Please install '$1' then press enter" - else - echo "Required dependency '$1' is not installed" 1>&2 - exit 1 - fi - which $1 &>/dev/null - done - set -e + if ! which $1 &>/dev/null; then + echo "Required dependency '$1' is not installed" 1>&2 + exit 1 + fi } if [[ $PLATFORM == *BSD ]] || [ $PLATFORM == "DragonFly" ]; then @@ -399,6 +389,28 @@ function get_sources() fi } +function download() +{ + local uri=$1 + local filename=$(basename $1) + + if which curl &>/dev/null; then + ## cURL ## + local curl_opts="-L -C - " + curl $curl_opts -o $filename $uri + elif which wget &>/dev/null; then + ## wget ## + local wget_opts="-c " + local output=$(wget --no-config 2>&1) + if [[ $output != *--no-config* ]]; then + wget_opts+="--no-config " + fi + wget $wget_opts -O $filename $uri + else + echo "Required dependency 'curl or wget' not installed" 1>&2 + exit 1 + fi +} function create_symlink() {