OSDN Git Service

Merge branch 'master' of https://github.com/instantos/instantOS into master
[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 answer="$(echo 'cancel
15 shutdown
16 logout
17 reboot
18 lock screen
19 suspend
20 restart wm' | instantmenu -l 10 -w -1 -c -n -F -p 'shutdown menu' -q 'select')"
21
22 # if there are apps open, ask for confirmation
23 zconfirm() {
24     if wmctrl -l | grep -q '..'; then
25         echo "running applications found"
26         if imenu -c "there are apps running, sure you want to $1?"; then
27             echo "yes"
28             return 0
29         else
30             echo "no"
31             exit
32         fi
33     else
34         echo "no running applications found"
35     fi
36 }
37
38 prepareshutdown(){
39     # save current brightness
40     if CURBRIGHT="$(/usr/share/instantassist/utils/b.sh g)"
41     then
42         iconf savebright "$CURBRIGHT"
43     fi
44
45     rm /tmp/instantosrunning
46     # these keep causing stop jobs
47     pkill -f clipnotify
48     pkill -f clipmenud
49 }
50
51 case "$answer" in
52 shut*)
53     zconfirm "shutdown"
54     prepareshutdown
55     sleep 0.4
56     shutdown now
57     ;;
58 reb*)
59     zconfirm "reboot"
60     prepareshutdown
61     sleep 0.4
62     reboot
63     ;;
64 log*)
65     zconfirm "sign out"
66     rm /tmp/instantosrunning
67     sleep 0.4
68     kill -9 -1
69     ;;
70 loc*)
71     ilock
72     ;;
73 sus*)
74     systemctl suspend
75     ilock
76     ;;
77 res*)
78     pkill instantwm
79     ;;
80 *)
81     echo "canceled"
82     ;;
83 esac