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
This commit is contained in:
classabbyamp 2024-06-15 12:12:09 -04:00 committed by classabbyamp
parent 9ff75d00a2
commit 0420101ca2
2 changed files with 49 additions and 16 deletions

View File

@ -19,32 +19,65 @@ UPDATE="$5"
export PATH="usr/bin:usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin" 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 case "$ACTION" in
targets) targets)
echo "post-install pre-remove" echo "post-install pre-remove"
;; ;;
run) run)
[ -x /usr/bin/update-binfmts ] || exit 0 [ -x /usr/bin/update-binfmts ] || exit 0
[ -z "${binfmts}" ] && exit 0
case "$TARGET" in case "$TARGET" in
post-install) post-install)
echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do if [ -n "${binfmts}" ]; then
line=$(echo $line | tr '&' '\' 2> /dev/null) install_binfmts
set -- ${line} fi
_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})" if [ -n "${import_binfmts}" ]; then
update-binfmts --package ${PKGNAME} --install ${_bname} ${_bin} ${_args} import_binfmts
done fi
;; ;;
pre-remove) pre-remove)
echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do if [ -n "${binfmts}" ]; then
line=$(echo $line | tr '&' '\' 2> /dev/null) remove_binfmts
set -- ${line} fi
_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})" if [ -n "${import_binfmts}" ]; then
if [ -f /var/lib/binfmts/${_bname} ]; then unimport_binfmts
update-binfmts --package ${PKGNAME} --remove ${_bname} ${_bin}
fi fi
done
;; ;;
*) *)
exit 1 exit 1

View File

@ -1,6 +1,6 @@
# Template file for 'xbps-triggers' # Template file for 'xbps-triggers'
pkgname=xbps-triggers pkgname=xbps-triggers
version=0.127 version=0.128
revision=1 revision=1
bootstrap=yes bootstrap=yes
short_desc="XBPS triggers for Void Linux" short_desc="XBPS triggers for Void Linux"