From 21627180c375fef13b88778cb5339a890aca946a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 1 Apr 2021 22:07:47 -0600 Subject: [PATCH] Update wk-power-command to support macOS --- scripts/wk-power-command | 59 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/scripts/wk-power-command b/scripts/wk-power-command index 92af02fb..6cce8840 100755 --- a/scripts/wk-power-command +++ b/scripts/wk-power-command @@ -2,20 +2,51 @@ # ## Wizard Kit: Wrapper for logout, reboot, & poweroff -# Unmount filesystems -find /media -maxdepth 1 -mindepth 1 -type d \ - -exec udevil umount "{}" \; +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail -# Flush write cache -sudo sync +# Functions +function linux_power_cmd() { + case "${1:-x}" in + poweroff) + sudo systemctl poweroff;; + reboot) + sudo systemctl reboot;; + *) + openbox --exit;; + esac +} + +function macos_power_cmd() { + case "${1:-x}" in + poweroff) + shutdown -h now;; + reboot) + shutdown -r now;; + *) + exit;; + esac +} + +# "Main" +if [[ -e "/.wk-live-macos" ]]; then + # Flush write cache + sync + + # Perform requested action + macos_power_cmd "${1:-x}" +else + # Unmount filesystems + find /media -maxdepth 1 -mindepth 1 -type d \ + -exec udevil umount "{}" \; + + # Flush write cache + sudo sync + + # Perform requested action + linux_power_cmd "${1:-x}" +fi -# Perform requested action -case "${1:-x}" in - poweroff) - sudo systemctl poweroff;; - reboot) - sudo systemctl reboot;; - *) - openbox --exit;; -esac exit 0