pnd_run.sh: restore fb0 too
[pandora-libraries.git] / testdata / scripts / pnd_run.sh
index d521849..c851920 100755 (executable)
@@ -259,7 +259,7 @@ PND_RestartX(){
 show_mounted_info(){
        echo "+++++++"
        echo "Loopback devices :"
-       sudo losetup -a
+       sudo /sbin/losetup -a
        echo "Are mounted on :"
        mount|grep loop
        echo "For these Union :"
@@ -284,10 +284,10 @@ noMoreProcessUnion() {
 }
 
 mountPnd() {
-       MOUNT_TARGET=${1:-$PND_MOUNT_DIR}
+       MOUNT_TARGET="${1:-$PND_MOUNT_DIR}"
        if ! is_pnd_mounted;then
                #check if pnd is already attached to loop 
-               LOOP=$(losetup -a | grep "$PND" | tail -n1 | awk -F: '{print $1}')
+               LOOP=$(/sbin/losetup -a | grep "$PND" | tail -n1 | awk -F: '{print $1}')
                #check if the loop device is already mounted
                if ! [ -z "$LOOP" ];then
                        echo "Found a loop ($LOOP), using it"
@@ -314,8 +314,8 @@ mountPnd() {
                        #detect fs
                        case $PND_FSTYPE in
                        ISO)
-                               /sbin/losetup $FREELOOP "$PND" #attach the pnd to the loop device
-                               mntline="mount" #setup the mountline for later
+                               /sbin/losetup -r $FREELOOP "$PND" #attach the pnd to the loop device
+                               mntline="mount -o ro" #setup the mountline for later
                                mntdev="${FREELOOP}"
                                ;;
                        directory)
@@ -325,8 +325,8 @@ mountPnd() {
                                mntdev="${PND}"
                                ;;
                        Squashfs)
-                               /sbin/losetup $FREELOOP "$PND" #attach the pnd to the loop device
-                               mntline="mount -t squashfs"
+                               /sbin/losetup -r $FREELOOP "$PND" #attach the pnd to the loop device
+                               mntline="mount -t squashfs -o ro"
                                mntdev="${FREELOOP}"
                                ;;
                        *)
@@ -443,11 +443,11 @@ cleanups() {
 
        # Clean the loopback device
        if [ $PND_FSTYPE = ISO ] || [ $PND_FSTYPE = Squashfs ]; then # check if we where running an iso, clean up loop device if we did
-               LOOP=$(losetup -a | grep "$(basename $PND)" | tail -n1 | awk -F: '{print $1}')
+               LOOP=$(/sbin/losetup -a | grep "$(basename $PND)" | tail -n1 | awk -F: '{print $1}')
                /sbin/losetup -d $LOOP
                #rm $LOOP
        fi
-       losetup -a|cut -d':' -f 1|while read l;do
+       /sbin/losetup -a|cut -d':' -f 1|while read l;do
                if ! mount|grep -q $l;then
                        echo "WARNING Found $l loop as unused. flushing"
                        /sbin/losetup -d $l
@@ -458,18 +458,22 @@ cleanups() {
 }
 
 umountPnd() {
+       MOUNT_TARGET="${1:-$PND_MOUNT_DIR}"
        if is_pnd_mounted;then
                PND_WaitFor noMoreProcessPnd "Waiting the PND mount dir to be free"
-               umount "$PND_MOUNT_DIR/$PND_NAME"
+               umount "$MOUNT_TARGET/$PND_NAME"
        fi
        if is_pnd_mounted; then
                echo WARNING umount PND failed, didnt clean up. Process still using this FS :
-               list_using_fs "$PND_MOUNT_DIR/$PND_NAME"
+               list_using_fs "$MOUNT_TARGET/$PND_NAME"
                show_mounted_info
        else
                # removing the now useless mountpoint
-               if [ -d $PND_MOUNT_DIR/$PND_NAME ];then
-                       rmdir "$PND_MOUNT_DIR/$PND_NAME"
+               if [ -d "$MOUNT_TARGET/$PND_NAME" ];then
+                       rmdir "$MOUNT_TARGET/$PND_NAME"
+               fi
+               if [ -h "$PND_MOUNT_DIR/$PND_NAME" ];then
+                       rm "$PND_MOUNT_DIR/$PND_NAME"
                fi
 
                # All went well, cleaning
@@ -504,7 +508,7 @@ umountUnion() {
                        fi
                fi
                # Try umounting the PND
-               umountPnd
+               umountPnd $UNION_MOUNT_DIR
        fi
 }
 
@@ -533,11 +537,14 @@ runApp() {
        fi
 
        export XDG_CONFIG_HOME="$UNION_MOUNT_DIR/$PND_NAME"
+       export REAL_HOME="$HOME"
+       export HOME="$UNION_MOUNT_DIR/$PND_NAME"
 
        if echo "$EXENAME"|grep -q ^\.\/;then
                "$EXENAME" $ARGUMENTS
        else
                "./$EXENAME" $ARGUMENTS
+       fi
        RC=$?
 
        #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
@@ -546,6 +553,7 @@ runApp() {
                sleep 10s
                PID=`pidof -o %PPID -x \"$EXENAME\"`
        done
+       export HOME="$REAL_HOME"
        return $RC
 }
 
@@ -577,6 +585,7 @@ main() {
                        PND_EndTask
                fi
                oPWD=$(pwd)
+               old_fb0_geometry=$(fbset -fb /dev/fb0 -s | grep geometry | awk '{print $2, $3, $4, $5, $6}')
                if [ -e "${APPDATADIR}/PND_pre_script.sh" ]; then
                        PND_BeginTask "Starting user configured pre-script"
                        . ${APPDATADIR}/PND_pre_script.sh # Sourcing so it can shared vars with post-script ;)
@@ -601,6 +610,12 @@ main() {
                        PND_resetCPUSpeed
                        PND_EndTask
                fi
+               PND_BeginTask "Restoring the frame buffer status"
+               fbset -fb /dev/fb0 -g $old_fb0_geometry
+               if ! lsof /dev/fb1 > /dev/null; then
+                       ofbset -fb /dev/fb1 -mem 0 -size 0 0 -en 0
+               fi
+               PND_EndTask
                PND_BeginTask "uMount the PND"
                umountUnion
                PND_EndTask