fixed check for running x
[pandora-libraries.git] / testdata / scripts / op_battlow.sh
1 #!/bin/bash
2 #usage op_shutdown.sh time in seconds
3 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
4 time=$1
5 countdown () {
6   for i in $(seq $time); do
7     precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
8     echo $precentage
9     echo "# Low power, shutdown in $i"
10     sleep 1
11   done
12 }
13 countdown  | su -c 'DISPLAY=:0.0  zenity --progress --auto-close --text "Shutdown" --title "Shutdown"' $xfceuser
14 if [ $? -eq 0 ]; then
15 shutdown -h now
16 else
17 su -c 'DISPLAY=:0.0  zenity --error --text "`printf "Shutdown aborted! \n
18 Pleas plug in the charger ASAP or shutdown manually, the System will crash in a few minuts"`"' $xfceuser
19 fi