Update wk-power-command to support macOS

This commit is contained in:
2Shirt 2021-04-01 22:07:47 -06:00
parent c49391d05a
commit 21627180c3
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -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