powermenu: Adapt for both archlinux and voidlinux

Keeps using the known systemctl commands for voidlinux environments (or
other environments that have access to the `systemctl` command).

For voidlinux it instead uses the commands `poweroff`, `reboot`, `zzz`
and `ZZZ` (which are the same script). Works fairly naively for now and
does no checking if the commands exist or work. Runs required commands
as sudo so ideally the user or group has access to a passwordless
implementation of the commands.
This commit is contained in:
Marty Oehme 2025-02-25 22:49:38 +01:00
parent 0cbd8d548f
commit b0ab5c59dd
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -58,12 +58,20 @@ result=$(printf "%s" "$menu" | $selector_program $selector_opts --prompt "$promp
case "$result" in case "$result" in
"Shutdown" | "$power_off_btn") "Shutdown" | "$power_off_btn")
if [ -n "$POWERMENU_SHUTDOWN_CMD" ]; then eval "$POWERMENU_SHUTDOWN_CMD"; else if [ -n "$POWERMENU_SHUTDOWN_CMD" ]; then eval "$POWERMENU_SHUTDOWN_CMD"; else
if [ -x /usr/bin/systemctl ]; then
systemctl poweroff systemctl poweroff
else
sudo poweroff
fi
fi fi
;; ;;
"Reboot" | "$reboot_btn") "Reboot" | "$reboot_btn")
if [ -n "$POWERMENU_REBOOT_CMD" ]; then eval "$POWERMENU_REBOOT_CMD"; else if [ -n "$POWERMENU_REBOOT_CMD" ]; then eval "$POWERMENU_REBOOT_CMD"; else
if [ -x /usr/bin/systemctl ]; then
systemctl reboot systemctl reboot
else
sudo reboot
fi
fi fi
;; ;;
"Lockscreen" | "$lock_btn") "Lockscreen" | "$lock_btn")
@ -81,12 +89,20 @@ case "$result" in
;; ;;
"Suspend" | "$suspend_btn") "Suspend" | "$suspend_btn")
if [ -n "$POWERMENU_SUSPEND_CMD" ]; then eval "$POWERMENU_SUSPEND_CMD"; else if [ -n "$POWERMENU_SUSPEND_CMD" ]; then eval "$POWERMENU_SUSPEND_CMD"; else
if [ -x /usr/bin/systemctl ]; then
systemctl suspend-then-hibernate systemctl suspend-then-hibernate
else
sudo zzz -H
fi
fi fi
;; ;;
"Hibernate" | "$hibernate_btn") "Hibernate" | "$hibernate_btn")
if [ -n "$POWERMENU_HIBERNATE_CMD" ]; then eval "$POWERMENU_HIBERNATE_CMD"; else if [ -n "$POWERMENU_HIBERNATE_CMD" ]; then eval "$POWERMENU_HIBERNATE_CMD"; else
if [ -x /usr/bin/systemctl ]; then
systemctl hibernate systemctl hibernate
else
sudo ZZZ
fi
fi fi
;; ;;
esac esac