Initial commit of libpnd 0.0.5 so we cna restart with GIT
[pandora-libraries.git] / testdata / scripts / pnd_run.sh
1 #!/bin/bash
2  
3 #input pnd_run.sh -p "/path/to/foobar.pnd" -e "exe" --a "arguments for exe"
4 #output none
5  
6 ########################### FS NAMES NEED ADJUSTMENT #################
7 #todo
8 # check if all vars are set to sensible values
9  
10 # parse arguments
11 TEMP=`getopt -o p:e:a:: --long p-long,e-long:,a-long: -- "$@"`
12  
13 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
14  
15 # Note the quotes around `$TEMP': they are essential!
16 eval set -- "$TEMP"
17  
18 while true ; do
19         case "$1" in
20                 -p|--p-long) echo "pnd set to \`$2'" ;PND=$2;shift 2;;
21                 -e|--e-long) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;
22                 -a|--a-long) 
23                         # a has an optional argument. As we are in quoted mode,
24                         # an empty parameter will be generated if its optional
25                         # argument is not found.
26                         case "$2" in
27                                 "") echo "no arguments"; shift 2 ;;
28                                 *)  echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;
29                         esac ;;
30                 --) shift ; break ;;
31                 *) echo "Error while parsing arguments!" ; exit 1 ;;
32         esac
33 done
34  
35 # add sanity check
36  
37 #vars
38 DFS=$(file -b $PND | awk '{ print $1 }') # is -p a zip iso or folder?
39 MOUNTPOINT=$(df $PND | grep -vE '^Filesystem' | awk '{ print $6  }') #find out which mountpoint the pnd/folder is on
40 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
41 oCWD=$(pwd)
42 # add sanity check
43  
44 #detect fs
45 if [ $DFS = ISO ]; then
46         mntline="mount -o loop $PND /mnt/pnd/$BASENAME"
47         echo "Filetype is $DFS"
48 elif [ $DFS = Zip ]; then
49         mntline="fuse-zip $PND /mnt/pnd/$BASENAME -oro" #should be reight now
50         echo "Filetype is $DFS"
51 elif [ $DFS = directory ]; then
52         mntline="mount --bind -o ro $PND /mnt/pnd/$BASENAME"
53 #we bind the folder, now it can be treated in a unified way ATENTION: -o ro doesnt work for --bind at least on 25, on 26 its possible using remount, may have changed on 27
54         echo "Filetype is $DFS"
55 else
56         echo "error"
57         exit 1;
58 fi
59  
60 #create mountpoints
61 #echo "
62 #will run:
63 # create mountpoints
64 mkdir -p /mnt/pnd/$BASENAME
65 mkdir -p $MOUNTPOINT/appdata/$BASENAME
66 mkdir -p /mnt/utmp/$BASENAME
67  
68 #mount
69 $mntline #mount the pnd/folder
70 mount -t unionfs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro unionfs /mnt/utmp/$BASENAME #union mount
71  
72 #start app
73 cd /mnt/utmp/$BASENAME
74 $EXENAME $ARGUMENTS 
75 cd $oCWD
76 #app exited
77  
78 #clean up
79 umount /mnt/utmp/$BASENAME
80 umount /mnt/pnd/$BASENAME
81 rmdir /mnt/pnd/$BASENAME
82 rmdir /mnt/utmp/$BASENAME
83 #