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