pkgmeek: bugfix for the recursive() subroutine

This commit is contained in:
John McQuah 2022-06-01 08:31:21 -04:00
parent ea0e1fc63e
commit bb5937463f

View File

@ -26,7 +26,7 @@ fi
# Read the Pkgfile to determine what to do next. But first ensure that
# it came from a trusted source (FS#1851)
#
validate_pkgfile
validate_pkgfile || exit $E_PKGFILE
[ -f .32bit ] && PGKMK_ARCH=32 || PKGMK_ARCH=64
. "Pkgfile"; . "$PKGMK_CONF"
@ -88,12 +88,12 @@ done; }
check_pkg_mtime && pkg_ood=0 || pkg_ood=1
[ "$PKGMK_MTIME_ONLY" = "no" ] || exit $pkg_ood
# If the user did NOT ask for '-utd' or '-do', then all sources must be present.
{ [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ] || [ "$errDL" ] ; } && exit $(( E_DOWNLOAD*(errDL>0) ))
[ "$PKGMK_DOWNLOAD_ONLY" = "yes" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] \
|| [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] \
|| [ $errDL -gt 0 ] || exit $(( E_DOWNLOAD*(errDL > 0) ))
# Some further tests before proceeding with the build
[ "$pkg_ood" = 1 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || \
[ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || exit 0
[ "$pkg_ood" = 1 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || exit 0
[ "$PKGMK_CHECK_SIG" = "yes" ] || echo "Checking signatures before unpacking..."
# The option -uf is meant to be used AFTER a previous invocation of pkgmeek has
@ -111,13 +111,14 @@ if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
fi
[ "$PKGMK_UPDATE_SIG" = "no" ] || \
{ cat_signature > "$PKGMK_ROOT/.signature" &&
echo "Signature successfully created."; } || \
info "Signature successfully created."; } || \
{ cat_manifest md5sum > "$PKGMK_ROOT"/.md5sum &&
warning "Signature creation failed, falling back to md5sums."; } \
|| { info "Could not create signatures or md5sums."; exit "$E_DIRPERM"; }
[ "$PKGMK_UPDATE_MD5" = "no" ] || \
cat_manifest md5sum >"$PKGMK_ROOT"/.md5sum || \
{ cat_manifest md5sum > "$PKGMK_ROOT"/.md5sum && info "md5sum updated."; } || \
{ info "Could not create requested md5sums."; exit "$E_DIRPERM"; }
# Exit after fulfilling any *explicit* requests for (signed) manifests
# (decision regarding the work directory is retained from the first run of pkgmeek)
if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || \
@ -233,6 +234,7 @@ PKGMK_WORK_DIR="$PWD/work"
PKGMK_COMPRESSION_MODE="gz"
PKGMK_INSTALL_COMMAND=""
PKGMK_CLEAN="no"
PKGMK_DOWNLOAD_ONLY="no"
PKGMK_EXTRACT_ONLY="no"
PKGMK_MTIME_ONLY="no"
@ -255,7 +257,7 @@ parse_options() {
ARGV=( "$@" ) # retain all arguments in case '-r' was not the first
while [ "$1" ]; do
case $1 in
-r|--recursive) recursive "${ARGV[@]}" ;;
-r|--recursive) recursive ${ARGV[@]} ;;
-c|--clean) [ -x "$PRTWASH_COMMAND" ] && PKGMK_CLEAN="yes" || \
{ error "option '-c' not supported ($PRTWASH_COMMAND not installed)";
exit 1; } ;;
@ -347,20 +349,24 @@ validate_pkgfile() { # called from within PKGMK_ROOT
check_signature "pre-Pkgfile" | parse_signify_output
errcode=$?
[ "$errcode" = 0 ] || info "Use '-is' if you have confirmed its origin some other way."
[ "$errcode" = 0 ] || [ "$PKGMK_IGNORE_SIG" = "yes" ] || exit $E_SIGNATURE
[ "$errcode" = 0 ] || [ "$PKGMK_IGNORE_SIG" = "yes" ] || return $E_SIGNATURE
# the environment should not be affected by sourcing the Pkgfile both here
# and in the later build, but to be safe we use a nested subshell
( . Pkgfile; [ -n "$name" ] || nn=1; [ -n "$version" ] || nv=1; \
[ -n "$release" ] || nr=1; [ "$(type -t build)" = "function" ] || nb=1; \
echo $(( nn+2*nv+4*nr+8*nb )) ) | { read -r checksum;
[ $((checksum & 1)) = 1 ] && absent=" 'name'";
[ $((checksum & 2)) = 2 ] && absent+=" 'version'";
[ $((checksum & 4)) = 4 ] && absent+=" 'release'";
[ $((checksum & 8)) = 8 ] && absent+=" 'build()'";
[ "$checksum" = 0 ] ||
{ error "Pkgfile does not specify these required variables:";
info "$absent"; exit "$E_PKGFILE"; }; }
echo $(( nn+2*nv+4*nr+8*nb )) ) | check_reqvars
}
check_reqvars () {
local checksum
read -r checksum;
[ $((checksum & 1)) = 1 ] && absent=" 'name'"
[ $((checksum & 2)) = 2 ] && absent+=" 'version'"
[ $((checksum & 4)) = 4 ] && absent+=" 'release'"
[ $((checksum & 8)) = 8 ] && absent+=" 'build()'"
[ "$checksum" = 0 ] || { error "Pkgfile does not specify these required variables:"; \
info "$absent"; exit "$E_PKGFILE"; }
}
check_pkg_mtime() { # can be called even if some sources are missing
@ -521,19 +527,19 @@ refresh_signature() {
}
recursive() {
local ARGS FILE DIR
local ARGS DIR
[ "$PKGMK_CLEAN" == "no" ] || { find "$PKGMK_ROOT" -name Pkgfile -printf "%h\n" \
| xargs "$PRTWASH_COMMAND" -s -p -b -q; exit $? ; }
ARGS=$(echo "$@" | sed -e "s/--recursive//g; s/[ ]+-r[ ]+/ /g")
for FILE in $(find "$PKGMK_ROOT" -name Pkgfile | sort); do
DIR="$(dirname "$FILE")/"
if [ -d "$DIR" ]; then
ARGS=$(echo "$@" | sed "s/--recursive//g; s/\s*-r\s*/ /g")
for DIR in $(find "$PKGMK_ROOT" -type d | sort); do
if [ -f "$DIR/Pkgfile" ]; then
info "Entering directory '$DIR'."
(cd "$DIR" && "$PKGMK_COMMAND" "$ARGS")
(cd "$DIR" && "$PKGMK_COMMAND" $ARGS)
info "Leaving directory '$DIR'."
fi
done
exit
}
info() {
@ -550,8 +556,8 @@ error() {
######################## end of subroutines ###########################
## Now ensure that they cannot be overwritten when sourcing Pkgfile ##
readonly -f main parse_options print_help validate_pkgfile check_pkg_mtime \
cat_manifest check_manifest cat_signature check_signature \
parse_signify_output refresh_signature recursive
readonly -f main info warning error print_help parse_options recursive \
validate_pkgfile check_reqvars check_pkg_mtime cat_manifest check_manifest \
cat_signature check_signature parse_signify_output refresh_signature
main "$@"