2 #needs some serious cleanup!
4 #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)] [-x close x before launching(script needs to be started with nohup for this to work]
5 # -n to skip union mount, should probably be removed before release
7 # arguments can be inside -e, -a is optional
9 #/etc/sudoers needs to be adjusted if you touch any of the sudo lines in the wrong place.
11 # look at the comments in the nox part, adjust
13 #use "lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq > whitelist" with nothing running to generate the whitelist
15 #launch the script with nohup for -x to work!
18 #make sure to only use free loop devices!
22 TEMP=`getopt -o p:e:a:b:s:m::u::n::x:: -- "$@"`
24 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
26 # Note the quotes around `$TEMP': they are essential!
31 -p) echo "pnd set to \`$2'" ;PND=$2;shift 2;;
32 -e) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;
33 -n) echo "n set, no union pls!";NOUNION=1;shift 2;;
34 -b) echo "BASENAME set to $2";BASENAME=$2;shift 2;;
35 -s) echo "startdir set to $2";STARTDIR=$2;shift 2;;
36 -m) echo "mount";mount=1;shift 2;;
37 -u) echo "umount";umount=1;shift 2;;
38 -x) echo "no x";nox=1;shift 2;;
41 "") echo "no arguments"; shift 2 ;;
42 *) echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;
45 *) echo "Error while parsing arguments!" ; exit 1 ;;
50 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)] [-x close x before launching(script needs to be started with nohup for this to work]"
54 applist=$(lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq)
55 whitelist=$(cat ~/pndtest/whitelist) #adjust this to a fixed whitelist, maybe in the config dir
56 filteredlist=$(echo -e "$applist\n\n$whitelist\n\n$whitelist" | sort | uniq -u) #whitelist appended two times so those items are always removed
57 if [ ${#filteredlist} -ge 1 ]; then
58 message=$(echo -e "The following applications are still running, are you sure you want to close x? \n$filteredlist")
60 xmessage -center "$message", -buttons yes,no
64 sudo /etc/init.d/gdm stop
68 xmessage -center "killing x, nothing of value will be lost", -buttons ok,cancel
72 # close x now, do we want to use gdm stop or just kill x?
73 sudo /etc/init.d/gdm stop
79 DFS=$(file -b $PND | awk '{ print $1 }') #is -p a zip/iso or folder?
80 MOUNTPOINT=$(df $PND | sed -ne 's/.*\% \(\S*\)/\1/p' | tail -n1)
81 echo "mountpoint: $MOUNTPOINT"
82 #MOUNTPOINT=$(df -h $PND | grep -E '[1-9]%' | awk '{ print $6 }') #find out which mountpoint the pnd/folder is on, there probably is a better way to do this
85 #BASENAME really should be something sensible and somewhat unique
86 #if -b is set use that as basename, else generate it from PND
87 #get basename (strip extension if file) for union mountpoints etc, maybe this should be changed to something specified inside the xml
88 #this should probably be changed to .... something more sensible
89 if [ ! $BASENAME ]; then BASENAME=$(basename "$PND" | cut -d'.' -f1) ; fi
96 if [ $DFS = ISO ]; then
98 usedminor=$( ls -l /dev/loop* | awk '{print $6}')
99 freeminor=$( echo -e "$(seq 0 64)\n$usedminor" | sort -rn | uniq -u | tail -n1)
100 sudo mknod -m777 /dev/loop$freeminor b 7 $freeminor
101 sudo losetup /dev/loop$freeminor $PND
103 mntline="sudo mount /dev/loop$freeminor /mnt/pnd/$BASENAME/"
104 # mntline="sudo mount -o loop,mode=777 $PND /mnt/pnd/$BASENAME"
105 echo "Filetype is $DFS"
106 elif [ $DFS = Zip ]; then
107 mntline="fuse-zip $PND /mnt/pnd/$BASENAME -o ro,fmask=000" #TOTALLY untested right now
108 echo "Filetype is $DFS"
109 elif [ $DFS = directory ]; then
110 mntline="sudo mount --bind -o ro $PND /mnt/pnd/$BASENAME"
111 #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
112 echo "Filetype is $DFS"
118 #create mountpoints, check if they exist already first to avoid annoying error messages
119 if [ ! -d /mnt/pnd/$BASENAME ]; then sudo mkdir -p /mnt/pnd/$BASENAME ; fi
120 if [ ! -d $MOUNTPOINT/appdata/$BASENAME ]; then sudo mkdir -p $MOUNTPOINT/appdata/$BASENAME; fi
121 if [ ! -d /mnt/utmp/$BASENAME ]; then sudo mkdir -p /mnt/utmp/$BASENAME; fi
125 if [ ! $NOUNION ] && [ ! $umount ]; then
126 #is the union already mounted? if not mount evrything, else launch the stuff
127 mount | grep "on /mnt/utmp/$BASENAME type" # > /dev/null
128 if [ ! $? -eq 0 ]; then
130 $mntline #mount the pnd/folder
131 echo "mounting union!"
132 sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw+nolwh:/mnt/pnd/$BASENAME=rr none /mnt/utmp/$BASENAME # put union on top
135 echo "Union already mounted"
138 if [ $mount ]; then echo "mounted /mnt/utmp/$BASENAME"; exit 1; fi;
141 cd /mnt/utmp/$BASENAME
142 if [ $STARTDIR ]; then cd $STARTDIR; fi #cd to folder specified by the optional arg -s
143 #echo "/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS"
144 #/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS
145 LD_LIBRARY_PATH=/mnt/utmp/$BASENAME ./$EXENAME $ARGUMENTS
146 #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
147 PID=`pidof -o %PPID -x $EXENAME`
151 PID=`pidof -o %PPID -x $EXENAME`
156 cd $oCWD #cd out of the mountpoint so we can umount, doesnt really matter to where...
158 elif [ ! $umount ]; then
160 if [ $mount ]; then echo "mounted /mnt/pnd/$BASENAME"; exit 1; fi;
161 cd /mnt/pnd/$BASENAME
162 if [ $STARTDIR ]; then cd $STARTDIR; fi
164 #/lib/ld-linux.so.2 --library-path /mnt/pnd/$BASENAME/ $EXENAME $ARGUMENTS
165 ./$EXENAME $ARGUMENTS
166 LD_LIBRARY_PATH=/mnt/pnd/$BASENAME ./$EXENAME $ARGUMENTS
167 #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
168 PID=`pidof -o %PPID -x $EXENAME`
172 PID=`pidof -o %PPID -x $EXENAME`
178 echo "-u set, nothing to do here"
183 if [ ! $NOUNION ] ; then sudo umount /mnt/utmp/$BASENAME; fi #umount union if -u wasnt set
184 if [ $NOUNION ] ; then sudo umount /mnt/pnd/$BASENAME; fi #umount iso if -u WAS set
185 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, this WILL lead to clutter if it happens, so we should make damn sure it never happens
186 if [ ! $NOUNION ] ; then
187 sudo umount /mnt/pnd/$BASENAME
188 sudo rmdir $MOUNTPOINT/appdata/$BASENAME/.wh..wh.plink
189 sudo rmdir $MOUNTPOINT/appdata/$BASENAME/
190 sudo rmdir /mnt/utmp/$BASENAME;
192 if [ $DFS = ISO ]; then
193 sudo losetup -d /dev/loop$freeminor
194 sudo rm /dev/loop$freeminor
196 sudo rmdir /mnt/pnd/$BASENAME
199 echo "starting x in 5s"
201 sudo /etc/init.d/gdm start