discovery code now recognizes pnd files
[pandora-libraries.git] / testdata / scripts / pnd_run.sh
index d3f9083..eac2552 100644 (file)
@@ -1,6 +1,8 @@
 #!/bin/bash
  
 #input pnd_run.sh -p "/path/to/foobar.pnd" -e "exe" --a "arguments for exe"
+# -u to skip union mount
+# -b to override basename
 #output none
  
 ########################### FS NAMES NEED ADJUSTMENT #################
@@ -8,7 +10,7 @@
 # check if all vars are set to sensible values
  
 # parse arguments
-TEMP=`getopt -o p:e:a:: --long p-long,e-long:,a-long: -- "$@"`
+TEMP=`getopt -o p:e:a:b:u:: --long p-long,e-long:,a-long: -- "$@"`
  
 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  
@@ -19,10 +21,9 @@ while true ; do
         case "$1" in
                 -p|--p-long) echo "pnd set to \`$2'" ;PND=$2;shift 2;;
                 -e|--e-long) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;
+                -u) echo "u set, no union pls!";UNION=1;shift 2 ;;
+                -b) echo "BASENAME set to $2";BASENAME=$2;shift 2;;
                 -a|--a-long) 
-                        # a has an optional argument. As we are in quoted mode,
-                        # an empty parameter will be generated if its optional
-                        # argument is not found.
                         case "$2" in
                                 "") echo "no arguments"; shift 2 ;;
                                 *)  echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;
@@ -37,7 +38,11 @@ done
 #vars
 DFS=$(file -b $PND | awk '{ print $1 }') # is -p a zip iso or folder?
 MOUNTPOINT=$(df $PND | grep -vE '^Filesystem' | awk '{ print $6  }') #find out which mountpoint the pnd/folder is on
-BASENAME=$(basename "$PND" | cut -d'.' -f1) #get basename (strip extension if file) for union mountpoints etc, maybe  this should be changed to something specified inside the xml
+#if -b is set use that as basename, else generate it from PND
+#get basename (strip extension if file) for union mountpoints etc, maybe  this should be changed to something specified inside the xml
+if [ ! $BASENAME ]; then BASENAME=$(basename "$PND" | cut -d'.' -f1) ; fi
 oCWD=$(pwd)
 # add sanity check
  
@@ -58,26 +63,54 @@ else
 fi
  
 #create mountpoints
-#echo "
+echo "
 #will run:
 # create mountpoints
-mkdir -p /mnt/pnd/$BASENAME
-mkdir -p $MOUNTPOINT/appdata/$BASENAME
-mkdir -p /mnt/utmp/$BASENAME
+" 
+if [ ! -d /mnt/pnd/$BASENAME ]; then
+echo "mkdir -p /mnt/pnd/$BASENAME "
+fi
+if [ ! -d $MOUNTPOINT/appdata/$BASENAME ]; then
+echo "mkdir -p $MOUNTPOINT/appdata/$BASENAME "
+fi
+if [ ! -d /mnt/utmp/$BASENAME ]; then
+echo "mkdir -p /mnt/utmp/$BASENAME "
+fi 
  
 #mount
-$mntline #mount the pnd/folder
-mount -t unionfs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro unionfs /mnt/utmp/$BASENAME #union mount
-#start app
-cd /mnt/utmp/$BASENAME
-$EXENAME $ARGUMENTS 
-cd $oCWD
-#app exited
+if [ ! $UNION ] ; then
+        mount | grep "on /mnt/utmp/$BASENAME type" > /dev/null
+        if [ ! $? -eq 0 ]; then 
+                echo "
+                $mntline #mount the pnd/folder
+                #mount -t unionfs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro unionfs /mnt/utmp/$BASENAME #union mount
+                #aufs, one of those should work, bit unsure.
+                mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro none /mnt/utmp/$BASENAME #aufs?
+                #mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro aufs /mnt/utmp/$BASENAME #aufs?
+                "
+        else
+                echo "doh!"
+        fi
  
+        echo "
+        #start app
+        cd /mnt/utmp/$BASENAME
+        $EXENAME $ARGUMENTS 
+        cd $oCWD
+        #app exited
+        "
+else
+echo "
+        $mntline
+        cd /mnt/pnd/$BASENAME
+        $EXENAME $ARGUMENTS 
+        cd $oCWD
+"
+fi
+echo "
 #clean up
 umount /mnt/utmp/$BASENAME
 umount /mnt/pnd/$BASENAME
 rmdir /mnt/pnd/$BASENAME
 rmdir /mnt/utmp/$BASENAME
-#
\ No newline at end of file
+"