op_osupgrade: rework update script
[openpandora.oe.git] / recipes / pandora-system / pandora-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 if [ x$time = "x" ]; then
6         time=30
7 fi
8 countdown () {
9   for i in $(seq $time); do
10     percentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
11     echo $percentage
12     remain=$(echo $time $i | awk '{ printf("%d\n", $1-$2) }')
13     echo "# Low power, shutdown in $remain"
14     sleep 1
15   done
16 }
17 countdown  | su -c 'DISPLAY=:0.0  zenity --progress --auto-close --text "Shutdown" --title "Shutdown"' $xfceuser
18 if [ $? -eq 0 ]; then
19     shutdown -h now
20 else
21     su -c 'DISPLAY=:0.0  zenity --error --text "`printf "Shutdown aborted! \n
22 Please plug in the charger ASAP or shutdown manually, the System will crash in a few minutes"`"' $xfceuser
23 fi