pkgmeek: add support for resuming interrupted downloads
This commit is contained in:
parent
62905f5ac6
commit
1885070666
@ -63,24 +63,14 @@ done
|
|||||||
[ -w "$(dirname "$work")" ] || work="$(pwd)"/work
|
[ -w "$(dirname "$work")" ] || work="$(pwd)"/work
|
||||||
rm -rf "$work"; mkdir -p "$work"/{src,pkg} && cd "$work"
|
rm -rf "$work"; mkdir -p "$work"/{src,pkg} && cd "$work"
|
||||||
|
|
||||||
# Determine whether git can be used to obtain sources
|
|
||||||
PKGMK_GIT_COMMAND="/usr/bin/git"
|
|
||||||
[ -x "$PKGMK_GIT_COMMAND" ] || PKGMK_GIT_COMMAND="/bin/true"
|
|
||||||
|
|
||||||
# Skip the retrieval of sources if the user only asked for '-utd'
|
# Skip the retrieval of sources if the user only asked for '-utd'
|
||||||
[ "$PKGMK_MTIME_ONLY" = "yes" ] || {
|
[ "$PKGMK_MTIME_ONLY" = "yes" ] || { for (( u=0; u<${#_local_[@]}; u++ )); do
|
||||||
for (( u=0; u<${#_local_[@]}; u++ )); do
|
|
||||||
here="${_local_[$u]}"; url="${source[$u]}";
|
here="${_local_[$u]}"; url="${source[$u]}";
|
||||||
# at least one of the following commands should put a file of the
|
# at least one of the following commands should put a file of the
|
||||||
# appropriate name in the current directory
|
# appropriate name in the current directory
|
||||||
[ -e "$here" ] || [ "$src_dir" = "" ] || [ ! -e "$src_dir/$here" ] || ln -sf "$src_dir/$here" ;
|
[ -e "$here" ] || [ "$src_dir" = "" ] || [ ! -e "$src_dir/$here" ] || ln -sf "$src_dir/$here" ;
|
||||||
[ -e "$here" ] || [ ! -e "$PKGMK_ROOT/$here" ] || ln -sf "$PKGMK_ROOT/$here" . ;
|
[ -e "$here" ] || [ ! -e "$PKGMK_ROOT/$here" ] || ln -sf "$PKGMK_ROOT/$here" . ;
|
||||||
[ -e "$here" ] || [[ $url =~ ^(https|ssh|git)://.*/(.+)\.git$ ]] || {
|
[ -e "$here" ] || fetch_source "$url" "$here";
|
||||||
if "$PKGMK_DOWNLOAD_PROG" -O "$here" "$url"; then
|
|
||||||
[ "$src_dir" = "" ] || { mv "$here" "$src_dir"/ && ln -sf "$src_dir/$here" . ; };
|
|
||||||
fi; };
|
|
||||||
[ -e "$here" ] || [[ ! $url =~ ^(https|ssh|git)://.*/(.+)\.git$ ]] || \
|
|
||||||
( "$PKGMK_GIT_COMMAND" clone "$url" "$here" ) ;
|
|
||||||
# but if not, exit with an informative error message
|
# but if not, exit with an informative error message
|
||||||
[ -e "$here" ] || { error "failed to download $here. Check connection and try again.";
|
[ -e "$here" ] || { error "failed to download $here. Check connection and try again.";
|
||||||
errDL+=1; }
|
errDL+=1; }
|
||||||
@ -132,10 +122,8 @@ fi
|
|||||||
|
|
||||||
# Exit after fulfilling any *explicit* requests for (signed) manifests
|
# Exit after fulfilling any *explicit* requests for (signed) manifests
|
||||||
# (decision regarding the work directory is retained from the first run of pkgmeek)
|
# (decision regarding the work directory is retained from the first run of pkgmeek)
|
||||||
if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || \
|
[ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || \
|
||||||
[ "$PKGMK_UPDATE_MD5" = "yes" ];
|
[ "$PKGMK_UPDATE_MD5" = "yes" ] && exit 0
|
||||||
then exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# All the sources should be here by now, let's verify that we can trust them.
|
# All the sources should be here by now, let's verify that we can trust them.
|
||||||
readonly cs_fail_msg="Use '--ignore-signature' to override, if you have determined integrity by other means."
|
readonly cs_fail_msg="Use '--ignore-signature' to override, if you have determined integrity by other means."
|
||||||
@ -377,6 +365,31 @@ check_pkg_mtime() { # can be called even if some sources are missing
|
|||||||
info "$msg"; return $utd
|
info "$msg"; return $utd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetch_source() {
|
||||||
|
local u="$1"; local h="$2"; local SAVE_AS OCONTINUE OOUT;
|
||||||
|
|
||||||
|
# Determine whether git can be used to obtain sources
|
||||||
|
PKGMK_GIT_COMMAND="/usr/bin/git"
|
||||||
|
[ -x "$PKGMK_GIT_COMMAND" ] || PKGMK_GIT_COMMAND="/bin/false"
|
||||||
|
[[ $u =~ ^(https|http|ssh|git)://.*/(.+)\.git$ ]] && SAVE_AS="$PKGMK_GIT_COMMAND clone $u"
|
||||||
|
|
||||||
|
[[ "$PKGMK_DOWNLOAD_PROG" =~ wget$ ]] && { OCONTINUE="-c"; OOUT="-O"; }
|
||||||
|
[[ "$PKGMK_DOWNLOAD_PROG" =~ curl$ ]] && { OCONTINUE="-C -"; OOUT="-o"; }
|
||||||
|
[[ "$PKGMK_DOWNLOAD_PROG" =~ (wget|curl)$ ]] || SAVE_AS=/bin/false
|
||||||
|
|
||||||
|
[ -s "$src_dir/$h.partial" ] && { ln -s "$src_dir/$h.partial" . ;
|
||||||
|
SAVE_AS="$PKGMK_DOWNLOAD_PROG $u $OCONTINUE $OOUT"; } \
|
||||||
|
|| SAVE_AS="$PKGMK_DOWNLOAD_PROG $u $OOUT"
|
||||||
|
|
||||||
|
if $SAVE_AS "$h.partial"; then
|
||||||
|
[ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] || { mv "$h.partial" "$src_dir/$h";
|
||||||
|
ln -sf "$src_dir/$h" . ; }
|
||||||
|
else # an interrupted download should not have its efforts destroyed by cleanup_work()
|
||||||
|
[ ! -e "$h.partial" ] || [ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] \
|
||||||
|
|| mv "$h.partial" "$src_dir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cat_manifest() {
|
cat_manifest() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
footprint)
|
footprint)
|
||||||
@ -394,7 +407,7 @@ cat_manifest() {
|
|||||||
check_manifest() {
|
check_manifest() {
|
||||||
local FILTER TRUTH CN CM
|
local FILTER TRUTH CN CM
|
||||||
local retval=0; local severity=error;
|
local retval=0; local severity=error;
|
||||||
[ -f "$pkgdir$package" ] || [ "$1" = "md5sum" ] || { error "$package not found. Cannot check $1.";
|
[ -f "$pkg_dir$package" ] || [ "$1" = "md5sum" ] || { error "$package not found. Cannot check $1.";
|
||||||
return "$E_MANIFEST"; }
|
return "$E_MANIFEST"; }
|
||||||
[ "$1" = "md5sum" ] && FILTER="-k 3" || FILTER=""
|
[ "$1" = "md5sum" ] && FILTER="-k 3" || FILTER=""
|
||||||
TRUTH="$PKGMK_ROOT/.$1"
|
TRUTH="$PKGMK_ROOT/.$1"
|
||||||
@ -549,7 +562,8 @@ error() {
|
|||||||
######################## end of subroutines ###########################
|
######################## end of subroutines ###########################
|
||||||
## Now ensure that they cannot be overwritten when sourcing Pkgfile ##
|
## Now ensure that they cannot be overwritten when sourcing Pkgfile ##
|
||||||
readonly -f main info warning error print_help parse_options validate_pkgfile \
|
readonly -f main info warning error print_help parse_options validate_pkgfile \
|
||||||
check_reqvars check_pkg_mtime cat_manifest check_manifest cat_signature \
|
check_reqvars check_pkg_mtime fetch_source cat_manifest check_manifest \
|
||||||
check_signature parse_signify_output refresh_signature cleanup_work recursive
|
cat_signature check_signature parse_signify_output refresh_signature \
|
||||||
|
cleanup_work recursive
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
Loading…
Reference in New Issue
Block a user