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 ################################
|
2023-02-17 08:54:10 -05:00
|
|
|
local pkg_dir src_dir work _local_ here url u f DIR TARGET pkg_utd
|
2022-06-04 13:32:28 -04:00
|
|
|
local errDL=0; local errUZ=0;
|
2022-05-31 16:02:44 -04:00
|
|
|
parse_options "$@"
|
2023-02-17 08:54:10 -05:00
|
|
|
|
|
|
|
# Exit early if refreshing an existing sha256 manifest was requested
|
|
|
|
[ "$PKGMK_REFRESH_SIG" = "yes" ] && { refresh_signature; exit $?; }
|
2022-05-31 16:02:44 -04:00
|
|
|
#
|
|
|
|
# Read the Pkgfile to determine what to do next. But first ensure that
|
|
|
|
# it came from a trusted source (FS#1851)
|
|
|
|
#
|
2022-08-25 10:29:20 -04:00
|
|
|
[ "$PKGMK_UPDATE_SIG" = "yes" ] && [ -e ./Pkgfile ] || validate_pkgfile || exit $E_PKGFILE
|
2022-09-30 20:44:44 -04:00
|
|
|
[ -f .32bit ] && PKGMK_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
|
2023-02-17 08:54:10 -05:00
|
|
|
case "${source[s]}" in
|
2022-11-24 14:42:02 -05:00
|
|
|
http://*|https://*|ftp://*|__git__*)
|
2023-02-17 08:54:10 -05:00
|
|
|
_local_[s]="${source[s]##*/}" # strip the leading path
|
2022-11-24 14:42:02 -05:00
|
|
|
# and for git sources, extract the project name:
|
2023-02-17 08:54:10 -05:00
|
|
|
[[ "${source[s]}" =~ ^__git__ ]] && { _local_[s]="${_local_[s]%\#*}";
|
|
|
|
_local_[s]="${_local_[s]%.git}"; } ;;
|
2022-11-24 14:42:02 -05:00
|
|
|
*)
|
2023-02-17 08:54:10 -05:00
|
|
|
_local_[s]="${source[s]}" ;;
|
2022-11-24 14:42:02 -05:00
|
|
|
esac
|
2023-02-17 08:54:10 -05:00
|
|
|
[ -z "${renames[s]}" ] || [ "${renames[s]}" = "SKIP" ] || \
|
|
|
|
_local_[s]="${renames[s]}"
|
2022-05-31 16:02:44 -04:00
|
|
|
done
|
2022-11-24 14:42:02 -05:00
|
|
|
# Example: source = ( __git__https://gitlab.com/demo-user/cool-project.git#0.4.9
|
2022-06-12 15:38:35 -04:00
|
|
|
# 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-11-27 07:41:38 -05:00
|
|
|
# Skip the retrieval of sources if the user asked for '-utd' or '-uf'.
|
|
|
|
[[ "$PKGMK_MTIME_ONLY $PKGMK_UPDATE_FOOTPRINT" =~ yes ]] && [ -e "$PKGMK_PACKAGE_DIR/$package" ] \
|
|
|
|
|| { 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
|
2023-02-16 18:14:27 -05: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-11-27 07:41:38 -05:00
|
|
|
[ $errDL = 0 ] && { [[ "$PKGMK_MTIME_ONLY $PKGMK_UPDATE_FOOTPRINT" =~ yes ]] || \
|
2022-06-03 12:11:53 -04:00
|
|
|
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-11-24 14:42:02 -05:00
|
|
|
[ "$PKGMK_DOWNLOAD_ONLY" = "no" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] \
|
|
|
|
|| [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "yes" ] \
|
2022-12-23 13:38:40 -05:00
|
|
|
|| [ "$PKGMK_MTIME_ONLY" = "yes" ] || { cleanup_work; exit 0; }
|
2022-06-11 14:28:14 -04:00
|
|
|
|
2022-11-27 07:41:38 -05:00
|
|
|
# If '-utd' was requested, check the modification times and then exit.
|
2022-06-11 14:28:14 -04:00
|
|
|
check_pkg_mtime; pkg_utd=$?
|
2022-06-12 15:38:35 -04:00
|
|
|
[ "$PKGMK_MTIME_ONLY" = "no" ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || \
|
2022-11-24 14:42:02 -05:00
|
|
|
[ "$PKGMK_FORCE" = "yes" ] || { cleanup_work; exit $pkg_utd; }
|
2022-06-01 23:11:58 -04:00
|
|
|
|
2022-11-27 07:41:38 -05:00
|
|
|
# Take into account all the actions that can be done without extracting
|
|
|
|
# the downloaded sources
|
2022-11-24 14:42:02 -05:00
|
|
|
[ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "yes" ] \
|
|
|
|
|| [[ "$PKGMK_UPDATE_FOOTPRINT $PKGMK_CHECK_SIG $PKGMK_UPDATE_SIG" =~ yes ]] \
|
|
|
|
|| { info "$package is up to date, use '-f' to force a rebuild."; cleanup_work; 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 ]] || \
|
2022-11-24 14:42:02 -05:00
|
|
|
[[ "$PKGMK_IGNORE_SIG $PKGMK_UPDATE_FOOTPRINT" =~ yes ]] \
|
|
|
|
|| echo "Checking signatures before unpacking..."
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-11-27 07:41:38 -05:00
|
|
|
# The option -uf is meant to be used *after* a previous invocation of pkgmeek has
|
|
|
|
# alerted the user to a footprint mismatch.
|
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.";
|
2022-11-24 14:42:02 -05:00
|
|
|
exit "$E_FOOTPRINT"; }
|
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-11-24 14:42:02 -05:00
|
|
|
exit "$E_FOOTPRINT"; }
|
|
|
|
cat_footprint > "$PKGMK_ROOT/.footprint" && info "footprint created." \
|
2022-12-23 13:38:40 -05:00
|
|
|
|| { error "Failed to write the footprint."; cleanup_work; exit "$E_DIRPERM"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2022-11-27 07:41:38 -05:00
|
|
|
# Updating signatures (option -us) requires only sources and footprint, not a built package.
|
2022-11-24 14:42:02 -05:00
|
|
|
if [ "$PKGMK_UPDATE_SIG" = "yes" ]; then
|
|
|
|
cat_signature > "$PKGMK_ROOT/.signature" && info "Signature successfully created." \
|
2022-12-23 13:38:40 -05:00
|
|
|
|| { info "Could not create signature."; cleanup_work; exit "$E_DIRPERM"; }
|
2022-11-24 14:42:02 -05:00
|
|
|
fi
|
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
|
2022-11-24 14:42:02 -05:00
|
|
|
[[ "$PKGMK_UPDATE_FOOTPRINT $PKGMK_UPDATE_SIG" =~ yes ]] && { cleanup_work; 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." ;;
|
2022-12-23 13:38:40 -05:00
|
|
|
1) error "Signature file missing or corrupted."
|
|
|
|
echo "$cs_fail_msg" ; cleanup_work; exit $E_SIGNATURE ;;
|
|
|
|
2) error "Failed to authenticate remote sources using signify."
|
|
|
|
echo "$cs_fail_msg" ; cleanup_work; exit $E_SIGNATURE ;;
|
2022-06-01 05:58:13 -04:00
|
|
|
esac; }
|
2022-11-24 14:42:02 -05:00
|
|
|
[ "$PKGMK_CHECK_SIG" = "no" ] || { cleanup_work; exit 0; } # no need to continue if the user only requested -cs
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-12 15:38:35 -04:00
|
|
|
if [ "$pkg_utd" = 0 ] || [ "$PKGMK_FORCE" = "yes" ]; then
|
2023-02-17 08:54:10 -05:00
|
|
|
if [ "$(type -t unpack_source)" = "function" ]; then
|
|
|
|
SRC=$PWD/src unpack_source || errUZ+=1
|
2023-01-17 07:25:41 -05:00
|
|
|
else
|
2023-02-17 08:54:10 -05:00
|
|
|
for (( u=0; u<${#_local_[@]}; u++ )) ; do
|
|
|
|
here="${_local_[$u]}"
|
|
|
|
case "$here" in
|
|
|
|
*.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.tar.lz|*.7z|*.zip|*.rpm)
|
|
|
|
bsdtar -p -o -C src -xf "$here" || errUZ+=1 ;;
|
|
|
|
*)
|
|
|
|
cp -r -L "$here" src/ ;;
|
|
|
|
esac
|
|
|
|
done
|
2023-01-17 07:25:41 -05:00
|
|
|
fi
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-06-02 20:29:57 -04:00
|
|
|
[ $errUZ = 0 ] && info "Sources successfully unpacked." || \
|
2022-12-23 13:38:40 -05:00
|
|
|
{ error "Failed to unpack all sources."; cleanup_work; 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)
|
2022-11-24 14:42:02 -05:00
|
|
|
[ $? = 0 ] && echo "Build successful. Moving on to compression." \
|
|
|
|
|| { error "Unsuccessful build!"; cleanup_work; exit "$E_BUILD"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2023-02-17 08:54:10 -05:00
|
|
|
# Strip binaries
|
2022-06-02 12:54:54 -04:00
|
|
|
[ -f "$PKGMK_ROOT/.nostrip" ] && ns_filter="| grep -v -f $PKGMK_ROOT/.nostrip"
|
2023-02-16 18:14:27 -05:00
|
|
|
{ while read -r f; do
|
2022-06-01 23:11:58 -04:00
|
|
|
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
|
2023-02-16 18:14:27 -05:00
|
|
|
done } < <(eval find pkg -type f $ns_filter)
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2023-02-17 08:54:10 -05:00
|
|
|
# Compress anything under /man that does not appear to be gzipped
|
|
|
|
find pkg -type f -path "*/man/man*/*" \! -iname '*.gz' \
|
|
|
|
-exec gzip -9 '{}' +
|
|
|
|
|
|
|
|
# Ensure that symlinks point to the (now-compressed) manpages
|
|
|
|
{ while IFS="!" read -r f DIR; do
|
|
|
|
TARGET="$(readlink -n "$DIR/$f")"
|
|
|
|
TARGET="${TARGET##*/}"; TARGET="${TARGET%.gz}.gz";
|
|
|
|
rm -f "$DIR/$f"
|
|
|
|
[ -e "$DIR/$TARGET" ] && ln -sf "$TARGET" "$DIR/${f%.gz}.gz"
|
|
|
|
done } < <(find pkg -type l -path "*/man/man*/*" -printf '%f!%h\n')
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2023-02-17 08:54:10 -05:00
|
|
|
# Create the archive
|
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-11-24 14:42:02 -05:00
|
|
|
[ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ] || check_footprint
|
|
|
|
|
|
|
|
fi # Continue from here if extract and build were skipped
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-11-24 14:42:02 -05:00
|
|
|
# Clean up the work directory.
|
|
|
|
find . -maxdepth 1 -mindepth 1 -type l -delete; cleanup_work
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-11-24 14:42:02 -05:00
|
|
|
# Proceed to install/upgrade if requested.
|
|
|
|
if [ -n "$PKGMK_INSTALL_COMMAND" ]; then
|
2023-02-17 08:54:10 -05:00
|
|
|
[ $UID = 0 ] && PKGMK_SU=""
|
|
|
|
[ -z "$PKGMK_SU" ] || [ -x "$PKGMK_SU" ] || PKGMK_SU="/usr/bin/doas"
|
|
|
|
[ -z "$PKGMK_SU" ] || [ -x "$PKGMK_SU" ] ||
|
|
|
|
{ error "Cannot run pkgadd as a non-root user."; exit "$E_INSTALL"; }
|
2022-11-24 14:42:02 -05:00
|
|
|
$PKGMK_SU $PKGMK_INSTALL_COMMAND "$pkg_dir$package" \
|
2023-02-17 08:54:10 -05:00
|
|
|
&& info "pkgadd $package succeeded." || \
|
|
|
|
{ error "pkgadd $package failed.";
|
2022-11-24 14:42:02 -05:00
|
|
|
exit "$E_INSTALL"; }
|
|
|
|
fi
|
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-11-24 14:42:02 -05:00
|
|
|
E_FOOTPRINT=6 # footprint mismatch
|
2022-06-01 17:37:01 -04:00
|
|
|
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"
|
2022-10-10 13:50:03 -04:00
|
|
|
PKGMK_DOWNLOAD_PROG="/usr/bin/curl"
|
2022-06-12 15:38:35 -04:00
|
|
|
PKGMK_GIT_COMMAND="/usr/bin/git"
|
2023-02-17 08:54:10 -05:00
|
|
|
PKGMK_CONF="/etc/pkgmk.conf"; PKGMK_SU="/usr/bin/sudo"
|
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"
|
2023-02-17 08:54:10 -05:00
|
|
|
PKGMK_DOWNLOAD_ONLY="no"; PKGMK_KEEP_WORK="no"
|
2022-06-12 15:38:35 -04:00
|
|
|
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
|
|
|
|
-uf|--update-footprint) PKGMK_UPDATE_FOOTPRINT="yes" ;;
|
|
|
|
-us|--update-signature) PKGMK_UPDATE_SIG="yes" ;;
|
|
|
|
-rs|--refresh-signature) PKGMK_REFRESH_SIG="yes" ;;
|
|
|
|
-cs|--check-signature) PKGMK_CHECK_SIG="yes" ;;
|
2022-11-24 14:42:02 -05:00
|
|
|
--check-md5sum|--ignore-md5sum) ;; # deprecated flags
|
|
|
|
-d|-cm|-im|--download) ;; # but don't throw an error for them
|
2023-02-17 08:54:10 -05:00
|
|
|
-um|--update-md5sum) warn "updating md5sums is obsolete, ignoring option '$1'." ;;
|
|
|
|
-r|--recursive) warn "option '$1' no longer supported. Use a wrapper script for recursive operation." ;;
|
|
|
|
-c|--clean) { error "option '$1' no longer implemented in $(basename "$PKGMK_COMMAND"). Use prtwash instead."; exit 1; } ;;
|
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" ;;
|
|
|
|
-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 " -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 " -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"
|
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]}" ] || \
|
2023-02-17 08:54:10 -05:00
|
|
|
[ "$pkg_dir$package" -nt "$(realpath "${_local_[$li]}")" ] || utd=0
|
2022-05-31 16:02:44 -04:00
|
|
|
li=$(( li+1 ))
|
|
|
|
done
|
2022-11-24 14:42:02 -05:00
|
|
|
[ ! -e "$PKGMK_ROOT/Pkgfile" ] || [ "$pkg_dir$package" -nt "$PKGMK_ROOT/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-11-27 07:41:38 -05:00
|
|
|
[ "$PKGMK_MTIME_ONLY" = "yes" ] && info "$msg"; return $utd
|
2022-05-31 16:02:44 -04:00
|
|
|
}
|
|
|
|
|
2022-06-13 16:58:27 -04:00
|
|
|
fetch_url() {
|
2022-11-24 14:42:02 -05:00
|
|
|
local u="$1"; local h="$2"; local finished=0; local giturl tag CLONE_ARGS
|
2022-06-12 15:38:35 -04:00
|
|
|
local REPO SAVE_AS OCONTINUE OOUT; local m=0
|
2022-06-03 10:31:12 -04:00
|
|
|
|
2022-11-24 14:42:02 -05:00
|
|
|
if [[ "$u" =~ ^__git__ ]]; then
|
|
|
|
# git must be installed in order to obtain such a source
|
|
|
|
[ -x "$PKGMK_GIT_COMMAND" ] || return 1;
|
|
|
|
#
|
|
|
|
giturl="${u#__git__}"
|
|
|
|
# Did the port maintainer specify a branch other than 'master'?
|
|
|
|
tag="${giturl##*\#}"
|
2022-12-23 13:38:40 -05:00
|
|
|
[ "$tag" = "$giturl" ] || { giturl="${giturl%\#*}";
|
2022-11-27 07:41:38 -05:00
|
|
|
CLONE_ARGS="-c advice.detachedHead=false --branch $tag"; }
|
2022-11-24 14:42:02 -05:00
|
|
|
#
|
|
|
|
# Has this project been downloaded before?
|
|
|
|
if [ -d "$src_dir/$h.partial" ]; then
|
|
|
|
ln -s "$src_dir/$h.partial" "$h"; cd "$h"
|
2023-02-17 08:54:10 -05:00
|
|
|
"$PKGMK_GIT_COMMAND" pull "$giturl" "$tag"
|
2022-11-24 14:42:02 -05:00
|
|
|
finished=$?; cd ..
|
|
|
|
else
|
|
|
|
"$PKGMK_GIT_COMMAND" clone "$giturl" $CLONE_ARGS "$h.partial"
|
|
|
|
finished=$?; [ "$src_dir" = "" ] || { mv "$h.partial" "$src_dir";
|
|
|
|
ln -s "$src_dir/$h.partial" "$h"; }
|
|
|
|
fi
|
|
|
|
return $finished;
|
|
|
|
else
|
|
|
|
case "$PKGMK_DOWNLOAD_PROG" in
|
|
|
|
*wget) OCONTINUE="-c"
|
2023-02-17 08:54:10 -05:00
|
|
|
OOUT="--compression=none --passive-ftp
|
|
|
|
--no-directories --tries=3 --waitretry=3
|
|
|
|
$PKGMK_WGET_OPTIONS -O" ;;
|
2022-11-24 14:42:02 -05:00
|
|
|
*curl) OCONTINUE="-C -"
|
2023-02-17 08:54:10 -05:00
|
|
|
OOUT="-L -# --fail --ftp-pasv
|
|
|
|
--retry 3 --retry-delay 3
|
|
|
|
$PKGMK_CURL_OPTIONS -o" ;;
|
2022-11-24 14:42:02 -05:00
|
|
|
*) SAVE_AS="/bin/false" ;;
|
|
|
|
esac
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
[ "${PKGMK_SOURCE_MIRRORS[m]}" = "" ] && um=$u || \
|
|
|
|
{ REPO=${PKGMK_SOURCE_MIRRORS[m]%/}; um=$REPO/${u##*/}; }
|
|
|
|
m=$(( m+1 ))
|
|
|
|
# interrupted downloads from a previous run should be put where wget or curl will find them
|
|
|
|
[ -f "$src_dir/$h.partial" ] && { ln -s "$src_dir/$h.partial" . ;
|
2023-02-17 08:54:10 -05:00
|
|
|
SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OCONTINUE $OOUT"; } \
|
|
|
|
|| SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OOUT"
|
2022-11-24 14:42:02 -05:00
|
|
|
if $SAVE_AS "$h.partial"; then
|
|
|
|
finished=1
|
|
|
|
[ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] || \
|
|
|
|
{ mv "$h.partial" "$src_dir/$h"; ln -sf "$src_dir/$h" . ; }
|
|
|
|
else # an interrupted download should not have its efforts destroyed by cleanup_work()
|
|
|
|
[ ! -s "$h.partial" ] || [ "$src_dir" = "" ] || \
|
|
|
|
[ ! -w "$src_dir"/ ] || mv "$h.partial" "$src_dir"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2022-06-03 10:31:12 -04:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:42:02 -05:00
|
|
|
cat_footprint() {
|
|
|
|
pkginfo --footprint "$pkg_dir$package" \
|
|
|
|
| sed "s|\tlib/modules/$(uname -r)/|\tlib/modules/<kernel-version>/|g" \
|
|
|
|
| sort -k 3
|
2022-05-31 16:02:44 -04:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:42:02 -05:00
|
|
|
check_footprint() {
|
|
|
|
local CN CM
|
|
|
|
local TRUTH="$PKGMK_ROOT/.footprint"; local diffs=0; local severity=error;
|
|
|
|
[ -f "$pkg_dir$package" ] || \
|
|
|
|
{ error "$package not found. Cannot check footprint."; exit "$E_FOOTPRINT"; }
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
if [ -f "$TRUTH" ]; then
|
2022-11-24 14:42:02 -05:00
|
|
|
diff -w -t -U 0 <(sort "$TRUTH") <(cat_footprint | sort) | \
|
|
|
|
sed '/^@@/d; /^+++/d; /^---/d; s/^+/NEW /g; s/^-/MISSING /g' > ".footprint.diff"
|
|
|
|
if [ -s ".footprint.diff" ]; then
|
2022-11-27 07:41:38 -05:00
|
|
|
CN=$(grep -c ^NEW ".footprint.diff"); CM=$(grep -c ^MISSING ".footprint.diff")
|
2022-11-24 14:42:02 -05:00
|
|
|
[ "$PKGMK_IGNORE_MISSING" = "yes" ] || diffs=$CM
|
|
|
|
[ "$PKGMK_IGNORE_NEW" = "yes" ] || diffs=$(( diffs+CN ))
|
2023-02-17 08:54:10 -05:00
|
|
|
(( diffs == 0 )) && severity=warning
|
2022-11-24 14:42:02 -05:00
|
|
|
$severity "footprint mismatch found:"; cat ".footprint.diff" >&2
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2022-11-24 14:42:02 -05:00
|
|
|
rm ".footprint.diff"
|
2022-05-31 16:02:44 -04:00
|
|
|
else
|
2022-11-24 14:42:02 -05:00
|
|
|
warning "footprint not found, creating new."; cat_footprint > "$TRUTH"
|
2022-05-31 16:02:44 -04:00
|
|
|
fi
|
2023-02-17 08:54:10 -05:00
|
|
|
(( diffs == 0 )) || exit $E_FOOTPRINT
|
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-11-24 14:42:02 -05:00
|
|
|
# otherwise called from within $work.
|
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-11-24 14:42:02 -05:00
|
|
|
[[ "${source[$s]}" =~ ^__git__ ]] || 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-11-24 14:42:02 -05:00
|
|
|
[ "$when" = "pre-Pkgfile" ] && echo "Pkgfile verification failed"
|
|
|
|
[ "$when" != "pre-Pkgfile" ] && echo "signature verification failed"
|
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-11-24 14:42:02 -05:00
|
|
|
pub="/etc/ports/$(basename "${key%.sec}.pub")"
|
2022-05-31 16:02:44 -04:00
|
|
|
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
|
2022-11-24 14:42:02 -05:00
|
|
|
[ -e "$f" ] && ordered+=( "$f" )
|
2022-06-01 17:37:01 -04:00
|
|
|
done
|
2022-06-13 16:58:27 -04:00
|
|
|
for ((si=0; si < ${#source[@]}; si++)); do
|
2022-11-24 14:42:02 -05:00
|
|
|
# ignore git directories when writing the signature
|
2023-02-17 08:54:10 -05:00
|
|
|
[[ "${source[si]}" =~ ^__git__ ]] || ordered+=("${_local_[si]}"); done
|
2022-11-24 14:42:02 -05:00
|
|
|
sha256sum --tag "${ordered[@]}" \
|
2022-05-31 16:02:44 -04:00
|
|
|
| sed 's|^SHA256 (.*/\(.*\))\(.* = .*\)|SHA256 (\1)\2|' \
|
2022-11-24 14:42:02 -05:00
|
|
|
| /usr/bin/signify -S -e -x - -q -s "$key" -m - \
|
|
|
|
| sed "s|${key%.sec}.pub|$pub|"
|
2022-05-31 16:02:44 -04:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh_signature() {
|
2023-02-17 08:54:10 -05:00
|
|
|
[ -e ".signature" ] && [ ! -w ".signature" ] || {
|
|
|
|
error ".signature not writable."; return $E_DIRPERM; }
|
2022-05-31 16:02:44 -04:00
|
|
|
|
|
|
|
local REPO
|
2023-02-17 08:54:10 -05:00
|
|
|
if [ -z "$PKGMK_PRIVATEKEY" ]; then
|
|
|
|
REPO=${PWD##*/}; REPO=${REPO%.git};
|
|
|
|
[ -r "/etc/ports/${REPO}.sec" ] && \
|
|
|
|
PKGMK_PRIVATEKEY="/etc/ports/${REPO}.sec" || \
|
|
|
|
{ error "No suitable secret key found. Specify one explicitly with '-sk'."; return $E_SIGNATURE; }
|
|
|
|
fi
|
2022-05-31 16:02:44 -04:00
|
|
|
|
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
|
2023-02-17 08:54:10 -05:00
|
|
|
info "Signature refreshed."
|
2022-05-31 16:02:44 -04:00
|
|
|
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
|
|
|
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-11-24 14:42:02 -05:00
|
|
|
check_reqvars check_pkg_mtime fetch_url cat_footprint check_footprint \
|
2022-06-03 10:31:12 -04:00
|
|
|
cat_signature check_signature parse_signify_output refresh_signature \
|
2023-02-17 08:54:10 -05:00
|
|
|
cleanup_work
|
2022-06-16 16:18:58 -04:00
|
|
|
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
|
2022-05-31 16:02:44 -04:00
|
|
|
|
2022-10-31 16:49:34 -04:00
|
|
|
export LC_ALL=C.UTF-8
|
2022-05-31 16:02:44 -04:00
|
|
|
main "$@"
|