[[ -n "$LIBMAKEPKG_UTIL_SOURCE_SH" ]] && return
LIBMAKEPKG_UTIL_SOURCE_SH=1
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
source "$MAKEPKG_LIBRARY/util/message.sh"
get_url() {
printf "%s\n" "${1#*::}"
}
get_protocol() {
if [[ $1 = *://* ]]; then
local proto="${1#*::}"
proto="${proto%%://*}"
printf "%s\n" "${proto%%+*}"
elif [[ $1 = *lp:* ]]; then
local proto="${1#*::}"
printf "%s\n" "${proto%%+lp:*}"
else
printf "%s\n" local
fi
}
get_filename() {
local netfile=$1
if [[ $netfile = *::* ]]; then
printf "%s\n" "${netfile%%::*}"
return
fi
local proto=$(get_protocol "$netfile")
case $proto in
bzr|fossil|git|hg|svn)
filename=${netfile%%#*}
filename=${filename%%\?*}
filename=${filename%/}
filename=${filename##*/}
if [[ $proto = bzr ]]; then
filename=${filename#*lp:}
fi
if [[ $proto = fossil ]]; then
filename=$filename.fossil
fi
if [[ $proto = git ]]; then
filename=${filename%%.git*}
fi
;;
*)
filename="${netfile##*/}"
;;
esac
printf "%s\n" "${filename}"
}
get_filepath() {
local file="$(get_filename "$1")"
local proto="$(get_protocol "$1")"
case $proto in
bzr|git|hg|svn)
if [[ -d "$startdir/$file" ]]; then
file="$startdir/$file"
elif [[ -d "$SRCDEST/$file" ]]; then
file="$SRCDEST/$file"
else
return 1
fi
;;
*)
if [[ -f "$startdir/$file" ]]; then
file="$startdir/$file"
elif [[ -f "$SRCDEST/$file" ]]; then
file="$SRCDEST/$file"
else
return 1
fi
;;
esac
printf "%s\n" "$file"
}
get_uri_fragment() {
local netfile=$1
local fragment=${netfile#*#}
if [[ $fragment = "$netfile" ]]; then
unset fragment
fi
fragment=${fragment%\?*}
printf "%s\n" "$fragment"
}
get_uri_query() {
local netfile=$1
local query=${netfile#*\?}
if [[ $query = "$netfile" ]]; then
unset query
fi
query=${query%#*}
printf "%s\n" "$query"
}
get_downloadclient() {
local proto=$1
local i
for i in "${DLAGENTS[@]}"; do
local handler="${i%%::*}"
if [[ $proto = "$handler" ]]; then
local agent="${i#*::}"
break
fi
done
if [[ -z $agent ]]; then
error "$(gettext "Unknown download protocol: %s")" "$proto"
plainerr "$(gettext "Aborting...")"
exit 1 fi
local program="${agent%% *}"
if [[ ! -x $program ]]; then
local baseprog="${program##*/}"
error "$(gettext "The download program %s is not installed.")" "$baseprog"
plainerr "$(gettext "Aborting...")"
exit 1 fi
printf "%s\n" "$agent"
}