From 0420101ca22c30d0aa3e6069adb37ed39a8168ba Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Sat, 15 Jun 2024 12:12:09 -0400 Subject: [PATCH] xbps-triggers: support importing/unimporting binfmt files removes the need to manually list all the binfmt magics and masks in qemu-user-static. keeps the legacy behaviour around for compatibility --- srcpkgs/xbps-triggers/files/binfmts | 63 ++++++++++++++++++++++------- srcpkgs/xbps-triggers/template | 2 +- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/srcpkgs/xbps-triggers/files/binfmts b/srcpkgs/xbps-triggers/files/binfmts index 16919833a80..4212afd1e0d 100755 --- a/srcpkgs/xbps-triggers/files/binfmts +++ b/srcpkgs/xbps-triggers/files/binfmts @@ -19,32 +19,65 @@ UPDATE="$5" export PATH="usr/bin:usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin" +# {install,remove}_binfmts: legacy installation style +install_binfmts() { + echo "$binfmts" | while read -r line; do + set -- $line + _bin="$1"; shift + _bname="${_bin##*/}" + update-binfmts --package "${PKGNAME}" --install "${_bname}" "${_bin}" "$@" + done +} + +remove_binfmts() { + echo "$binfmts" | while read -r line; do + set -- $line + _bin="$1"; shift + _bname="${_bin##*/}" + if [ -f "var/lib/binfmts/${_bname}" ]; then + update-binfmts --package "${PKGNAME}" --remove "${_bname}" "${_bin}" + fi + done +} + +# {,un}import_binfmts: new installation style +import_binfmts() { + for _fmt in $import_binfmts; do + update-binfmts --import "$_fmt" + done +} + +unimport_binfmts() { + for _fmt in $import_binfmts; do + if [ -f "var/lib/binfmts/${_fmt}" ]; then + update-binfmts --unimport "$_fmt" + fi + done +} + case "$ACTION" in targets) echo "post-install pre-remove" ;; run) [ -x /usr/bin/update-binfmts ] || exit 0 - [ -z "${binfmts}" ] && exit 0 case "$TARGET" in post-install) - echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do - line=$(echo $line | tr '&' '\' 2> /dev/null) - set -- ${line} - _bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})" - update-binfmts --package ${PKGNAME} --install ${_bname} ${_bin} ${_args} - done + if [ -n "${binfmts}" ]; then + install_binfmts + fi + if [ -n "${import_binfmts}" ]; then + import_binfmts + fi ;; pre-remove) - echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do - line=$(echo $line | tr '&' '\' 2> /dev/null) - set -- ${line} - _bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})" - if [ -f /var/lib/binfmts/${_bname} ]; then - update-binfmts --package ${PKGNAME} --remove ${_bname} ${_bin} - fi - done + if [ -n "${binfmts}" ]; then + remove_binfmts + fi + if [ -n "${import_binfmts}" ]; then + unimport_binfmts + fi ;; *) exit 1 diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template index 66936411a42..7745a9aa4f1 100644 --- a/srcpkgs/xbps-triggers/template +++ b/srcpkgs/xbps-triggers/template @@ -1,6 +1,6 @@ # Template file for 'xbps-triggers' pkgname=xbps-triggers -version=0.127 +version=0.128 revision=1 bootstrap=yes short_desc="XBPS triggers for Void Linux"