3 #Usage: pnd_run.sh -p your.pnd -e executeable [-a \"(arguments)\"] [ -s \"cd to folder inside pnd\"] [-u (skip union)] [-b override BASENAME (name of mountpoint/appdata)]
4 # -n to skip union mount, should probably be removed before release
6 # arguments can be inside -e, -a is optional
8 #/etc/sudoers needs to be adjusted if you touch any of the sudo lines in the wrong place.
12 TEMP=`getopt -o p:e:a:b:s:m::u::n:: -- "$@"`
14 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
16 # Note the quotes around `$TEMP': they are essential!
21 -p) echo "pnd set to \`$2'" ;PND=$2;shift 2;;
22 -e) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;
23 -n) echo "u set, no union pls!";NOUNION=1;shift 2;;
24 -b) echo "BASENAME set to $2";BASENAME=$2;shift 2;;
25 -s) echo "startdir set to $2";STARTDIR=$2;shift 2;;
26 -m) echo "mount";mount=1;shift 2;;
27 -u) echo "umount";umount=1;shift 2;;
30 "") echo "no arguments"; shift 2 ;;
31 *) echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;
34 *) echo "Error while parsing arguments!" ; exit 1 ;;
38 if [ ! $PND ] || [ ! $EXENAME ]; then
39 echo "Usage: pnd_run.sh -p your.pnd -e executeable [-a \"(arguments)\"] [ -s \"cd to folder inside pnd\"] [-u (skip union)] [-b override BASENAME (name of mountpoint/appdata)]"
44 DFS=$(file -b $PND | awk '{ print $1 }') #is -p a zip/iso or folder?
45 MOUNTPOINT=$(df $PND | grep -vE '^Filesystem' | awk '{ print $6 }') #find out which mountpoint the pnd/folder is on, there probably is a better way to do this
48 #BASENAME really should be something sensible and somewhat unique
49 #if -b is set use that as basename, else generate it from PND
50 #get basename (strip extension if file) for union mountpoints etc, maybe this should be changed to something specified inside the xml
51 #this should probably be changed to .... something more sensible
52 if [ ! $BASENAME ]; then BASENAME=$(basename "$PND" | cut -d'.' -f1) ; fi
59 if [ $DFS = ISO ]; then
60 mntline="sudo mount -o loop,mode=777 $PND /mnt/pnd/$BASENAME"
61 echo "Filetype is $DFS"
62 elif [ $DFS = Zip ]; then
63 mntline="fuse-zip $PND /mnt/pnd/$BASENAME -o ro,fmask=000" #TOTALLY untested right now
64 echo "Filetype is $DFS"
65 elif [ $DFS = directory ]; then
66 mntline="sudo mount --bind -o ro $PND /mnt/pnd/$BASENAME"
67 #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
68 echo "Filetype is $DFS"
74 #create mountpoints, check if they exist already first to avoid annoying error messages
75 if [ ! -d /mnt/pnd/$BASENAME ]; then sudo mkdir -p /mnt/pnd/$BASENAME ; fi
76 if [ ! -d $MOUNTPOINT/appdata/$BASENAME ]; then sudo mkdir -p $MOUNTPOINT/appdata/$BASENAME; fi
77 if [ ! -d /mnt/utmp/$BASENAME ]; then sudo mkdir -p /mnt/utmp/$BASENAME; fi
81 if [ ! $NOUNION ] && [ ! $umount ]; then
82 #is the union already mounted? if not mount evrything, else launch the stuff
83 mount | grep "on /mnt/utmp/$BASENAME type" # > /dev/null
84 if [ ! $? -eq 0 ]; then
85 $mntline #mount the pnd/folder
86 echo "mounting union!"
87 sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw+nolwh:/mnt/pnd/$BASENAME=rr none /mnt/utmp/$BASENAME # put union on top
90 echo "Union already mounted"
93 if [ $mount ]; then echo "mounted /mnt/utmp/$BASENAME"; exit 1; fi;
96 cd /mnt/utmp/$BASENAME
97 if [ $STARTDIR ]; then cd $STARTDIR; fi #cd to folder specified by the optional arg -s
100 #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
101 PID=`pidof -o %PPID -x $EXENAME`
102 while [ "$PID" -gt 0 ]
105 PID=`pidof -o %PPID -x $EXENAME`
110 cd $oCWD #cd out of the mountpoint so we can umount, doesnt really matter to where...
112 elif [ ! $umount ]; then
114 if [ $mount ]; then echo "mounted /mnt/pnd/$BASENAME"; exit 1; fi;
115 cd /mnt/pnd/$BASENAME
116 if [ $STARTDIR ]; then cd $STARTDIR; fi
118 ./$EXENAME $ARGUMENTS
120 #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
121 PID=`pidof -o %PPID -x $EXENAME`
122 while [ "$PID" -gt 0 ]
125 PID=`pidof -o %PPID -x $EXENAME`
131 echo "-u set, nothing to do here"
137 if [ ! $NOUNION ] ; then sudo umount /mnt/utmp/$BASENAME; fi #umount union if -u wasnt set
138 if [ $NOUNION ] ; then sudo umount /mnt/pnd/$BASENAME; fi #umount iso if -u WAS set
139 if [ $? -eq 0 ]; then # check if the umount was successfull, if it wasnt it would mean that theres still something running so we skip this stuff
140 if [ ! $NOUNION ] ; then
141 sudo umount /mnt/pnd/$BASENAME
142 sudo rmdir $MOUNTPOINT/appdata/$BASENAME/.wh..wh.plink
143 sudo rmdir $MOUNTPOINT/appdata/$BASENAME/
144 sudo rmdir /mnt/utmp/$BASENAME;
146 sudo rmdir /mnt/pnd/$BASENAME