2022-05-31 16:02:44 -04:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# pkgmeek - a drop-in replacement for pkgmk
|
|
|
|
# based on upkgmk (c) 2018 therealfun
|
|
|
|
# and pkgmk (c) 2004--2022 Per Liden et al.
|
|
|
|
# Distributed under the same license,
|
|
|
|
# https://crux.nu/gitweb/?p=tools/pkgutils.git;a=blob_plain;f=COPYING;hb=HEAD
|
|
|
|
|
|
|
|
main() {
|
|
|
|
######################## main routine ################################
|
2022-06-04 13:32:28 -04:00
|
|
|
local o_ignored pkg_dir src_dir work _local_ here url u f TARGET pkg_utd
|
|
|
|
local errDL=0; local errUZ=0;
|
2022-05-31 16:02:44 -04:00
|
|
|
parse_options "$@"
|
2022-06-03 18:14:35 -04:00
|
|
|
[ "$PKGMK_RECURSIVE" = "yes" ] && recursive "$@"
|
2022-05-31 16:02:44 -04:00
|
|
|
#
|
|
|
|
# Exit early if cleaning was requested
|
|
|
|
#
|
|
|
|
if [ "$PKGMK_CLEAN" = "yes" ]; then
|
2022-06-03 07:36:52 -04:00
|
|
|
[ "$PKGMK_MTIME_ONLY" = "yes" ] && o_ignored="'-utd' "
|
|
|
|
[ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] && o_ignored+="'-uf' "
|
|
|
|
[ "$PKGMK_CHECK_SIG" = "yes" ] && o_ignored+="'-cs' "
|
2022-05-31 16:02:44 -04:00
|
|
|
[ "$PKGMK_REFRESH_SIG" = "yes" ] && refresh_signature
|
|
|
|
[ "$o_ignored" = "" ] || { warning "option -c nullifies these requested options:";
|
2022-06-01 17:37:01 -04:00
|
|
|
info "$o_ignored"; }
|
2022-06-01 05:58:13 -04:00
|
|
|
exec $PRTWASH_COMMAND -p -s -q "$(pwd)"
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
|
|
|
#
|
|
|
|
# Read the Pkgfile to determine what to do next. But first ensure that
|
|
|
|
# it came from a trusted source (FS#1851)
|
|
|
|
#
|
2022-06-13 16:58:27 -04:00
|
|
|
[ "$PKGMK_UPDATE_SIG" = "yes" ] || validate_pkgfile || exit $E_PKGFILE
|
2022-05-31 16:02:44 -04:00
|
|
|
[ -f .32bit ] && PGKMK_ARCH=32 || PKGMK_ARCH=64
|
2022-06-15 13:24:04 -04:00
|
|
|
. "Pkgfile"; . "$PKGMK_CONF"
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-01 10:55:07 -04:00
|
|
|
# respect the settings for centralized source and package directories ...
|
2022-05-31 16:02:44 -04:00
|
|
|
[ -v pkg_dir ] || pkg_dir="$PKGMK_PACKAGE_DIR"/
|
|
|
|
[ -w "$pkg_dir" ] || pkg_dir="$(pwd)"/
|
|
|
|
[ -v src_dir ] || src_dir="$PKGMK_SOURCE_DIR"
|
|
|
|
[ -w "$src_dir" ] || src_dir=
|
|
|
|
|
2022-06-01 10:55:07 -04:00
|
|
|
# ... and for WORK_DIR in case the user wants to build in RAM
|
2022-05-31 16:02:44 -04:00
|
|
|
[ -v PKGMK_WORK_DIR ] && work="$PKGMK_WORK_DIR"
|
|
|
|
|
|
|
|
# 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}"
|
2022-06-02 07:13:52 -04:00
|
|
|
declare -a _local_
|
2022-05-31 16:02:44 -04:00
|
|
|
for (( s=0; s<${#source[@]}; s++ )); do
|
2022-06-12 15:38:35 -04:00
|
|
|
[[ ${source[$s]} =~ ^(http|https|ssh|ftp|git)://.*/(.+)$ ]] && \
|
|
|
|
_local_[$s]="${BASH_REMATCH[2]%.git*}" || _local_[$s]="${source[$s]}"
|
2022-05-31 16:02:44 -04:00
|
|
|
[ -z "${renames[$s]}" ] || [ "${renames[$s]}" = "SKIP" ] || \
|
|
|
|
_local_[$s]="${renames[$s]}"
|
|
|
|
done
|
2022-06-12 15:38:35 -04:00
|
|
|
# Example: source = ( https://gitlab.com/demo-user/cool-project.git#0.4.9
|
|
|
|
# https://dev.big-corp.com/src/needed-library.tgz
|
|
|
|
# random.patch )
|
|
|
|
# _local_ = ( cool-project
|
|
|
|
# needed-library.zgt <-- renamed to prevent automatic unpacking
|
|
|
|
# random.patch )
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
# The effective user should at least have write permissions on $PWD
|
|
|
|
[ -w "$(dirname "$work")" ] || work="$(pwd)"/work
|
|
|
|
rm -rf "$work"; mkdir -p "$work"/{src,pkg} && cd "$work"
|
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
# Skip the retrieval of sources if the user only asked for '-utd'
|
2022-06-03 10:31:12 -04:00
|
|
|
[ "$PKGMK_MTIME_ONLY" = "yes" ] || { for (( u=0; u<${#_local_[@]}; u++ )); do
|
2022-06-01 15:10:25 -04:00
|
|
|
here="${_local_[$u]}"; url="${source[$u]}";
|
2022-06-01 05:58:13 -04:00
|
|
|
# at least one of the following commands should put a file of the
|
|
|
|
# appropriate name in the current directory
|
2022-06-01 15:10:25 -04:00
|
|
|
[ -e "$here" ] || [ "$src_dir" = "" ] || [ ! -e "$src_dir/$here" ] || ln -sf "$src_dir/$here" ;
|
|
|
|
[ -e "$here" ] || [ ! -e "$PKGMK_ROOT/$here" ] || ln -sf "$PKGMK_ROOT/$here" . ;
|
2022-06-13 16:58:27 -04:00
|
|
|
[ -e "$here" ] || fetch_url "$url" "$here"; # <-- should also be able to resume partial downloads
|
2022-06-03 18:14:35 -04:00
|
|
|
[ -e "$here" ] || { error "failed to download $here. Check connection and try again."; errDL+=1; }
|
2022-06-01 15:10:25 -04:00
|
|
|
done ; }
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-03 12:11:53 -04:00
|
|
|
[ $errDL = 0 ] && { [ "$PKGMK_MTIME_ONLY" = "yes" ] || \
|
|
|
|
info "Successfully obtained all needed source files."; } || exit $E_DOWNLOAD
|
2022-06-01 10:55:07 -04:00
|
|
|
|
2022-06-15 17:42:11 -04:00
|
|
|
# Can stop here if the user asked for '-do', but honor any requests for '-um', '-uf',
|
|
|
|
# '-us', '-eo', or '-utd' by proceeding to those steps
|
2022-06-01 23:11:58 -04:00
|
|
|
[ "$PKGMK_DOWNLOAD_ONLY" = "no" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || \
|
|
|
|
[ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || \
|
2022-06-11 14:28:14 -04:00
|
|
|
[ "$PKGMK_EXTRACT_ONLY" = "yes" ] || [ "$PKGMK_MTIME_ONLY" = "yes" ] || exit 0
|
|
|
|
|
|
|
|
# If the user only asked for '-utd', perform the check using the sources that do exist.
|
|
|
|
check_pkg_mtime; pkg_utd=$?
|
2022-06-12 15:38:35 -04:00
|
|
|
[ "$PKGMK_MTIME_ONLY" = "no" ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || \
|
|
|
|
[ "$PKGMK_FORCE" = "yes" ] || exit $pkg_utd
|
2022-06-01 23:11:58 -04:00
|
|
|
|
|
|
|
# Take into account all the actions that can be done with a previously built package,
|
|
|
|
# or with a full set of sources
|
2022-06-02 11:03:36 -04:00
|
|
|
[ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] \
|
2022-06-02 07:13:52 -04:00
|
|
|
|| [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_CHECK_SIG" = "yes" ] \
|
|
|
|
|| [ "$PKGMK_UPDATE_MD5" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "yes" ] \
|
2022-06-01 17:37:01 -04:00
|
|
|
|| { info "$package is up to date, use '-f' to force a rebuild."; exit 0; }
|
2022-06-01 11:39:39 -04:00
|
|
|
|
|
|
|
# Silence the progress report if the user never intended to proceed with unpacking
|
2022-06-04 14:57:45 -04:00
|
|
|
[ "$pkg_utd" = 1 ] || [[ "$PKGMK_CHECK_SIG $PKGMK_UPDATE_SIG" =~ yes ]] || \
|
|
|
|
[[ "$PKGMK_UPDATE_FOOTPRINT $PKGMK_UPDATE_MD5" =~ yes ]] || \
|
|
|
|
echo "Checking signatures before unpacking..."
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
# 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
|
|
|
|
# to update the signature|md5sum, which only requires the sources and the footprint.
|
2022-05-31 16:02:44 -04:00
|
|
|
if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
|
2022-06-16 12:09:25 -04:00
|
|
|
[ -f "$pkg_dir$package" ] || \
|
2022-05-31 16:02:44 -04:00
|
|
|
{ error "unable to update footprint. File '$package' not found.";
|
|
|
|
exit "$E_MANIFEST"; }
|
2022-06-02 07:13:52 -04:00
|
|
|
[ "$pkg_utd" = 1 ] || [ "$PKGMK_FORCE" = "yes" ] || \
|
2022-05-31 16:02:44 -04:00
|
|
|
{ error "outdated package. Use '-f' to force the footprint update.";
|
2022-06-16 12:09:25 -04:00
|
|
|
exit "$E_MANIFEST"; }
|
|
|
|
cat_manifest footprint > "$PKGMK_ROOT/.footprint" && info "footprint created." \
|
|
|
|
|| { error "Failed to write the footprint."; exit "$E_DIRPERM"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2022-06-01 05:58:13 -04:00
|
|
|
[ "$PKGMK_UPDATE_SIG" = "no" ] || \
|
|
|
|
{ cat_signature > "$PKGMK_ROOT/.signature" &&
|
2022-06-01 08:31:21 -04:00
|
|
|
info "Signature successfully created."; } || \
|
2022-06-01 05:58:13 -04:00
|
|
|
{ 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" ] || \
|
2022-06-01 08:31:21 -04:00
|
|
|
{ cat_manifest md5sum > "$PKGMK_ROOT"/.md5sum && info "md5sum updated."; } || \
|
2022-06-01 05:58:13 -04:00
|
|
|
{ info "Could not create requested md5sums."; exit "$E_DIRPERM"; }
|
2022-06-01 08:31:21 -04:00
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
# Exit after fulfilling any *explicit* requests for (signed) manifests
|
|
|
|
# (decision regarding the work directory is retained from the first run of pkgmeek)
|
2022-06-03 10:31:12 -04:00
|
|
|
[ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || \
|
|
|
|
[ "$PKGMK_UPDATE_MD5" = "yes" ] && exit 0
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
# All the sources should be here by now, let's verify that we can trust them.
|
2022-06-01 05:58:13 -04:00
|
|
|
readonly cs_fail_msg="Use '--ignore-signature' to override, if you have determined integrity by other means."
|
2022-06-02 20:29:57 -04:00
|
|
|
[ "$PKGMK_IGNORE_SIG" = "yes" ] || { check_signature "pre-build" | parse_signify_output;
|
2022-05-31 16:02:44 -04:00
|
|
|
case $? in
|
|
|
|
0) info "Sources successfully authenticated." ;;
|
|
|
|
1) error "Signature file missing or corrupted." ; echo "$cs_fail_msg" ;;
|
|
|
|
2) error "Failed to authenticate remote sources using signify." ; echo "$cs_fail_msg" ;;
|
2022-06-01 05:58:13 -04:00
|
|
|
esac; }
|
2022-05-31 16:02:44 -04:00
|
|
|
[ "$PKGMK_CHECK_SIG" = "no" ] || exit 0 # no need to continue if the user only requested -cs
|
|
|
|
|
2022-06-12 15:38:35 -04:00
|
|
|
if [ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ]; then
|
2022-06-01 23:11:58 -04:00
|
|
|
for (( u=0; u<${#_local_[@]}; u++ )) ; do
|
2022-05-31 16:02:44 -04:00
|
|
|
here="${_local_[$u]}"
|
|
|
|
case "$here" in
|
2022-06-21 06:38:42 -04:00
|
|
|
*.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.tar.lz)
|
2022-06-17 14:57:33 -04:00
|
|
|
tar -C src --no-same-owner -paxf "$here" || errUZ+=1 ;;
|
2022-06-21 06:38:42 -04:00
|
|
|
*.7z|*.zip|*.rpm)
|
|
|
|
7z x -osrc "$here" || errUZ+=1 ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
*)
|
|
|
|
cp -r "$here" src/ ;;
|
|
|
|
esac
|
2022-06-01 23:11:58 -04:00
|
|
|
done
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-02 20:29:57 -04:00
|
|
|
[ $errUZ = 0 ] && info "Sources successfully unpacked." || \
|
2022-06-01 10:55:07 -04:00
|
|
|
{ error "Failed to unpack all sources."; exit "$E_UNPACK"; }
|
2022-06-01 23:11:58 -04:00
|
|
|
[ "$PKGMK_EXTRACT_ONLY" = "no" ] || exit 0
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-04 13:32:28 -04:00
|
|
|
# The actual build step! (use fakeroot when building daemon ports as an ordinary user,
|
|
|
|
# otherwise the owner and group might not be correct)
|
2022-06-15 13:24:04 -04:00
|
|
|
(SRC=$(pwd)/src; PKG=$(pwd)/pkg; cd src; set -e -x; build)
|
|
|
|
if [ $? = 0 ]; then
|
|
|
|
echo "Build successful. Moving on to compression."
|
|
|
|
else
|
|
|
|
error "Unsuccessful build!"; cleanup_work; exit "$E_BUILD"
|
|
|
|
fi
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-02 12:54:54 -04:00
|
|
|
[ -f "$PKGMK_ROOT/.nostrip" ] && ns_filter="| grep -v -f $PKGMK_ROOT/.nostrip"
|
2022-06-01 23:11:58 -04:00
|
|
|
find pkg -type f $ns_filter | while read -r f; do
|
|
|
|
case $(file -b "$f") in
|
2022-05-31 16:02:44 -04:00
|
|
|
*ELF*executable*not\ stripped*) strip --strip-all "$f" ;;
|
|
|
|
*ELF*shared\ object*not\ stripped*) strip --strip-unneeded "$f" ;;
|
|
|
|
current\ ar\ archive) strip --strip-debug "$f" ;;
|
2022-06-01 23:11:58 -04:00
|
|
|
esac
|
|
|
|
done
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-02 12:54:54 -04:00
|
|
|
find pkg -type f -path "*/man/man*/*" | grep -v '.gz$' | xargs -r -I{} gzip -9 '{}'
|
2022-06-04 13:32:28 -04:00
|
|
|
find pkg -xtype l -path "*/man/man*/*" | while read f; do
|
|
|
|
TARGET="$(basename -s .gz $(readlink -n $f)).gz"; DIR="$(dirname ${f%%.gz}.gz)";
|
|
|
|
rm -f $f; [ -e $DIR/$TARGET ] && ln -sf $TARGET ${f%%.gz}.gz
|
|
|
|
done
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-01 23:11:58 -04:00
|
|
|
[ $UID = 0 ] || fake_uid="--uid 0 --gid 0"
|
|
|
|
if (cd pkg; bsdtar --format=gnutar $fake_uid -cf "$pkg_dir$package" *); then
|
|
|
|
info "Package creation successful."
|
2022-06-03 07:36:52 -04:00
|
|
|
else
|
2022-06-15 17:42:11 -04:00
|
|
|
error "Unable to create the compressed package $package."
|
|
|
|
cleanup_work; exit "$E_BUILD"
|
2022-06-01 23:11:58 -04:00
|
|
|
fi
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-16 12:09:25 -04:00
|
|
|
# Check the footprint of the built package, unless '-if' was given
|
2022-06-15 13:24:04 -04:00
|
|
|
[ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ] || check_manifest footprint
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-03 18:14:35 -04:00
|
|
|
# Clean up the work directory
|
2022-06-03 07:36:52 -04:00
|
|
|
find . -maxdepth 1 -mindepth 1 -type l -delete; cleanup_work
|
2022-06-02 11:03:36 -04:00
|
|
|
fi # Continue from here if the extract and build were skipped
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-12 15:38:35 -04:00
|
|
|
# Install if requested. For non-root builds, only sudo and doas are supported.
|
|
|
|
# Avoid falling back on su -c! It gobbles up the options intended for pkgadd.
|
2022-06-01 20:05:15 -04:00
|
|
|
[ $UID = 0 ] || PKGMK_SU="sudo";
|
|
|
|
[ -z "$PKGMK_SU" ] || [ -x "$(command -v $PKGMK_SU)" ] || PKGMK_SU="/usr/bin/doas";
|
2022-06-12 15:38:35 -04:00
|
|
|
[ -z "$PKGMK_SU" ] || [ -x "$(command -v $PKGMK_SU)" ] \
|
|
|
|
|| { error "Cannot run pkgadd as a non-root user."; exit "$E_INSTALL"; }
|
2022-06-01 20:05:15 -04:00
|
|
|
|
|
|
|
[ -z "$PKGMK_INSTALL_COMMAND" ] || { $PKGMK_SU $PKGMK_INSTALL_COMMAND "$pkg_dir$package" \
|
|
|
|
&& info "$(basename $PKGMK_INSTALL_COMMAND) $package succeeded."; } || \
|
2022-06-12 15:38:35 -04:00
|
|
|
{ error "$(basename $PKGMK_INSTALL_COMMAND) $package failed."; exit "$E_INSTALL"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
# Done!
|
|
|
|
}
|
|
|
|
|
|
|
|
####################### error codes ##############################
|
|
|
|
E_PKGFILE=2 # invalid Pkgfile
|
2022-06-01 17:37:01 -04:00
|
|
|
E_DIRPERM=3 # (source/build) directory missing or missing read/write permission
|
2022-05-31 16:02:44 -04:00
|
|
|
E_DOWNLOAD=4 # error during download
|
|
|
|
E_UNPACK=5 # error during unpacking of source file(s)
|
2022-06-01 17:37:01 -04:00
|
|
|
E_MANIFEST=6 # footprint or md5sum failure
|
|
|
|
E_BUILD=7 # error while running 'build()'
|
|
|
|
E_INSTALL=8 # error while installing the package via 'pkgadd'
|
|
|
|
E_SIGNATURE=9 # error verifying the signature
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
######################## settings ################################
|
|
|
|
readonly PKGMK_VERSION="#VERSION#"
|
|
|
|
readonly PKGMK_COMMAND="$0"
|
|
|
|
readonly PKGMK_ROOT="$PWD"
|
|
|
|
readonly PRTWASH_COMMAND="/usr/bin/prtwash"
|
|
|
|
PKGMK_DOWNLOAD_PROG="/usr/bin/wget"
|
2022-06-12 15:38:35 -04:00
|
|
|
PKGMK_GIT_COMMAND="/usr/bin/git"
|
2022-05-31 16:02:44 -04:00
|
|
|
PKGMK_CONF="/etc/pkgmk.conf"
|
2022-06-12 15:38:35 -04:00
|
|
|
|
|
|
|
PKGMK_SOURCE_DIR="$PWD"; PKGMK_WORK_DIR="$PWD/work"
|
|
|
|
PKGMK_PACKAGE_DIR="$PWD"; PKGMK_COMPRESSION_MODE="gz"
|
|
|
|
|
|
|
|
PKGMK_INSTALL_COMMAND=""; PKGMK_FORCE="no"
|
|
|
|
PKGMK_CLEAN="no"; PKGMK_KEEP_WORK="no"
|
|
|
|
PKGMK_RECURSIVE="no"; PKGMK_UPDATE_MD5="no"
|
|
|
|
PKGMK_DOWNLOAD_ONLY="no"; PKGMK_IGNORE_MD5="no"
|
|
|
|
PKGMK_EXTRACT_ONLY="no"; PKGMK_UPDATE_SIG="no"
|
|
|
|
PKGMK_MTIME_ONLY="no"; PKGMK_IGNORE_SIG="no"
|
|
|
|
PKGMK_UPDATE_FOOTPRINT="no"; PKGMK_REFRESH_SIG="no"
|
|
|
|
PKGMK_IGNORE_FOOTPRINT="no"; PKGMK_CHECK_SIG="no"
|
|
|
|
PKGMK_IGNORE_NEW="no"; PKGMK_PRIVATEKEY=""
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
######################## subroutines ################################
|
|
|
|
parse_options() {
|
|
|
|
while [ "$1" ]; do
|
|
|
|
case $1 in
|
2022-06-01 10:55:07 -04:00
|
|
|
-r|--recursive) PKGMK_RECURSIVE="yes" ;;
|
2022-06-01 05:58:13 -04:00
|
|
|
-c|--clean) [ -x "$PRTWASH_COMMAND" ] && PKGMK_CLEAN="yes" || \
|
|
|
|
{ error "option '-c' not supported ($PRTWASH_COMMAND not installed)";
|
|
|
|
exit 1; } ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
-uf|--update-footprint) PKGMK_UPDATE_FOOTPRINT="yes" ;;
|
|
|
|
-um|--update-md5sum) PKGMK_UPDATE_MD5="yes" ;;
|
|
|
|
-us|--update-signature) PKGMK_UPDATE_SIG="yes" ;;
|
|
|
|
-rs|--refresh-signature) PKGMK_REFRESH_SIG="yes" ;;
|
|
|
|
-cs|--check-signature) PKGMK_CHECK_SIG="yes" ;;
|
2022-06-03 18:14:35 -04:00
|
|
|
-d|-cm|--download|--check-md5sum) ;; # deprecated flags, but at least they won't trigger an error
|
2022-05-31 16:02:44 -04:00
|
|
|
-do|--download-only) PKGMK_DOWNLOAD_ONLY="yes" ;;
|
|
|
|
-eo|--extract-only) PKGMK_EXTRACT_ONLY="yes" ;;
|
|
|
|
-utd|--up-to-date) PKGMK_MTIME_ONLY="yes" ;;
|
|
|
|
-if|--ignore-footprint) PKGMK_IGNORE_FOOTPRINT="yes" ;;
|
|
|
|
-in|--ignore-new) PKGMK_IGNORE_NEW="yes" ;;
|
|
|
|
-im|--ignore-md5sum) PKGMK_IGNORE_MD5="yes" ;;
|
|
|
|
-is|--ignore-signature) PKGMK_IGNORE_SIG="yes" ;;
|
2022-06-02 12:54:54 -04:00
|
|
|
-ns|--no-strip) echo ".*" >> "$PKGMK_ROOT/.nostrip" ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
-f|--force) PKGMK_FORCE="yes" ;;
|
|
|
|
-kw|--keep-work) PKGMK_KEEP_WORK="yes" ;;
|
|
|
|
-i|--install) PKGMK_INSTALL_COMMAND="/usr/bin/pkgadd" ;;
|
|
|
|
-u|--upgrade) PKGMK_INSTALL_COMMAND="/usr/bin/pkgadd -u" ;;
|
|
|
|
-pk|--public-key)
|
2022-06-03 07:36:52 -04:00
|
|
|
[ "$2" ] && PKGMK_PUBLICKEY="$2" || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument";
|
2022-06-01 23:11:58 -04:00
|
|
|
exit 1; }
|
2022-05-31 16:02:44 -04:00
|
|
|
shift ;;
|
|
|
|
-sk|--secret-key)
|
2022-06-03 07:36:52 -04:00
|
|
|
[ "$2" ] && PKGMK_PRIVATEKEY="$2" || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument";
|
2022-06-01 23:11:58 -04:00
|
|
|
exit 1; }
|
2022-05-31 16:02:44 -04:00
|
|
|
shift ;;
|
|
|
|
-cf|--config-file)
|
2022-06-03 18:14:35 -04:00
|
|
|
[ "$2" ] && PKGMK_CONF="$2" || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument";
|
2022-06-01 23:11:58 -04:00
|
|
|
exit 1; }
|
2022-05-31 16:02:44 -04:00
|
|
|
shift ;;
|
|
|
|
-v|--version)
|
2022-06-01 23:11:58 -04:00
|
|
|
echo "$(basename "$PKGMK_COMMAND") (pkgutils) $PKGMK_VERSION"; exit 0 ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
-h|--help)
|
2022-06-01 23:11:58 -04:00
|
|
|
print_help; exit 0 ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
*)
|
2022-06-01 23:11:58 -04:00
|
|
|
echo "$(basename "$PKGMK_COMMAND"): invalid option $1"; exit 1 ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
print_help() {
|
|
|
|
echo "usage: $(basename "$PKGMK_COMMAND") [options]"
|
|
|
|
echo "options: "
|
|
|
|
echo " -r, --recursive search for Pkgfiles under $PWD, and run $(basename "$PKGMK_COMMAND")"
|
|
|
|
echo " with the other given options inside each directory found"
|
|
|
|
echo " -c, --clean remove package and downloaded files"
|
|
|
|
echo " -i, --install build and install package"
|
|
|
|
echo " -u, --upgrade build and install package (as upgrade)"
|
|
|
|
echo " -do, --download-only stop after downloading all the necessary source file(s)"
|
|
|
|
echo " -eo, --extract-only stop after downloading and extracting source file(s)"
|
2022-06-01 05:58:13 -04:00
|
|
|
echo " -utd, --up-to-date report whether the built package is up to date, then exit"
|
|
|
|
echo " -um, --update-md5sum update md5sum of the downloaded sources, do not build"
|
|
|
|
echo " -us, --update-signature update signature of Pkgfile and sources, do not build"
|
|
|
|
echo " -cs, --check-signature verify the signatures, do not build"
|
2022-05-31 16:02:44 -04:00
|
|
|
echo " -if, --ignore-footprint build package without checking footprint"
|
|
|
|
echo " -in, --ignore-new build package, ignoring new files in a footprint mismatch"
|
|
|
|
echo " -im, --ignore-md5sum build package without checking md5sum"
|
2022-06-01 05:58:13 -04:00
|
|
|
echo " -is, --ignore-signature build package without checking signature"
|
|
|
|
echo " -uf, --update-footprint update footprint using result from last build"
|
2022-05-31 16:02:44 -04:00
|
|
|
echo " -rs, --refresh-signature create new signature and keep existing sha256 checksums"
|
|
|
|
echo " -sk, --secret-key <file> use <file> to sign the port"
|
|
|
|
echo " -pk, --public-key <file> check the port signature using public-key <file>"
|
|
|
|
echo " -ns, --no-strip do not strip executable binaries or libraries"
|
|
|
|
echo " -f, --force build package even if it appears to be up to date"
|
|
|
|
echo " -kw, --keep-work keep temporary working directory"
|
|
|
|
echo " -cf, --config-file <file> use alternative configuration file"
|
|
|
|
echo " -v, --version print version and exit"
|
|
|
|
echo " -h, --help print help and exit"
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_pkgfile() { # called from within PKGMK_ROOT
|
2022-06-02 11:03:36 -04:00
|
|
|
local errcode kv
|
2022-06-03 07:36:52 -04:00
|
|
|
[ -f Pkgfile ] || { error "no Pkgfile found. $PKGMK_ROOT is not a valid ports directory."; return "$E_PKGFILE"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
check_signature "pre-Pkgfile" | parse_signify_output
|
|
|
|
errcode=$?
|
2022-06-02 11:03:36 -04:00
|
|
|
[ "$errcode" = 0 ] || info "Use '-is' if you have independent confirmation of the port's integrity."
|
2022-06-01 08:31:21 -04:00
|
|
|
[ "$errcode" = 0 ] || [ "$PKGMK_IGNORE_SIG" = "yes" ] || return $E_SIGNATURE
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
# 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
|
2022-06-02 11:03:36 -04:00
|
|
|
( . Pkgfile; kv=0; [ -n "$name" ] || kv+=1; [ -n "$version" ] || kv+=2; \
|
|
|
|
[ -n "$release" ] || kv+=4; [ "$(type -t build)" = "function" ] || kv+=8; \
|
|
|
|
echo $kv ) | check_reqvars
|
2022-06-01 08:31:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
check_reqvars () {
|
2022-06-02 20:29:57 -04:00
|
|
|
local checksum nullvars;
|
2022-06-01 17:37:01 -04:00
|
|
|
read -r checksum
|
2022-06-02 20:29:57 -04:00
|
|
|
[ $((checksum & 1)) = 1 ] && nullvars=" 'name'"
|
|
|
|
[ $((checksum & 2)) = 2 ] && nullvars+=" 'version'"
|
|
|
|
[ $((checksum & 4)) = 4 ] && nullvars+=" 'release'"
|
|
|
|
[ $((checksum & 8)) = 8 ] && nullvars+=" 'build()'"
|
2022-06-01 08:31:21 -04:00
|
|
|
[ "$checksum" = 0 ] || { error "Pkgfile does not specify these required variables:"; \
|
2022-06-03 07:36:52 -04:00
|
|
|
info "$nullvars"; return "$E_PKGFILE"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
}
|
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
check_pkg_mtime() { # can be called even if some sources are missing
|
2022-06-02 11:03:36 -04:00
|
|
|
local li=0; local utd=0; local msg="$package is not up to date."
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-01 15:10:25 -04:00
|
|
|
if [ -f "$pkg_dir$package" ]; then
|
2022-06-02 05:59:01 -04:00
|
|
|
utd=1
|
|
|
|
while [ $li -lt ${#_local_[@]} ] && [ "$utd" = 1 ]; do
|
2022-06-01 11:33:35 -04:00
|
|
|
[ ! -e "${_local_[$li]}" ] || \
|
2022-06-16 12:09:25 -04:00
|
|
|
[ "$pkgdir$package" -nt $(realpath "${_local_[$li]}") ] || utd=0
|
2022-05-31 16:02:44 -04:00
|
|
|
li=$(( li+1 ))
|
|
|
|
done
|
2022-06-16 12:09:25 -04:00
|
|
|
[ ! -e Pkgfile ] || [ "$pkg_dir$package" -nt Pkgfile ] || utd=0
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
|
|
|
|
2022-06-02 11:03:36 -04:00
|
|
|
[ $utd = 0 ] || msg="$package is up to date."
|
2022-06-02 05:59:01 -04:00
|
|
|
info "$msg"; return $utd
|
2022-05-31 16:02:44 -04:00
|
|
|
}
|
|
|
|
|
2022-06-13 16:58:27 -04:00
|
|
|
fetch_url() {
|
2022-06-12 15:38:35 -04:00
|
|
|
local u="$1"; local h="$2"; local finished=0; local gitsrc tag CLONE_ARGS
|
|
|
|
local REPO SAVE_AS OCONTINUE OOUT; local m=0
|
2022-06-03 10:31:12 -04:00
|
|
|
[ -x "$PKGMK_GIT_COMMAND" ] || PKGMK_GIT_COMMAND="/bin/false"
|
2022-06-12 15:38:35 -04:00
|
|
|
|
|
|
|
# Is this a url that requires git?
|
|
|
|
if [[ $u =~ ^(https|http|ssh|git)://.*/(.+)\.git(.*)$ ]]; then
|
|
|
|
# Did the port maintainer specify a branch other than 'master'?
|
|
|
|
tag=${BASH_REMATCH[3]#\#}; gitsrc="${u%.git*}.git"
|
|
|
|
[ -z "$tag" ] || CLONE_ARGS="--branch $tag"
|
|
|
|
|
|
|
|
# If git is not installed, this source cannot be obtained at present
|
|
|
|
[ "$PKGMK_GIT_COMMAND" != "/bin/false" ] || return 1;
|
|
|
|
|
|
|
|
# Is it our first attempt to download this repository?
|
|
|
|
if [ ! -d "$src_dir/$h.partial" ]; then
|
|
|
|
"$PKGMK_GIT_COMMAND" clone "$gitsrc" $CLONE_ARGS "$h.partial"
|
|
|
|
finished=$?
|
2022-06-12 07:25:41 -04:00
|
|
|
[ "$src_dir" = "" ] || { mv "$h.partial" "$src_dir";
|
2022-06-12 15:38:35 -04:00
|
|
|
ln -s "$src_dir/$h.partial" "$h"; }
|
|
|
|
else
|
|
|
|
ln -s "$src_dir/$h.partial" "$h"; cd "$h"
|
|
|
|
"$PKGMK_GIT_COMMAND" pull $gitsrc $tag
|
|
|
|
finished=$?; cd ..
|
|
|
|
fi
|
2022-06-12 07:25:41 -04:00
|
|
|
return $finished;
|
|
|
|
fi
|
2022-06-03 10:31:12 -04:00
|
|
|
|
2022-06-12 15:38:35 -04:00
|
|
|
# haven't returned yet, so a different transport protocol must be in effect
|
2022-06-03 11:41:44 -04:00
|
|
|
[[ "$PKGMK_DOWNLOAD_PROG" =~ wget$ ]] && { OCONTINUE="-c"; OOUT="$PKGMK_WGET_OPTIONS -O"; }
|
|
|
|
[[ "$PKGMK_DOWNLOAD_PROG" =~ curl$ ]] && { OCONTINUE="-C -"; OOUT="$PKGMK_CURL_OPTIONS -o"; }
|
2022-06-03 10:31:12 -04:00
|
|
|
[[ "$PKGMK_DOWNLOAD_PROG" =~ (wget|curl)$ ]] || SAVE_AS=/bin/false
|
|
|
|
|
2022-06-12 15:38:35 -04:00
|
|
|
# start with the mirrors defined in pkgmk.conf, then go to the url found in the Pkgfile
|
|
|
|
while [ $m -le ${#PKGMK_SOURCE_MIRRORS[@]} ] && [ $finished = 0 ] && [[ ! $SAVE_AS =~ false$ ]]; do
|
2022-06-03 11:41:44 -04:00
|
|
|
[ "${PKGMK_SOURCE_MIRRORS[m]}" = "" ] && um=$u || \
|
|
|
|
{ REPO=$(echo ${PKGMK_SOURCE_MIRRORS[m]} | sed 's,/$,,');
|
|
|
|
um=$REPO/$(echo $u | sed 's,.*/,,'); }
|
2022-06-12 15:38:35 -04:00
|
|
|
m=$(( m+1 ))
|
2022-06-03 11:41:44 -04:00
|
|
|
|
2022-06-03 18:14:35 -04:00
|
|
|
# interrupted downloads from a previous run should be put where wget or curl will find them
|
2022-06-13 16:58:27 -04:00
|
|
|
[ -f "$src_dir/$h.partial" ] && { ln -s "$src_dir/$h.partial" . ;
|
2022-06-03 11:41:44 -04:00
|
|
|
SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OCONTINUE $OOUT"; } \
|
|
|
|
|| SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OOUT"
|
|
|
|
|
|
|
|
if $SAVE_AS "$h.partial"; then
|
|
|
|
finished=1
|
2022-06-13 16:58:27 -04:00
|
|
|
[ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] || \
|
|
|
|
{ mv "$h.partial" "$src_dir/$h"; ln -sf "$src_dir/$h" . ; }
|
2022-06-03 11:41:44 -04:00
|
|
|
else # an interrupted download should not have its efforts destroyed by cleanup_work()
|
2022-06-13 16:58:27 -04:00
|
|
|
[ ! -s "$h.partial" ] || [ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] \
|
2022-06-03 11:41:44 -04:00
|
|
|
|| mv "$h.partial" "$src_dir"
|
|
|
|
fi
|
|
|
|
done
|
2022-06-03 10:31:12 -04:00
|
|
|
}
|
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
cat_manifest() {
|
2022-05-31 16:02:44 -04:00
|
|
|
case "$1" in
|
|
|
|
footprint)
|
2022-06-16 12:09:25 -04:00
|
|
|
pkginfo --footprint "$pkg_dir$package" \
|
2022-05-31 16:02:44 -04:00
|
|
|
| sed "s|\tlib/modules/$(uname -r)/|\tlib/modules/<kernel-version>/|g" \
|
|
|
|
| sort -k 3
|
|
|
|
;;
|
|
|
|
md5sum)
|
|
|
|
md5sum "${_local_[@]}" 2>&1 \
|
|
|
|
| grep -v "is a directory" | sed 's, .*/, ,' | sort -k 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
check_manifest() {
|
2022-06-11 09:23:07 -04:00
|
|
|
local FILTER CN CM
|
2022-06-15 13:24:04 -04:00
|
|
|
local TRUTH="$PKGMK_ROOT/.$1"; local diffs=0; local severity=error;
|
2022-06-03 18:14:35 -04:00
|
|
|
[ -f "$pkg_dir$package" ] || [ "$1" = "md5sum" ] || \
|
2022-06-15 13:24:04 -04:00
|
|
|
{ error "$package not found. Cannot check $1."; exit "$E_MANIFEST"; }
|
2022-06-03 07:36:52 -04:00
|
|
|
[ "$1" = "md5sum" ] && FILTER="-k 3" || FILTER=""
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
if [ -f "$TRUTH" ]; then
|
2022-06-03 08:55:25 -04:00
|
|
|
diff -w -t -U 0 <(sort $FILTER "$TRUTH") <(cat_manifest $1 | sort $FILTER) | \
|
|
|
|
sed '/^@@/d; /^+++/d; /^---/d; s/^+/NEW /g; s/^-/MISSING /g' > ".$1.diff"
|
|
|
|
if [ -s ".$1.diff" ]; then
|
2022-06-11 09:23:07 -04:00
|
|
|
CN=$(grep -c ^NEW ".$1.diff"); CM=$(grep -c ^MISSING ".$1.diff")
|
2022-05-31 16:02:44 -04:00
|
|
|
if [ "$1" = "footprint" ]; then
|
2022-06-15 13:24:04 -04:00
|
|
|
[ "$PKGMK_IGNORE_MISSING" = "yes" ] || diffs=$CM
|
|
|
|
[ "$PKGMK_IGNORE_NEW" = "yes" ] || diffs=$(( diffs+CN ))
|
|
|
|
[ $diffs = 0 ] && severity=warning
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2022-06-03 18:14:35 -04:00
|
|
|
$severity "$1 mismatch found:"; cat ".$1.diff" >&2
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2022-06-03 08:55:25 -04:00
|
|
|
rm ".$1.diff"
|
2022-05-31 16:02:44 -04:00
|
|
|
else
|
2022-06-03 07:36:52 -04:00
|
|
|
warning ".$1 not found, creating new."; cat_manifest $1 > "$TRUTH"
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2022-06-15 13:24:04 -04:00
|
|
|
[ $diffs = 0 ] || exit $E_MANIFEST
|
2022-05-31 16:02:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
parse_signify_output() { # chomps the output of check_signature()
|
|
|
|
local signout signerr
|
|
|
|
[ "$PKGMK_IGNORE_SIG" = "yes" ] && return 0
|
|
|
|
while read -r signout; do
|
|
|
|
case "$signout" in
|
2022-06-01 05:58:13 -04:00
|
|
|
*"Pkgfile verification failed")
|
|
|
|
signerr=-1; error "Signature missing! Unable to authenticate the Pkgfile."
|
|
|
|
;;
|
2022-05-31 16:02:44 -04:00
|
|
|
*"verification failed")
|
2022-06-01 05:58:13 -04:00
|
|
|
signerr=1; error "Signature file corrupted or unreadable."
|
2022-05-31 16:02:44 -04:00
|
|
|
;;
|
|
|
|
*"FAIL")
|
2022-06-01 05:58:13 -04:00
|
|
|
signerr=2; error "Signature mismatch found:"
|
2022-05-31 16:02:44 -04:00
|
|
|
echo "$signout" | awk -F: '/FAIL/ {printf "MISMATCH %s\n", $1}'
|
|
|
|
;;
|
2022-06-01 19:45:19 -04:00
|
|
|
*"OK") signerr=0 ;;
|
2022-05-31 16:02:44 -04:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
return $signerr
|
|
|
|
}
|
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
check_signature() { # called from $PKGMK_ROOT in the case "when"="pre-Pkgfile",
|
2022-06-01 19:45:19 -04:00
|
|
|
# otherwise called from within $work. Pass control to
|
|
|
|
# check_manifest() if the signature is missing and "ignore-md5"
|
|
|
|
# has not been requested.
|
2022-06-12 15:38:35 -04:00
|
|
|
local reqfiles=(Pkgfile); local s=0; local when="$1";
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
if [ -f "$PKGMK_ROOT/.signature" ]; then
|
2022-06-02 11:03:36 -04:00
|
|
|
[ "$when" = "pre-Pkgfile" ] || reqfiles=(.footprint)
|
2022-06-01 19:45:19 -04:00
|
|
|
while [ "$when" = "pre-build" ] && [ "$s" -lt ${#_local_[@]} ]; do
|
2022-06-12 15:38:35 -04:00
|
|
|
[[ "${source[$s]}" =~ ^(http|https|ssh|git)://(.+)\.git ]] || \
|
2022-06-01 19:45:19 -04:00
|
|
|
reqfiles+=("${_local_[$s]}")
|
2022-05-31 16:02:44 -04:00
|
|
|
s=$(( s+1 ))
|
|
|
|
done
|
2022-06-01 19:45:19 -04:00
|
|
|
for FILE in "${reqfiles[@]}"; do
|
2022-05-31 16:02:44 -04:00
|
|
|
[ -e "$FILE" ] || ln -sf "$PKGMK_ROOT/$FILE" .
|
|
|
|
done
|
|
|
|
if [ -f "$PKGMK_PUBLICKEY" ]; then
|
2022-06-02 05:59:01 -04:00
|
|
|
/usr/bin/signify -C -p "$PKGMK_PUBLICKEY" -x "$PKGMK_ROOT/.signature" \
|
2022-05-31 16:02:44 -04:00
|
|
|
"${reqfiles[@]}" 2>&1
|
|
|
|
else
|
2022-06-02 05:59:01 -04:00
|
|
|
/usr/bin/signify -C -x "$PKGMK_ROOT/.signature" \
|
2022-05-31 16:02:44 -04:00
|
|
|
"${reqfiles[@]}" 2>&1
|
|
|
|
fi
|
|
|
|
else
|
2022-06-01 05:58:13 -04:00
|
|
|
[ "$when" != "pre-Pkgfile" ] || echo "Pkgfile verification failed"
|
2022-05-31 16:02:44 -04:00
|
|
|
[ "$when" = "pre-Pkgfile" ] || [ "$PKGMK_IGNORE_MD5" = "yes" ] || \
|
|
|
|
{ info "Signature not found, falling back to old md5sum checking.";
|
2022-06-01 05:58:13 -04:00
|
|
|
check_manifest md5sum ; }
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-06-01 05:58:13 -04:00
|
|
|
cat_signature() {
|
2022-06-01 20:16:15 -04:00
|
|
|
local ordered si key pub
|
2022-06-01 17:37:01 -04:00
|
|
|
[ -e "$PKGMK_ROOT/.footprint" ] || warning "Footprint not found, signature will be incomplete."
|
2022-05-31 16:02:44 -04:00
|
|
|
for key in ~/.ssh/*.sec /etc/ports/*.sec; do
|
2022-06-01 17:37:01 -04:00
|
|
|
[ -e "$key" ] || continue # workaround for brain-dead shell globbing
|
2022-05-31 16:02:44 -04:00
|
|
|
pub=/etc/ports/$(basename "${key/%.sec/.pub}")
|
|
|
|
if [ -e "$pub" ]; then
|
|
|
|
pub=$(readlink -f "$pub")
|
2022-06-01 17:37:01 -04:00
|
|
|
for f in "$PKGMK_ROOT/Pkgfile" "$PKGMK_ROOT/.footprint"; do
|
|
|
|
[ -e $f ] && ordered+=( "$f" )
|
|
|
|
done
|
2022-06-13 16:58:27 -04:00
|
|
|
for ((si=0; si < ${#source[@]}; si++)); do
|
|
|
|
[[ ${source[$si]} =~ ^(http|https|ssh|git)://.+/.+\.git($|#.*) ]] || ordered+=("${_local_[$si]}"); done
|
2022-06-01 20:16:15 -04:00
|
|
|
sha256sum --tag "${ordered[@]}" \
|
2022-05-31 16:02:44 -04:00
|
|
|
| sed 's|^SHA256 (.*/\(.*\))\(.* = .*\)|SHA256 (\1)\2|' \
|
2022-06-02 05:59:01 -04:00
|
|
|
| /usr/bin/signify -S -e -x - -q -s "$key" -m - \
|
2022-05-31 16:02:44 -04:00
|
|
|
| sed "s|${key/%.sec/.pub}|$pub|"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh_signature() {
|
|
|
|
if [ -e ".signature" ] && [ ! -w ".signature" ]; then
|
2022-06-01 05:58:13 -04:00
|
|
|
echo "error: .signature not writable."; return $E_DIRPERM
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
local REPO
|
|
|
|
[ -n "$PKGMK_PRIVATEKEY" ] || REPO=$(dirname "$PWD" | sed 's|^.*/||; s|\.git$||;')
|
|
|
|
[ -n "$REPO" ] && PKGMK_PRIVATEKEY="/etc/ports/${REPO}.sec"
|
|
|
|
|
2022-06-02 05:59:01 -04:00
|
|
|
if ! tail -n +3 ".signature" | /usr/bin/signify -S -e -x - -q \
|
2022-05-31 16:02:44 -04:00
|
|
|
-s "$PKGMK_PRIVATEKEY" -m - > .signature.tmp ; then
|
|
|
|
rm .signature.tmp
|
|
|
|
error "Refreshing signature failed"
|
|
|
|
return $E_SIGNATURE
|
|
|
|
else
|
|
|
|
mv .signature.tmp .signature
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-06-16 16:18:58 -04:00
|
|
|
interrupted() {
|
|
|
|
error "Interrupted."; cleanup_work; exit 1
|
|
|
|
}
|
|
|
|
|
2022-06-03 07:36:52 -04:00
|
|
|
cleanup_work() {
|
|
|
|
[ "$PKGMK_KEEP_WORK" = "yes" ] || { cd "$PKGMK_ROOT"; rm -rf "$work"; }
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:02:44 -04:00
|
|
|
recursive() {
|
2022-06-01 10:55:07 -04:00
|
|
|
local ARGS DIR FILE
|
2022-06-01 17:37:01 -04:00
|
|
|
[ "$PKGMK_CLEAN" = "no" ] || { find "$PKGMK_ROOT" -name Pkgfile -printf "%h\n" \
|
2022-06-01 05:58:13 -04:00
|
|
|
| xargs "$PRTWASH_COMMAND" -s -p -b -q; exit $? ; }
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-01 08:31:21 -04:00
|
|
|
ARGS=$(echo "$@" | sed "s/--recursive//g; s/\s*-r\s*/ /g")
|
2022-06-01 10:55:07 -04:00
|
|
|
for FILE in $(find "$PKGMK_ROOT" -name Pkgfile | sort); do
|
|
|
|
DIR=$(dirname "$FILE")
|
|
|
|
[ -d $DIR ] && { info "Entering directory '$DIR'.";
|
|
|
|
(cd "$DIR" && "$PKGMK_COMMAND" $ARGS);
|
|
|
|
info "Leaving directory '$DIR'."; }
|
2022-05-31 16:02:44 -04:00
|
|
|
done
|
2022-06-01 08:31:21 -04:00
|
|
|
exit
|
2022-05-31 16:02:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
info() {
|
|
|
|
echo "=======> $1"
|
|
|
|
}
|
|
|
|
|
|
|
|
warning() {
|
|
|
|
info "WARNING: $1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
info "ERROR: $1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
######################## end of subroutines ###########################
|
|
|
|
## Now ensure that they cannot be overwritten when sourcing Pkgfile ##
|
2022-06-03 07:36:52 -04:00
|
|
|
readonly -f main info warning error print_help parse_options validate_pkgfile \
|
2022-06-13 16:58:27 -04:00
|
|
|
check_reqvars check_pkg_mtime fetch_url cat_manifest check_manifest \
|
2022-06-03 10:31:12 -04:00
|
|
|
cat_signature check_signature parse_signify_output refresh_signature \
|
|
|
|
cleanup_work recursive
|
2022-06-16 16:18:58 -04:00
|
|
|
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
main "$@"
|