makepkg: generalize download_sources
In order to treat all VCS sources as URLs, we need to be able to deal with more protocols. Rewrite download_sources to use a case statement so additional protocols are easily added. Also fix the use of scp to not pass the protocol in the URL (noticed by William J. Bowman <wjb@williamjbowman.com>) Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
a922d18056
commit
1a04e2e11a
1 changed files with 67 additions and 45 deletions
|
@ -236,9 +236,7 @@ get_protocol() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get_downloadclient() {
|
get_downloadclient() {
|
||||||
# $1 = URL with valid protocol prefix
|
local proto=$1
|
||||||
local url=$1
|
|
||||||
local proto="${url%%://*}"
|
|
||||||
|
|
||||||
# loop through DOWNLOAD_AGENTS variable looking for protocol
|
# loop through DOWNLOAD_AGENTS variable looking for protocol
|
||||||
local i
|
local i
|
||||||
|
@ -269,20 +267,56 @@ get_downloadclient() {
|
||||||
printf "%s\n" "$agent"
|
printf "%s\n" "$agent"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
download_local() {
|
||||||
|
local netfile=$1
|
||||||
|
local filepath=$(get_filepath "$netfile")
|
||||||
|
|
||||||
|
if [[ -n "$filepath" ]]; then
|
||||||
|
msg2 "$(gettext "Found %s")" "${filepath##*/}"
|
||||||
|
rm -f "$srcdir/${filepath##*/}"
|
||||||
|
ln -s "$filepath" "$srcdir/"
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
local filename=$(get_filename "$netfile")
|
||||||
|
error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename"
|
||||||
|
exit 1 # $E_MISSING_FILE
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
download_file() {
|
download_file() {
|
||||||
# download command
|
local netfile=$1
|
||||||
local dlcmd=$1
|
|
||||||
# URL of the file
|
local filepath=$(get_filepath "$netfile")
|
||||||
local url=$2
|
if [[ -n "$filepath" ]]; then
|
||||||
# destination file
|
msg2 "$(gettext "Found %s")" "${filepath##*/}"
|
||||||
local file=$3
|
rm -f "$srcdir/${filepath##*/}"
|
||||||
|
ln -s "$filepath" "$srcdir/"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local proto=$(get_protocol "$netfile")
|
||||||
|
|
||||||
|
# find the client we should use for this URL
|
||||||
|
local dlcmd
|
||||||
|
dlcmd=$(get_downloadclient "$proto") || exit $?
|
||||||
|
|
||||||
|
local filename=$(get_filename "$netfile")
|
||||||
|
local url=$(get_url "$netfile")
|
||||||
|
|
||||||
|
if [[ $proto = "scp" ]]; then
|
||||||
|
# scp downloads should not pass the protocol in the url
|
||||||
|
url="${url##*://}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg2 "$(gettext "Downloading %s...")" "$filename"
|
||||||
|
|
||||||
# temporary download file, default to last component of the URL
|
# temporary download file, default to last component of the URL
|
||||||
local dlfile="${url##*/}"
|
local dlfile="${url##*/}"
|
||||||
|
|
||||||
# replace %o by the temporary dlfile if it exists
|
# replace %o by the temporary dlfile if it exists
|
||||||
if [[ $dlcmd = *%o* ]]; then
|
if [[ $dlcmd = *%o* ]]; then
|
||||||
dlcmd=${dlcmd//\%o/\"$file.part\"}
|
dlcmd=${dlcmd//\%o/\"$filename.part\"}
|
||||||
dlfile="$file.part"
|
dlfile="$filename.part"
|
||||||
fi
|
fi
|
||||||
# add the URL, either in place of %u or at the end
|
# add the URL, either in place of %u or at the end
|
||||||
if [[ $dlcmd = *%u* ]]; then
|
if [[ $dlcmd = *%u* ]]; then
|
||||||
|
@ -295,13 +329,18 @@ download_file() {
|
||||||
eval "$dlcmd || ret=\$?"
|
eval "$dlcmd || ret=\$?"
|
||||||
if (( ret )); then
|
if (( ret )); then
|
||||||
[[ ! -s $dlfile ]] && rm -f -- "$dlfile"
|
[[ ! -s $dlfile ]] && rm -f -- "$dlfile"
|
||||||
return $ret
|
error "$(gettext "Failure while downloading %s")" "$filename"
|
||||||
|
plain "$(gettext "Aborting...")"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# rename the temporary download file to the final destination
|
# rename the temporary download file to the final destination
|
||||||
if [[ $dlfile != "$file" ]]; then
|
if [[ $dlfile != "$filename" ]]; then
|
||||||
mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
|
mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$srcdir/$filename"
|
||||||
|
ln -s "$SRCDEST/$filename" "$srcdir/"
|
||||||
}
|
}
|
||||||
|
|
||||||
download_sources() {
|
download_sources() {
|
||||||
|
@ -311,38 +350,21 @@ download_sources() {
|
||||||
|
|
||||||
local netfile
|
local netfile
|
||||||
for netfile in "${source[@]}"; do
|
for netfile in "${source[@]}"; do
|
||||||
local file=$(get_filepath "$netfile" || true)
|
local proto=$(get_protocol "$netfile")
|
||||||
if [[ -n "$file" ]]; then
|
|
||||||
msg2 "$(gettext "Found %s")" "${file##*/}"
|
|
||||||
rm -f "$srcdir/${file##*/}"
|
|
||||||
ln -s "$file" "$srcdir/"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
file=$(get_filename "$netfile")
|
case "$proto" in
|
||||||
local url=$(get_url "$netfile")
|
local)
|
||||||
|
download_local "$netfile"
|
||||||
# if we get here, check to make sure it was a URL, else fail
|
;;
|
||||||
if [[ $file = "$url" ]]; then
|
ftp|http|https|rsync|scp)
|
||||||
error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
|
download_file "$netfile"
|
||||||
exit 1 # $E_MISSING_FILE
|
;;
|
||||||
fi
|
*)
|
||||||
|
error "$(gettext "Unknown download protocol: %s")" "$proto"
|
||||||
# find the client we should use for this URL
|
|
||||||
local dlclient
|
|
||||||
dlclient=$(get_downloadclient "$url") || exit $?
|
|
||||||
|
|
||||||
msg2 "$(gettext "Downloading %s...")" "$file"
|
|
||||||
# fix flyspray bug #3289
|
|
||||||
local ret=0
|
|
||||||
download_file "$dlclient" "$url" "$file" || ret=$?
|
|
||||||
if (( ret )); then
|
|
||||||
error "$(gettext "Failure while downloading %s")" "$file"
|
|
||||||
plain "$(gettext "Aborting...")"
|
plain "$(gettext "Aborting...")"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
rm -f "$srcdir/$file"
|
esac
|
||||||
ln -s "$SRCDEST/$file" "$srcdir/"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
popd &>/dev/null
|
popd &>/dev/null
|
||||||
|
|
Loading…
Add table
Reference in a new issue