Tizen 2.0 Release
[external/acpid.git] / packaging / acpid.power.sh
1 #!/bin/sh
2
3 PATH=/sbin:/bin:/usr/bin
4
5 # Get the ID of the first active X11 session:
6 uid_session=$(
7 ck-list-sessions | \
8 awk '
9 /^Session[0-9]+:$/ { uid = active = x11 = "" ; next }
10 { gsub(/'\''/, "", $3) }
11 $1 == "unix-user" { uid = $3 }
12 $1 == "active" { active = $3 }
13 $1 == "x11-display" { x11 = $3 }
14 active == "TRUE" && x11 != "" {
15         print uid
16         exit
17 }')
18
19 # Check that there is a power manager, otherwise shut down.
20 [ "$uid_session" ] &&
21 ps axo uid,cmd | \
22 awk '
23     $1 == '$uid_session' &&
24         ($2 == "gnome-power-manager" || $2 == "kpowersave" || $2 == "xfce4-power-manager" || $2 ~ /dawati-power-icon/ ) \
25                 { found = 1; exit }
26     END { exit !found }
27 ' ||
28   shutdown -h now
29