From b0ab5c59ddf351d01bf52468c0906ef7b0066aa5 Mon Sep 17 00:00:00 2001 From: Marty Oehme <contact@martyoeh.me> Date: Tue, 25 Feb 2025 22:49:38 +0100 Subject: [PATCH] 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. --- scripts/.local/bin/powermenu | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/.local/bin/powermenu b/scripts/.local/bin/powermenu index 89362e0..b186399 100755 --- a/scripts/.local/bin/powermenu +++ b/scripts/.local/bin/powermenu @@ -58,12 +58,20 @@ result=$(printf "%s" "$menu" | $selector_program $selector_opts --prompt "$promp case "$result" in "Shutdown" | "$power_off_btn") if [ -n "$POWERMENU_SHUTDOWN_CMD" ]; then eval "$POWERMENU_SHUTDOWN_CMD"; else - systemctl poweroff + if [ -x /usr/bin/systemctl ]; then + systemctl poweroff + else + sudo poweroff + fi fi ;; "Reboot" | "$reboot_btn") if [ -n "$POWERMENU_REBOOT_CMD" ]; then eval "$POWERMENU_REBOOT_CMD"; else - systemctl reboot + if [ -x /usr/bin/systemctl ]; then + systemctl reboot + else + sudo reboot + fi fi ;; "Lockscreen" | "$lock_btn") @@ -81,12 +89,20 @@ case "$result" in ;; "Suspend" | "$suspend_btn") if [ -n "$POWERMENU_SUSPEND_CMD" ]; then eval "$POWERMENU_SUSPEND_CMD"; else - systemctl suspend-then-hibernate + if [ -x /usr/bin/systemctl ]; then + systemctl suspend-then-hibernate + else + sudo zzz -H + fi fi ;; "Hibernate" | "$hibernate_btn") if [ -n "$POWERMENU_HIBERNATE_CMD" ]; then eval "$POWERMENU_HIBERNATE_CMD"; else - systemctl hibernate + if [ -x /usr/bin/systemctl ]; then + systemctl hibernate + else + sudo ZZZ + fi fi ;; esac