pkgmk: add support for curl

See FS#1060, https://crux.nu/bugs/index.php?do=details&task_id=1060

New variables in /etc/pkgmk.conf:

PKGMK_DOWNLOAD_PROG="" (curl or wget)
PKGMK_CURL_OPTS="" (parameters for curl, when using curl)
This commit is contained in:
Alan Mizrahi 2015-07-25 12:23:49 +02:00 committed by Juergen Daubert
parent bf4255e16b
commit 3d1855e7d2
4 changed files with 38 additions and 12 deletions

View File

@ -86,6 +86,9 @@ MD5 checksum of source files.
.B "/etc/pkgmk.conf"
Global package make configuration.
.TP
.B "curl"
Used by pkgmk to download source code.
.TP
.B "wget"
Used by pkgmk to download source code.
.SH EXIT CODES
@ -120,7 +123,7 @@ An error occured while running the build function.
.B 9
An error occured while installing the package via pkgadd.
.SH SEE ALSO
pkgmk.conf(5), pkgadd(8), pkgrm(8), pkginfo(8), rejmerge(8), wget(1)
pkgmk.conf(5), pkgadd(8), pkgrm(8), pkginfo(8), rejmerge(8), curl(1), wget(1)
.SH COPYRIGHT
pkgmk (pkgutils) is Copyright (c) 2000-2005 Per Liden and Copyright (c) 2006-2013 CRUX team (http://crux.nu).
pkgmk (pkgutils) is licensed through the GNU General Public License.

View File

@ -30,6 +30,7 @@ esac
# PKGMK_IGNORE_FOOTPRINT="no"
# PKGMK_IGNORE_NEW="no"
# PKGMK_NO_STRIP="no"
# PKGMK_DOWNLOAD_PROG="wget"
# PKGMK_WGET_OPTS=""
# PKGMK_COMPRESSION_MODE="gz"

View File

@ -44,6 +44,16 @@ 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

View File

@ -97,20 +97,32 @@ check_file() {
download_file() {
info "Downloading '$1'."
if [ ! "`type -p wget`" ]; then
error "Command 'wget' not found."
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"
DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \
--directory-prefix=$PKGMK_SOURCE_DIR \
--output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate"
case ${PKGMK_DOWNLOAD_PROG} in
curl)
RESUME_CMD="-C -"
DOWNLOAD_OPTS="-L --fail --ftp-pasv --retry 3 --retry-delay 3 \
-o $LOCAL_FILENAME_PARTIAL --insecure $PKGMK_CURL_OPTS"
;;
wget)
RESUME_CMD="-c"
DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \
--directory-prefix=$PKGMK_SOURCE_DIR \
--output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate $PKGMK_WGET_OPTS"
;;
esac
if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
info "Partial download found, trying to resume"
RESUME_CMD="-c"
RESUME_OPTS="$RESUME_CMD"
fi
error=1
@ -118,7 +130,7 @@ download_file() {
BASENAME=`get_basename $1`
for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do
REPO="`echo $REPO | sed 's|/$||'`"
wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
$PKGMK_DOWNLOAD_PROG $DOWNLOAD_OPTS $RESUME_OPTS $REPO/$BASENAME
error=$?
if [ $error == 0 ]; then
break
@ -127,19 +139,19 @@ download_file() {
if [ $error != 0 ]; then
while true; do
wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
$PKGMK_DOWNLOAD_PROG $DOWNLOAD_OPTS $RESUME_OPTS $1
error=$?
if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
if [ $error != 0 ] && [ "$RESUME_OPTS" ]; then
info "Partial download failed, restarting"
rm -f "$LOCAL_FILENAME_PARTIAL"
RESUME_CMD=""
RESUME_OPTS=""
else
break
fi
done
fi
if [ $error != 0 ]; then
if [ $error != 0 -o ! -f "$LOCAL_FILENAME_PARTIAL" ]; then
error "Downloading '$1' failed."
exit $E_DOWNLOAD
fi