From cdcbefc784ed3806f46b4e2d33bbd2ef27c24df0 Mon Sep 17 00:00:00 2001 From: Fun Date: Mon, 8 Jan 2018 01:21:02 +0200 Subject: [PATCH 1/3] pkgmk: replace PKGMK_DOWNLOAD_PROG with download_url() This moves the complexity of downloading files out of pkgmk to user fingers (/etc/pkgmk.conf) giving users more flexibility. The default function from pkgmk: download_url() { wget ... } can be redefined in /etc/pkgmk.conf: download_url() { curl -L --fail --ftp-pasv --retry 3 --retry-delay 3 ${3/1/-C -} -o "$2" "$1" } or download_url() { case "${2##*/}" in java*) cp "/local/downloads/${2##*/}" "$2" ;; chrome*) axel ... ;; *) curl ... ;; } We also drop PKGMK_WGET_OPTS and PKGMK_CURL_OPTS. --- pkgmk.conf | 3 --- pkgmk.conf.5.in | 14 -------------- pkgmk.in | 36 +++++++++++++----------------------- 3 files changed, 13 insertions(+), 40 deletions(-) diff --git a/pkgmk.conf b/pkgmk.conf index 781e8b9..25529c2 100644 --- a/pkgmk.conf +++ b/pkgmk.conf @@ -33,9 +33,6 @@ esac # PKGMK_IGNORE_FOOTPRINT="no" # PKGMK_IGNORE_NEW="no" # PKGMK_NO_STRIP="no" -# PKGMK_DOWNLOAD_PROG="wget" -# PKGMK_WGET_OPTS="" -# PKGMK_CURL_OPTS="" # PKGMK_COMPRESSION_MODE="gz" # End of file diff --git a/pkgmk.conf.5.in b/pkgmk.conf.5.in index 98976d6..9a85c82 100644 --- a/pkgmk.conf.5.in +++ b/pkgmk.conf.5.in @@ -49,20 +49,6 @@ Set directory for building packages. .br Default: '\fBfoo\fP/work', where \fBfoo\fP is the directory of the Pkgfile. .TP -\fBPKGMK_DOWNLOAD_PROG='STRING'\fP -Use specified program to download source archives. Valid strings are curl and wget. -.br -Default: 'wget' -.br -.TP -\fBPKGMK_CURL_OPTS='STRING'\fP -Additional options for curl(1), which is used by pkgmk to download all files. -.br -.TP -\fBPKGMK_WGET_OPTS='STRING'\fP -Additional options for wget(1), which is used by pkgmk to download all files. -.br -.TP \fBPKGMK_DOWNLOAD='STRING'\fP If set to 'yes', pkgmk will download the source archives if necessary. .br diff --git a/pkgmk.in b/pkgmk.in index 6ee685f..416358a 100755 --- a/pkgmk.in +++ b/pkgmk.in @@ -105,35 +105,25 @@ check_file() { fi } +# curl -L --fail --ftp-pasv --retry 3 --retry-delay 3 ${3/1/-C -} -o "$2" "$1" +download_url() { + local URL=$1 + local DEST=$2 + local RESUME=$3 + wget --compression=none --passive-ftp --no-directories --tries=3 --waitretry=3 \ + ${RESUME/1/-c} "--directory-prefix=${DEST%/*}" "--output-document=$DEST" "$URL" +} + download_file() { info "Downloading '$1'." - PKGMK_DOWNLOAD_PROG=${PKGMK_DOWNLOAD_PROG:-wget} - if [ ! "`type -p ${PKGMK_DOWNLOAD_PROG}`" ]; then - error "Command '${PKGMK_DOWNLOAD_PROG}' not found." - exit $E_GENERAL - fi - LOCAL_FILENAME=`get_filename $1` LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial" - case ${PKGMK_DOWNLOAD_PROG} in - curl) - RESUME_CMD="-C -" - DOWNLOAD_OPTS="-L --fail --ftp-pasv --retry 3 --retry-delay 3 \ - -o $LOCAL_FILENAME_PARTIAL $PKGMK_CURL_OPTS" - ;; - wget) - RESUME_CMD="-c" - DOWNLOAD_OPTS="--compression=none --passive-ftp --no-directories --tries=3 --waitretry=3 \ - --directory-prefix=$PKGMK_SOURCE_DIR \ - --output-document=$LOCAL_FILENAME_PARTIAL $PKGMK_WGET_OPTS" - ;; - esac - + local RESUME_OPTS= if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then info "Partial download found, trying to resume" - RESUME_OPTS="$RESUME_CMD" + RESUME_OPTS=1 fi error=1 @@ -141,7 +131,7 @@ download_file() { BASENAME=`get_basename $1` for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do REPO="`echo $REPO | sed 's|/$||'`" - $PKGMK_DOWNLOAD_PROG $DOWNLOAD_OPTS $RESUME_OPTS $REPO/$BASENAME + download_url "$REPO/$BASENAME" "$LOCAL_FILENAME_PARTIAL" $RESUME_OPTS error=$? if [ $error == 0 ]; then break @@ -150,7 +140,7 @@ download_file() { if [ $error != 0 ]; then while true; do - $PKGMK_DOWNLOAD_PROG $DOWNLOAD_OPTS $RESUME_OPTS $1 + download_url "$1" "$LOCAL_FILENAME_PARTIAL" $RESUME_OPTS error=$? if [ $error != 0 ] && [ "$RESUME_OPTS" ]; then info "Partial download failed, restarting" -- 2.17.0