libmakepkg: extract functions for handling source URLs
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
366adc3bb0
commit
1a17249159
5 changed files with 148 additions and 120 deletions
|
@ -83,7 +83,8 @@ LIBMAKEPKG_IN = \
|
||||||
libmakepkg/tidy/strip.sh \
|
libmakepkg/tidy/strip.sh \
|
||||||
libmakepkg/tidy/upx.sh \
|
libmakepkg/tidy/upx.sh \
|
||||||
libmakepkg/tidy/zipman.sh \
|
libmakepkg/tidy/zipman.sh \
|
||||||
libmakepkg/util.sh
|
libmakepkg/util.sh \
|
||||||
|
libmakepkg/util/source.sh
|
||||||
|
|
||||||
LIBMAKEPKG_DIST = \
|
LIBMAKEPKG_DIST = \
|
||||||
$(LIBMAKEPKG) \
|
$(LIBMAKEPKG) \
|
||||||
|
|
1
scripts/libmakepkg/.gitignore
vendored
1
scripts/libmakepkg/.gitignore
vendored
|
@ -5,3 +5,4 @@ lint_pkgbuild/*.sh
|
||||||
tidy.sh
|
tidy.sh
|
||||||
tidy/*.sh
|
tidy/*.sh
|
||||||
/util.sh
|
/util.sh
|
||||||
|
util/source.sh
|
144
scripts/libmakepkg/util/source.sh.in
Normal file
144
scripts/libmakepkg/util/source.sh.in
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# source.sh - functions to extract information from source URLs
|
||||||
|
#
|
||||||
|
# Copyright (c) 2010-2015 Pacman Development Team <pacman-dev@archlinux.org>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
[[ -n "$LIBMAKEPKG_UTIL_SOURCE_SH" ]] && return
|
||||||
|
LIBMAKEPKG_UTIL_SOURCE_SH=1
|
||||||
|
|
||||||
|
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
|
||||||
|
|
||||||
|
source "$LIBRARY/util/message.sh"
|
||||||
|
|
||||||
|
|
||||||
|
# a source entry can have two forms :
|
||||||
|
# 1) "filename::http://path/to/file"
|
||||||
|
# 2) "http://path/to/file"
|
||||||
|
|
||||||
|
# extract the URL from a source entry
|
||||||
|
get_url() {
|
||||||
|
# strip an eventual filename
|
||||||
|
printf "%s\n" "${1#*::}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# extract the protocol from a source entry - return "local" for local sources
|
||||||
|
get_protocol() {
|
||||||
|
if [[ $1 = *://* ]]; then
|
||||||
|
# strip leading filename
|
||||||
|
local proto="${1#*::}"
|
||||||
|
printf "%s\n" "${proto%%://*}"
|
||||||
|
elif [[ $1 = *lp:* ]]; then
|
||||||
|
local proto="${1#*::}"
|
||||||
|
printf "%s\n" "${proto%%lp:*}"
|
||||||
|
else
|
||||||
|
printf "%s\n" local
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# extract the filename from a source entry
|
||||||
|
get_filename() {
|
||||||
|
local netfile=$1
|
||||||
|
|
||||||
|
# if a filename is specified, use it
|
||||||
|
if [[ $netfile = *::* ]]; then
|
||||||
|
printf "%s\n" ${netfile%%::*}
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local proto=$(get_protocol "$netfile")
|
||||||
|
|
||||||
|
case $proto in
|
||||||
|
bzr*|git*|hg*|svn*)
|
||||||
|
filename=${netfile%%#*}
|
||||||
|
filename=${filename%/}
|
||||||
|
filename=${filename##*/}
|
||||||
|
if [[ $proto = bzr* ]]; then
|
||||||
|
filename=${filename#*lp:}
|
||||||
|
fi
|
||||||
|
if [[ $proto = git* ]]; then
|
||||||
|
filename=${filename%%.git*}
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# if it is just an URL, we only keep the last component
|
||||||
|
filename="${netfile##*/}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
printf "%s\n" "${filename}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return the absolute filename of a source entry
|
||||||
|
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_downloadclient() {
|
||||||
|
local proto=$1
|
||||||
|
|
||||||
|
# loop through DOWNLOAD_AGENTS variable looking for protocol
|
||||||
|
local i
|
||||||
|
for i in "${DLAGENTS[@]}"; do
|
||||||
|
local handler="${i%%::*}"
|
||||||
|
if [[ $proto = "$handler" ]]; then
|
||||||
|
local agent="${i#*::}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# if we didn't find an agent, return an error
|
||||||
|
if [[ -z $agent ]]; then
|
||||||
|
error "$(gettext "Unknown download protocol: %s")" "$proto"
|
||||||
|
plain "$(gettext "Aborting...")"
|
||||||
|
exit 1 # $E_CONFIG_ERROR
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ensure specified program is installed
|
||||||
|
local program="${agent%% *}"
|
||||||
|
if [[ ! -x $program ]]; then
|
||||||
|
local baseprog="${program##*/}"
|
||||||
|
error "$(gettext "The download program %s is not installed.")" "$baseprog"
|
||||||
|
plain "$(gettext "Aborting...")"
|
||||||
|
exit 1 # $E_MISSING_PROGRAM
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s\n" "$agent"
|
||||||
|
}
|
|
@ -170,130 +170,11 @@ clean_up() {
|
||||||
remove_deps
|
remove_deps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enter_fakeroot() {
|
enter_fakeroot() {
|
||||||
msg "$(gettext "Entering %s environment...")" "fakeroot"
|
msg "$(gettext "Entering %s environment...")" "fakeroot"
|
||||||
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
|
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# a source entry can have two forms :
|
|
||||||
# 1) "filename::http://path/to/file"
|
|
||||||
# 2) "http://path/to/file"
|
|
||||||
|
|
||||||
# Return the absolute filename of a source entry
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
# extract the filename from a source entry
|
|
||||||
get_filename() {
|
|
||||||
local netfile=$1
|
|
||||||
|
|
||||||
# if a filename is specified, use it
|
|
||||||
if [[ $netfile = *::* ]]; then
|
|
||||||
printf "%s\n" ${netfile%%::*}
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
local proto=$(get_protocol "$netfile")
|
|
||||||
|
|
||||||
case $proto in
|
|
||||||
bzr*|git*|hg*|svn*)
|
|
||||||
filename=${netfile%%#*}
|
|
||||||
filename=${filename%/}
|
|
||||||
filename=${filename##*/}
|
|
||||||
if [[ $proto = bzr* ]]; then
|
|
||||||
filename=${filename#*lp:}
|
|
||||||
fi
|
|
||||||
if [[ $proto = git* ]]; then
|
|
||||||
filename=${filename%%.git*}
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# if it is just an URL, we only keep the last component
|
|
||||||
filename="${netfile##*/}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
printf "%s\n" "${filename}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# extract the URL from a source entry
|
|
||||||
get_url() {
|
|
||||||
# strip an eventual filename
|
|
||||||
printf "%s\n" "${1#*::}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# extract the protocol from a source entry - return "local" for local sources
|
|
||||||
get_protocol() {
|
|
||||||
if [[ $1 = *://* ]]; then
|
|
||||||
# strip leading filename
|
|
||||||
local proto="${1#*::}"
|
|
||||||
printf "%s\n" "${proto%%://*}"
|
|
||||||
elif [[ $1 = *lp:* ]]; then
|
|
||||||
local proto="${1#*::}"
|
|
||||||
printf "%s\n" "${proto%%lp:*}"
|
|
||||||
else
|
|
||||||
printf "%s\n" local
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_downloadclient() {
|
|
||||||
local proto=$1
|
|
||||||
|
|
||||||
# loop through DOWNLOAD_AGENTS variable looking for protocol
|
|
||||||
local i
|
|
||||||
for i in "${DLAGENTS[@]}"; do
|
|
||||||
local handler="${i%%::*}"
|
|
||||||
if [[ $proto = "$handler" ]]; then
|
|
||||||
local agent="${i#*::}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# if we didn't find an agent, return an error
|
|
||||||
if [[ -z $agent ]]; then
|
|
||||||
error "$(gettext "Unknown download protocol: %s")" "$proto"
|
|
||||||
plain "$(gettext "Aborting...")"
|
|
||||||
exit 1 # $E_CONFIG_ERROR
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ensure specified program is installed
|
|
||||||
local program="${agent%% *}"
|
|
||||||
if [[ ! -x $program ]]; then
|
|
||||||
local baseprog="${program##*/}"
|
|
||||||
error "$(gettext "The download program %s is not installed.")" "$baseprog"
|
|
||||||
plain "$(gettext "Aborting...")"
|
|
||||||
exit 1 # $E_MISSING_PROGRAM
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "%s\n" "$agent"
|
|
||||||
}
|
|
||||||
|
|
||||||
download_local() {
|
download_local() {
|
||||||
local netfile=$1
|
local netfile=$1
|
||||||
local filepath=$(get_filepath "$netfile")
|
local filepath=$(get_filepath "$netfile")
|
||||||
|
|
|
@ -39,5 +39,6 @@ scripts/libmakepkg/tidy/strip.sh.in
|
||||||
scripts/libmakepkg/tidy/upx.sh.in
|
scripts/libmakepkg/tidy/upx.sh.in
|
||||||
scripts/libmakepkg/tidy/zipman.sh.in
|
scripts/libmakepkg/tidy/zipman.sh.in
|
||||||
scripts/libmakepkg/util/message.sh
|
scripts/libmakepkg/util/message.sh
|
||||||
|
scripts/libmakepkg/util/source.sh.in
|
||||||
scripts/library/output_format.sh
|
scripts/library/output_format.sh
|
||||||
scripts/library/parseopts.sh
|
scripts/library/parseopts.sh
|
||||||
|
|
Loading…
Add table
Reference in a new issue