op_power.sh: fix lockfile usage
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_power.sh
index b422d92..25ca48a 100644 (file)
@@ -1,6 +1,10 @@
 #!/bin/bash
 
-( test -e /tmp/op_power.lock && exit 2 ) || touch "/tmp/op_power.lock"
+. /usr/pandora/scripts/op_paths.sh
+
+# XXX: better use lockfile (or something), but it's not in current firmware
+test -e /tmp/op_power.lock && exit 2
+touch /tmp/op_power.lock
 
 debug(){
        return 1 # 0 when debugging, 1 when not
@@ -20,28 +24,28 @@ debug && echo "powerstate=$powerstate"
 
 lowPowerOn(){ #switch from normal to lowpower mode
        cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
-       cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /tmp/oldbright
+       cat $SYSFS_BACKLIGHT_BRIGHTNESS > /tmp/oldbright
        pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
        for PID in $pidlist
        do
                kill -19 $PID #send SIGSTOP
        done
-       rm /tmp/hcistate
+       test -f /tmp/hcistate && rm /tmp/hcistate
        hcistate=$(hciconfig hci0 | grep DOWN)
        if [ $hcistate ]; then
                echo "down" > /tmp/hcistate
        else
                hciconfig hci0 down
        fi
-       rm /tmp/wlstate
+       test -f /tmp/wlstate && rm /tmp/wlstate
        wlstate=$(lsmod | grep -m1 wl1251)
-       if [ ! $wlstate ]; then
+       if [ -z "$wlstate" ]; then
                echo "down" > /tmp/wlstate
        else
                ifconfig wlan0 down
                rmmod board_omap3pandora_wifi wl1251_sdio wl1251
        fi
-       echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+       echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
        echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
        echo 16 > /sys/class/leds/pandora\:\:power/brightness #dim power LED
        /usr/pandora/scripts/op_cpuspeed.sh 125
@@ -51,7 +55,7 @@ lowPowerOff(){ # switch from lowpower to normal mode
        oldspeed=$(cat /tmp/oldspeed)
        /usr/pandora/scripts/op_cpuspeed.sh $oldspeed
        oldbright=$(cat /tmp/oldbright)
-       maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
+       maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
        echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
        sleep 0.1s # looks cleaner, could flicker without
        oldspeed=$(cat /tmp/oldspeed)
@@ -65,7 +69,7 @@ lowPowerOff(){ # switch from lowpower to normal mode
                hciconfig hci0 up pscan
        fi
        wlstate=$(cat /tmp/wlstate)
-       if [ ! $wlstate ]; then
+       if [ -z "$wlstate" ]; then
                /etc/init.d/wl1251-init start
        fi
        pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
@@ -89,7 +93,7 @@ shutdown(){ # warns the user and shuts the pandora down
        }
        countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
        if [ $? -eq 0 ]; then
-       shutdown -h now
+       /sbin/shutdown -h now
        else
        su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser
        fi
@@ -98,7 +102,7 @@ shutdown(){ # warns the user and shuts the pandora down
 displayOn(){ # turns the display on
        #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
        #sleep 0.1s # looks cleaner, could flicker without
-       maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
+       maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
        oldbright=0
        if [ -f /tmp/oldbright ]; then
                oldbright=$(cat /tmp/oldbright)
@@ -114,11 +118,11 @@ displayOn(){ # turns the display on
 }
 
 displayOff(){ # turns the display off
-       brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
+       brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
        if [ $brightness -gt 0 ]; then
                echo $brightness > /tmp/oldbright
        fi
-       echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+       echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
        #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
 }
 
@@ -170,5 +174,5 @@ elif [[ "$2" == "lid" ]]; then
  fi
 debug && echo "powerstate=$powerstate"
 echo "$powerstate" > /tmp/powerstate
-fi
 
+rm -f /tmp/op_power.lock