blob: 9b985f6089575de8e23d40f4500bf2d4da8e5122 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/bin/sh
set -eu
actions_icons='/usr/share/icons/gnome/16x16/actions'
awk_who_script='
BEGIN {
display_ere = " [(]" display "[)]$";
printed = 0;
}
{
if (!match($0, display_ere)) {
if (!printed) {
print("\n\nThe following sessions will be " \
"hung up:\n");
printed = 1;
}
print("<tt><small> " $0 "</small></tt>");
}
}
'
do_logout()
{
zenity --question --title='Log Out' \
--window-icon="${actions_icons}/system-log-out.png" \
--text='Are you sure you want to log out?' \
--ok-label='Log Out' --cancel-label='Cancel' && \
printf 'quit\n' >~/.xsessionmanage
return 0
}
do_shutdown()
{
zenity --question --title='Shut Down' \
--window-icon="${actions_icons}/system-shutdown.png" \
--text="Are you sure you want to shut down this system?$(who | \
awk -v "display=${DISPLAY}" "${awk_who_script}")" \
--ok-label='Shut Down' --cancel-label='Cancel' && \
sudo shutdown -hP now
return 0
}
do_reboot()
{
zenity --question --title='Reboot' \
--window-icon="${actions_icons}/system-shutdown.png" \
--text="Are you sure you want to reboot this system?$(who | \
awk -v "display=${DISPLAY}" "${awk_who_script}")" \
--ok-label='Reboot' --cancel-label='Cancel' && \
sudo reboot
return 0
}
do_s2mem()
{
zenity --question --title='Suspend' \
--window-icon="${actions_icons}/media-playback-pause.png" \
--text='Are you sure you want to suspend this system?' \
--ok-label='Suspend' --cancel-label='Cancel' && \
sudo dd of='/sys/power/state' <<-EOF
mem
EOF
return 0
}
do_s2disk()
{
zenity --question --title='Hibernate' \
--window-icon="${actions_icons}/media-playback-pause.png" \
--text='Are you sure you want to hibernate this system?' \
--ok-label='Hibernate' --cancel-label='Cancel' && \
sudo dd of='/sys/power/state' <<-EOF
disk
EOF
return 0
}
usage()
{
printf 'Usage: %s {logout|shutdown|reboot|s2mem|s2disk}\n' "${0}"
return 0
}
main()
{
local action=
if [ ${#} -ne 1 ]; then
usage 1>&2
return 1
fi
action="${1}"
shift 1
case "${action}" in
'logout' | 'shutdown' | 'reboot' | 's2mem' | 's2disk')
"do_${action}"
;;
*)
usage 1>&2
return 1
;;
esac
return 0
}
main "${@}"
|