OSDN Git Service

correct typo
[instantos/instantOS.git] / programs / instantshutdown
1 #!/bin/bash
2
3 ###################################################
4 ## shut down pc and break instantwm restart loop ##
5 ###################################################
6
7 # multiple instances would overlap
8 if [ "$(pgrep instantshutdown | wc -l)" -gt 2 ]; then
9     pgrep instantshutdown | wc -l
10     echo "instantshutdown already running"
11     exit
12 fi
13
14 if [ -n "$1" ]; then
15     answer="$1"
16 else
17     answer="$(echo 'cancel
18 shutdown
19 logout
20 reboot
21 lock screen
22 suspend
23 restart wm' | instantmenu -l 10 -w -1 -c -n -F -p 'shutdown menu' -q 'select')"
24 fi
25
26 # if there are apps open, ask for confirmation
27 zconfirm() {
28     if wmctrl -l | grep -q '..'; then
29         echo "running applications found"
30         if imenu -c "there are apps running, sure you want to $1?"; then
31             echo "yes"
32             return 0
33         else
34             echo "no"
35             exit
36         fi
37     else
38         echo "no running applications found"
39     fi
40 }
41
42 prepareshutdown() {
43     # save current brightness
44     touch /tmp/shuttingdown
45     if CURBRIGHT="$(/usr/share/instantassist/utils/b.sh g)"; then
46         iconf savebright "$CURBRIGHT"
47     fi
48
49     rm /tmp/instantosrunning
50     # these keep causing stop jobs
51     pkill -f clipnotify
52     pkill -f clipmenud
53 }
54
55 case "$answer" in
56 shut*)
57     zconfirm "shutdown"
58     prepareshutdown
59     sleep 0.4
60     shutdown now
61     ;;
62 reb*)
63     zconfirm "reboot"
64     prepareshutdown
65     sleep 0.4
66     reboot
67     ;;
68 log*)
69     zconfirm "sign out"
70     rm /tmp/instantosrunning
71     sleep 0.4
72     kill -9 -1
73     ;;
74 loc*)
75     ilock
76     ;;
77 sus*)
78     systemctl suspend
79     ilock
80     ;;
81 res*)
82     pkill instantwm
83     ;;
84 *)
85     echo "canceled"
86     ;;
87 esac