+if [ ! $NOUNION ] && [ ! $umount ]; then
+ #is the union already mounted? if not mount evrything, else launch the stuff
+ mount | grep "on /mnt/utmp/$BASENAME type" # > /dev/null
+ if [ ! $? -eq 0 ]; then
+ $mntline #mount the pnd/folder
+ echo "mounting union!"
+ sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw+nolwh:/mnt/pnd/$BASENAME=rr none /mnt/utmp/$BASENAME # put union on top
+
+ else
+ echo "Union already mounted"
+ fi
+
+ if [ $mount ]; then echo "mounted /mnt/utmp/$BASENAME"; exit 1; fi;
+
+ #start app
+ cd /mnt/utmp/$BASENAME
+ if [ $STARTDIR ]; then cd $STARTDIR; fi #cd to folder specified by the optional arg -s
+ ./$EXENAME $ARGUMENTS
+
+#the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
+ PID=`pidof -o %PPID -x $EXENAME`
+ while [ "$PID" -gt 0 ]
+ do
+ sleep 10s
+ PID=`pidof -o %PPID -x $EXENAME`
+ done
+ echo end
+
+ #app exited
+ cd $oCWD #cd out of the mountpoint so we can umount, doesnt really matter to where...
+
+elif [ ! $umount ]; then
+ $mntline
+ if [ $mount ]; then echo "mounted /mnt/pnd/$BASENAME"; exit 1; fi;
+ cd /mnt/pnd/$BASENAME
+ if [ $STARTDIR ]; then cd $STARTDIR; fi
+ echo $(pwd)
+ ./$EXENAME $ARGUMENTS
+
+#the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
+ PID=`pidof -o %PPID -x $EXENAME`
+ while [ "$PID" -gt 0 ]
+ do
+ sleep 10s
+ PID=`pidof -o %PPID -x $EXENAME`
+ done
+ echo end
+
+ cd $oCWD