OSDN Git Service

Merge branch 'master' of https://github.com/instantos/instantOS
[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 instantmenu; then
9     echo "instantmenu already running"
10     exit
11 fi
12
13 answer=$(echo "cancel
14 shutdown
15 logout
16 reboot
17 lock screen
18 kill wm" | instantmenu -l 10 -w 400 -c -n -F -p "do you want to shut down?")
19
20 # if there are apps open, ask for confirmation
21 zconfirm() {
22     if wmctrl -l | grep -q '..'; then
23         echo "running applications found"
24         if zenity --question --text="there are apps running, sure you want to $1"; then
25             echo "yes"
26             return 0
27         else
28             echo "no"
29             exit
30         fi
31     else
32         echo "no running applications found"
33     fi
34 }
35
36 case "$answer" in
37 s*)
38     zconfirm "shutdown"
39     rm ~/.instantosrunning
40     sleep 0.4
41     shutdown now
42     ;;
43 r*)
44     zconfirm "reboot"
45     rm ~/.instantosrunning
46     sleep 0.4
47     reboot
48     ;;
49 log*)
50     zconfirm "sign out"
51     rm ~/.instantosrunning
52     sleep 0.4
53     kill -9 -1
54     ;;
55 loc*)
56     ilock
57     ;;
58 k*)
59     pkill instantwm
60     ;;
61 *)
62     echo "canceled"
63     ;;
64 esac