pkgmeek: remove superfluous bash pattern matching

This commit is contained in:
John McQuah 2022-06-03 18:14:35 -04:00
parent 3aacbacba0
commit 1d82f6cedf

View File

@ -10,7 +10,7 @@ main() {
######################## main routine ################################
local o_ignored pkg_dir src_dir work _local_ here url u f pkg_utd; local errDL=0; local errUZ=0;
parse_options "$@"
[ "$PKGMK_RECURSIVE" = "no" ] || recursive "$@"
[ "$PKGMK_RECURSIVE" = "yes" ] && recursive "$@"
#
# Exit early if cleaning was requested
#
@ -45,13 +45,8 @@ validate_pkgfile || exit $E_PKGFILE
package="${name}#${version}-${release}.pkg.tar.${PKGMK_COMPRESSION_MODE}"
declare -a _local_
for (( s=0; s<${#source[@]}; s++ )); do
if [[ ${source[$s]} =~ ^(http|https|ssh|git)://.*/(.+)\.git$ ]]; then
_local_[$s]="${BASH_REMATCH[2]}"
elif [[ ${source[$s]} =~ ^(http|https|ftp|file)://.*/(.+) ]]; then
_local_[$s]="${BASH_REMATCH[2]}"
else
_local_[$s]="${source[$s]}"
fi
[[ ${source[$s]} =~ ^(http|https|ftp|ssh|git)://.*/(.+) ]] && \
_local_[$s]="${BASH_REMATCH[2]%%.git}" || _local_[$s]="${source[$s]}"
[ -z "${renames[$s]}" ] || [ "${renames[$s]}" = "SKIP" ] || \
_local_[$s]="${renames[$s]}"
done
@ -71,8 +66,7 @@ here="${_local_[$u]}"; url="${source[$u]}";
[ -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" ] || fetch_source "$url" "$here"; # <-- should also be able to resume partial downloads
[ -e "$here" ] || { error "failed to download $here. Check connection and try again.";
errDL+=1; }
[ -e "$here" ] || { error "failed to download $here. Check connection and try again."; errDL+=1; }
done ; }
[ $errDL = 0 ] && { [ "$PKGMK_MTIME_ONLY" = "yes" ] || \
@ -135,11 +129,10 @@ case $? in
esac; }
[ "$PKGMK_CHECK_SIG" = "no" ] || exit 0 # no need to continue if the user only requested -cs
# What used to be called unpack_source() is now hard-coded into the main routine.
# If you need to shield specific source files from unpacking, use the "renames"
# feature of Pkgfile(5) to avoid matching any of the following patterns.
if [ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ]; then
if [ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ]; then # Skip the extract, build steps.
# What used to be called unpack_source() is now hard-coded into the main routine.
# If you need to shield specific source files from unpacking, use the "renames"
# feature of Pkgfile(5) to avoid matching any of the following patterns.
for (( u=0; u<${#_local_[@]}; u++ )) ; do
here="${_local_[$u]}"
case "$here" in
@ -154,7 +147,7 @@ if [ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ]; then
{ error "Failed to unpack all sources."; exit "$E_UNPACK"; }
[ "$PKGMK_EXTRACT_ONLY" = "no" ] || exit 0
# The actual build step!
# The actual build step! (some ports choke if you try it as a regular user without fakeroot)
(SRC=$(pwd)/src; PKG=$(pwd)/pkg; cd src; set -x; build) &&
info "Build succeeded. Moving on to compression." ||
{ error "Unsuccessful build!"; cleanup_work; exit "$E_BUILD"; }
@ -184,7 +177,7 @@ if [ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ]; then
[ "$pkg_dir" = "$(pwd)/" ] || ln -sf "$pkg_dir$package" .
[ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ] || check_manifest footprint || exit $E_MANIFEST
# Clean up, part 1: remove soft links and the work directory
# Clean up the work directory
find . -maxdepth 1 -mindepth 1 -type l -delete; cleanup_work
fi # Continue from here if the extract and build were skipped
@ -256,7 +249,7 @@ parse_options() {
-us|--update-signature) PKGMK_UPDATE_SIG="yes" ;;
-rs|--refresh-signature) PKGMK_REFRESH_SIG="yes" ;;
-cs|--check-signature) PKGMK_CHECK_SIG="yes" ;;
-d|-cm|--download|--check-md5sum) ;;
-d|-cm|--download|--check-md5sum) ;; # deprecated flags, but at least they won't trigger an error
-do|--download-only) PKGMK_DOWNLOAD_ONLY="yes" ;;
-eo|--extract-only) PKGMK_EXTRACT_ONLY="yes" ;;
-utd|--up-to-date) PKGMK_MTIME_ONLY="yes" ;;
@ -278,7 +271,7 @@ parse_options() {
exit 1; }
shift ;;
-cf|--config-file)
[ "$2" ] && PKGMK_CONF="$2"|| { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument";
[ "$2" ] && PKGMK_CONF="$2" || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument";
exit 1; }
shift ;;
-v|--version)
@ -379,15 +372,14 @@ fetch_source() {
[[ "$PKGMK_DOWNLOAD_PROG" =~ (wget|curl)$ ]] || SAVE_AS=/bin/false
local m=${#PKGMK_SOURCE_MIRRORS[@]}
# nonexistent element of PKGMK_SOURCE_MIRRORS means that the
# url given in the Pkgfile will be tried first
# start with the url in the Pkgfile, then hit the mirrors until a download succeeds
while [ $m -ge 0 ] && [ $finished = 0 ] && [[ ! $SAVE_AS =~ false$ ]]; do
[ "${PKGMK_SOURCE_MIRRORS[m]}" = "" ] && um=$u || \
{ REPO=$(echo ${PKGMK_SOURCE_MIRRORS[m]} | sed 's,/$,,');
um=$REPO/$(echo $u | sed 's,.*/,,'); }
m=$(( m-1 ))
# interrupted downloads from a previous run should be put where wget or curl will find them
# interrupted downloads from a previous run should be put where wget or curl will find them
[ -s "$src_dir/$h.partial" ] && { ln -s "$src_dir/$h.partial" . ;
SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OCONTINUE $OOUT"; } \
|| SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OOUT"
@ -418,12 +410,11 @@ cat_manifest() {
}
check_manifest() {
local FILTER TRUTH CN CM
local retval=0; local severity=error;
[ -f "$pkg_dir$package" ] || [ "$1" = "md5sum" ] || { error "$package not found. Cannot check $1.";
return "$E_MANIFEST"; }
local FILTER CN CM
local TRUTH="$PKGMK_ROOT/.$1"; local retval=0; local severity=error;
[ -f "$pkg_dir$package" ] || [ "$1" = "md5sum" ] || \
{ error "$package not found. Cannot check $1."; return "$E_MANIFEST"; }
[ "$1" = "md5sum" ] && FILTER="-k 3" || FILTER=""
TRUTH="$PKGMK_ROOT/.$1"
if [ -f "$TRUTH" ]; then
diff -w -t -U 0 <(sort $FILTER "$TRUTH") <(cat_manifest $1 | sort $FILTER) | \
@ -438,8 +429,7 @@ check_manifest() {
else
retval=$E_MANIFEST
fi
$severity "$1 mismatch found:"
cat ".$1.diff" >&2
$severity "$1 mismatch found:"; cat ".$1.diff" >&2
fi
rm ".$1.diff"
else