summaryrefslogtreecommitdiff
path: root/bin/menuscripts/mpower
blob: d96e09a9db21f9b001474d3bdf137aed18ce3f6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh

if [ "$1" ]
then
 choice="$1"
else
 choice="$(
 cat <<EOF | commander -c -w 1 -y 8
poweroff
suspend
reboot
firmware
hibernate
windows
EOF
 )"
fi

>&2 printf 'choice: %s\n' "$choice"

# Same on both
case "$choice" in
 "windows")
  NextBoot="$(efibootmgr -u | grep 'Windows' | grep '^Boot[0-9]\{4\}' | cut -c 5-8)"
   expect -f - <<EOF
set pw [exec pass show aluc]
spawn doas efibootmgr --bootnext "$NextBoot" -u
expect "password:"
send "\$pw\r"
expect eof
EOF
  choice="reboot" ;;
 "firmware") rebootfw; exit ;;
esac

# Winter
if [ "$(hostname)" = "winter" ]; then 
 case "$choice" in
  "suspend") systemctl hybrid-sleep ;;
  "") exit 1 ;;
  *) systemctl "$choice" ;;
 esac
# Spring
elif [ "$(hostname)" = "spring" ]; then
	case "$choice" in
		"suspend") doas /usr/sbin/zzz -H ;;
		"hibernate") doas /usr/sbin/zzz -Z ;;
		"poweroff") doas /usr/sbin/poweroff ;;
		"reboot") doas /usr/sbin/reboot ;;
  "windows")
   ;;
		"") exit 1 ;;
		*) ;;
	esac 
fi