pkgmeek: added a fallback if git urls are not supported

This commit is contained in:
John McQuah 2022-06-02 07:13:52 -04:00
parent b40c8d5612
commit aba956949d

View File

@ -44,7 +44,7 @@ validate_pkgfile || exit $E_PKGFILE
# Let the main routine and subsequent subroutines know what filenames
# they should expect to see on disk.
package="${name}#${version}-${release}.pkg.tar.${PKGMK_COMPRESSION_MODE}"
declare -A _local_
declare -a _local_
for (( s=0; s<${#source[@]}; s++ )); do
if [[ ${source[$s]} =~ ^(http|https|ssh|git)://.*/(.+)\.git ]]; then
_local_[$s]="${BASH_REMATCH[2]}"
@ -64,6 +64,10 @@ done
[ -w "$(dirname "$work")" ] || work="$(pwd)"/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'
[ "$PKGMK_MTIME_ONLY" = "yes" ] || {
for (( u=0; u<${#_local_[@]}; u++ )); do
@ -77,7 +81,7 @@ here="${_local_[$u]}"; url="${source[$u]}";
[ "$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" ) || continue ;
( "$PKGMK_GIT_COMMAND" clone "$url" "$here" ) ;
# but if not, exit with an informative error message
[ -e "$here" ] || { error "failed to download $here. Check connection and try again.";
errDL+=1; }
@ -87,7 +91,7 @@ done ; }
# If the user only asked for '-utd', perform the check using the sources that do exist.
check_pkg_mtime && pkg_utd=0
[ "$PKGMK_MTIME_ONLY" = "no" ] || exit $pkg_utd
[ "$PKGMK_MTIME_ONLY" = "no" ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || exit $pkg_utd
# Some further tests before proceeding with the build
[ "$PKGMK_DOWNLOAD_ONLY" = "no" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || \
@ -96,12 +100,13 @@ check_pkg_mtime && pkg_utd=0
# Take into account all the actions that can be done with a previously built package,
# or with a full set of sources
[ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] \
|| [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "no" ] \
[ "$pkg_utd" = 1 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] \
|| [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_CHECK_SIG" = "yes" ] \
|| [ "$PKGMK_UPDATE_MD5" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "yes" ] \
|| { info "$package is up to date, use '-f' to force a rebuild."; exit 0; }
# Silence the progress report if the user never intended to proceed with unpacking
[ "$pkg_utd" = 0 ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || echo "Checking signatures before unpacking..."
[ "$pkg_utd" = 1 ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || echo "Checking signatures before unpacking..."
# The option -uf is meant to be used AFTER a previous invocation of pkgmeek has
# alerted the user to a footprint mismatch. The options -us|-um are likewise meant
@ -110,7 +115,7 @@ if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
[ -f "$package" ] || \
{ error "unable to update footprint. File '$package' not found.";
exit "$E_MANIFEST"; }
[ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ] || \
[ "$pkg_utd" = 1 ] || [ "$PKGMK_FORCE" = "yes" ] || \
{ error "outdated package. Use '-f' to force the footprint update.";
exit "$E_FOOTPRINT"; }
cat_manifest footprint > "$PKGMK_ROOT/.footprint" || \
@ -135,7 +140,7 @@ fi
# 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."
[ "$pkg_utd" = 0 ] || [ "$PKGMK_IGNORE_SIG" = "yes" ] || \
[ "$pkg_utd" = 1 ] || [ "$PKGMK_IGNORE_SIG" = "yes" ] || \
{ check_signature "pre-build" | parse_signify_output;
case $? in
0) info "Sources successfully authenticated." ;;
@ -227,7 +232,6 @@ readonly PKGMK_VERSION="#VERSION#"
readonly PKGMK_COMMAND="$0"
readonly PKGMK_ROOT="$PWD"
readonly PRTWASH_COMMAND="/usr/bin/prtwash"
readonly PKGMK_GIT_COMMAND="/usr/bin/git"
PKGMK_DOWNLOAD_PROG="/usr/bin/wget"
PKGMK_CONF="/etc/pkgmk.conf"
@ -363,7 +367,7 @@ check_reqvars () {
}
check_pkg_mtime() { # can be called even if some sources are missing
local li=0; local utd=0; local msg="$package is not up to date."
local li=0; local utd=0; local msg="$package is up to date."
if [ -f "$pkg_dir$package" ]; then
utd=1
@ -375,7 +379,7 @@ check_pkg_mtime() { # can be called even if some sources are missing
[ ! -e Pkgfile ] || [ Pkgfile -nt "$pkg_dir$package" ] || utd=0
fi
[ "$utd" = 0 ] || msg="$package is up to date."
[ $utd != 0 ] && msg="$package is not up to date."
info "$msg"; return $utd
}