chamesle-store-helper (1935B)
1 #!/bin/sh 2 # what the store runs as root, through pkexec: nothing else gets through 3 # add|del PKG... driver PKG... upgrade import FILE.deb|FILE.rpm auto on|off firmware DEVICE-ID 4 set -eu 5 cmd=${1:-} 6 [ $# -gt 0 ] && shift 7 case $cmd in 8 add|del|driver) 9 [ $# -gt 0 ] || exit 2 10 for p; do 11 case $p in -*|*[!a-zA-Z0-9._+-]*) echo "not a package name: $p" >&2; exit 2;; esac 12 done 13 if [ "$cmd" = driver ]; then 14 # drivers: install, then a new initramfs so the right one (not nouveau) loads at boot 15 apk add --no-interactive --progress-fd 1 "$@" 16 # nvidia: flatpak apps need their part of it too 17 [ -x /usr/libexec/chamesle-nvidia-flatpak ] && /usr/libexec/chamesle-nvidia-flatpak >&2 || true 18 exec dracut --force --regenerate-all 19 fi 20 # --progress-fd 1: "done/total" lines on stdout, the store turns them into a progress bar 21 exec apk "$cmd" --no-interactive --progress-fd 1 "$@" 22 ;; 23 upgrade) 24 exec apk upgrade --update-cache --no-interactive --progress-fd 1 25 ;; 26 import) 27 [ $# = 1 ] && [ -f "$1" ] || { echo "no such file: ${1:-}" >&2; exit 2; } 28 case $1 in *.deb|*.rpm) ;; *) echo "only .deb and .rpm files" >&2; exit 2;; esac 29 exec pkgimport install "$1" 30 ;; 31 auto) 32 # updates on their own or not, read by /usr/libexec/chamesle-auto-update 33 case ${1:-} in on) v=yes;; off) v=no;; *) exit 2;; esac 34 mkdir -p /etc/chamesle 35 printf '# install updates on their own once a day while plugged in (the store'"'"'s switch)\nauto=%s\n' $v > /etc/chamesle/updates.conf 36 ;; 37 firmware) 38 # fwupd device ids are 40 hex characters 39 [ $# = 1 ] || exit 2 40 case $1 in *[!0-9a-f]*|"") echo "not a device id: $1" >&2; exit 2;; esac 41 exec fwupdmgr update "$1" --assume-yes --no-reboot-check 42 ;; 43 *) 44 echo "usage: chamesle-store-helper add|del|driver PKG... | upgrade | import FILE | auto on|off | firmware ID" >&2 45 exit 2 46 ;; 47 esac