From f4078e682079a1a41eb52c10c75e2172a172f4c5 Mon Sep 17 00:00:00 2001 From: Morgan Aldridge Date: Wed, 20 Sep 2023 12:46:35 -0400 Subject: [PATCH] Added new mlvwm-powerdown script implementing OS-specific sleep/reboot/shutdown functionality, updated Makefile to install mlvwm-* scripts in ~/bin, and updated Special menu items to use mlvwm-powerdown for sleep/restart/shutdown functionality. Issue #10 --- .mlvwm/MenuBar | 11 ++++--- Makefile | 7 ++++- bin/mlvwm-powerdown | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100755 bin/mlvwm-powerdown diff --git a/.mlvwm/MenuBar b/.mlvwm/MenuBar index e3eb559..4cb30a3 100644 --- a/.mlvwm/MenuBar +++ b/.mlvwm/MenuBar @@ -48,9 +48,10 @@ Menu Default-Label, Label "Label" "Project 2" NonSelect, Gray END -Menu Default-Restart +Menu Default-WindowManager "Start twm" Action Restart twm "Start fvwm" Action Restart fvwm +"Restart mlvwm" Action Restart mlvwm END Menu Default-Special, Label "Special" @@ -60,10 +61,12 @@ Menu Default-Special, Label "Special" "Eject Disk" NonSelect, Gray "Erase Disk..." NonSelect, Gray "" NonSelect -"Start" SubMenu Default-Restart +"Window Manager" SubMenu Default-WindowManager +"" NonSelect "Log Out" Action Exit -"Restart" Action Restart mlvwm -"Shut down" Action Exit +"Sleep" Action Exec mlvwm-powerdown exec mlvwm-powerdown -s +"Restart" Action Exec mlvwm-powerdown exec mlvwm-powerdown -r +"Shut Down" Action Exec mlvwm-powerdown exec mlvwm-powerdown -p END Menu Default-Window diff --git a/Makefile b/Makefile index fe6cd2b..8743302 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ TEMP=tmp CONF=.mlvwm +BIN=bin PIXMAP=$(CONF)/pixmap PATTERNS=$(CONF)/patterns @@ -51,11 +52,15 @@ patterns: curl -# -L https://imgur.com/a/9jYy0/zip -o "$(TEMP)/Mac OS Solid Color Backgrounds.zip" unzip -d $(PATTERNS) "$(TEMP)/Mac OS Solid Color Backgrounds.zip" -install: +install: install-bin cp -R $(CONF) $(HOME)/ ln -fs $(HOME)/$(CONF)/.mlvwmrc $(HOME)/.mlvwmrc sed -i 's@/home2/tak/bin/pixmap@$(HOME)/$(PIXMAP)@g' $(HOME)/$(CONF)/.mlvwmrc +install-bin: + mkdir -p $(HOME)/$(BIN) + install -b -B .`date +%Y%m%d-%H%M%S` -m 700 -o $(USER) $(BIN)/mlvwm-* $(HOME)/$(BIN) + clean: clean-pixmap rm -r $(TEMP) rm -rf $(PATTERNS) diff --git a/bin/mlvwm-powerdown b/bin/mlvwm-powerdown new file mode 100755 index 0000000..21dd0bc --- /dev/null +++ b/bin/mlvwm-powerdown @@ -0,0 +1,70 @@ +#!/bin/sh + +# mlvwm-powerdown - Wrapper OS-specific implementations of sleep, reboot, and/or +# power off of the system +# +# There may be OS-specific configuration required + +tool="$(basename "$0")" +os="$(uname -s)" + +_usage() { + echo "Usage: ${tool} [-s | -r | -p]" + exit 1 +} + +_unsupported() { + echo "${tool}: ${1} is not supported under ${os}." + exit 1 +} + +_sleep_now() { + case "$os" in + "OpenBSD") + pgrep -q apmd && zzz + ;; + *) + _unsupported "sleep" + ;; + esac +} + +_reboot_now() { + case "$os" in + "OpenBSD"|"FreeBSD"|"Linux") + shutdown -r now + ;; + *) + _unsupported "reboot" + ;; + esac +} + +_poweroff_now() { + case "$os" in + "OpenBSD"|"FreeBSD") + shutdown -p now + ;; + "Linux") + shutdown -P now + ;; + *) + _unsupported "power off" + ;; + esac +} + +case "$1" in + "-s") + _sleep_now + ;; + "-r") + _reboot_now + ;; + "-p") + _poweroff_now + ;; + *) + _usage + ;; +esac