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/pandora/appdata)] [-x close x before launching(script needs to be started with nohup for this to work]
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.
10 # look at the comments in the nox part, adjust
12 #use "lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq > whitelist" with nothing running to generate the whitelist
14 #launch the script with nohup for -x to work!
17 #make sure to only use free loop devices!
21 TEMP=`getopt -o p:e:a:b:s:m::u::n::x:: -- "$@"`
23 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
25 # Note the quotes around `$TEMP': they are essential!
30 -p) echo "pnd set to \`$2'" ;PND=$2;shift 2;;
31 -e) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;
32 -n) echo "n set, no union pls!";NOUNION=1;shift 2;;
33 -b) echo "BASENAME set to $2";BASENAME=$2;shift 2;;
34 -s) echo "startdir set to $2";STARTDIR=$2;shift 2;;
35 -m) echo "mount";mount=1;shift 2;;
36 -u) echo "umount";umount=1;shift 2;;
37 -x) echo "no x";nox=1;shift 2;;
40 "") echo "no arguments"; shift 2 ;;
41 *) echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;
44 *) echo "Error while parsing arguments!" ; exit 1 ;;
49 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/pandora/appdata)] [-x close x before launching(script needs to be started with nohup for this to work]"
53 applist=$(lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq)
54 whitelist=$(cat ~/pndtest/whitelist) #adjust this to a fixed whitelist, maybe in the config dir
55 filteredlist=$(echo -e "$applist\n\n$whitelist\n\n$whitelist" | sort | uniq -u) #whitelist appended two times so those items are always removed
56 if [ ${#filteredlist} -ge 1 ]; then
57 message=$(echo -e "The following applications are still running, are you sure you want to close x? \n$filteredlist")
59 xmessage -center "$message", -buttons yes,no
63 sudo /etc/init.d/gdm stop
67 xmessage -center "killing x, nothing of value will be lost", -buttons ok,cancel
71 # close x now, do we want to use gdm stop or just kill x?
72 sudo /etc/init.d/gdm stop
78 DFS=$(file -b $PND | awk '{ print $1 }') #is -p a zip/iso or folder?
79 MOUNTPOINT=$(df $PND | sed -ne 's/.*\% \(\S*\)/\1/p' | tail -n1)
80 echo "mountpoint: $MOUNTPOINT"
81 #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
84 #BASENAME really should be something sensible and somewhat unique
85 #if -b is set use that as basename, else generate it from PND
86 #get basename (strip extension if file) for union mountpoints etc, maybe this should be changed to something specified inside the xml
87 #this should probably be changed to .... something more sensible
88 if [ ! $BASENAME ]; then BASENAME=$(basename "$PND" | cut -d'.' -f1) ; fi
95 if [ $DFS = ISO ]; then
97 usedminor=$( ls -l /dev/loop* | awk '{print $6}')
98 freeminor=$( echo -e "$(seq 0 64)\n$usedminor" | sort -rn | uniq -u | tail -n1)
99 sudo mknod -m777 /dev/loop$freeminor b 7 $freeminor
100 sudo losetup /dev/loop$freeminor $PND
102 mntline="sudo mount /dev/loop$freeminor /mnt/pnd/$BASENAME/"
103 # mntline="sudo mount -o loop,mode=777 $PND /mnt/pnd/$BASENAME"
104 echo "Filetype is $DFS"
105 elif [ $DFS = Zip ]; then
106 mntline="fuse-zip $PND /mnt/pnd/$BASENAME -o ro,fmask=000" #TOTALLY untested right now
107 echo "Filetype is $DFS"
108 elif [ $DFS = directory ]; then
109 mntline="sudo mount --bind -o ro $PND /mnt/pnd/$BASENAME"
110 #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
111 echo "Filetype is $DFS"
117 #create mountpoints, check if they exist already first to avoid annoying error messages
118 if [ ! -d /mnt/pnd/$BASENAME ]; then sudo mkdir -p /mnt/pnd/$BASENAME ; fi
119 if [ ! -d $MOUNTPOINT/pandora/appdata/$BASENAME ]; then sudo mkdir -p $MOUNTPOINT/pandora/appdata/$BASENAME; fi
120 if [ ! -d /mnt/utmp/$BASENAME ]; then sudo mkdir -p /mnt/utmp/$BASENAME; fi
124 if [ ! $NOUNION ] && [ ! $umount ]; then
125 #is the union already mounted? if not mount evrything, else launch the stuff
126 mount | grep "on /mnt/utmp/$BASENAME type" # > /dev/null
127 if [ ! $? -eq 0 ]; then
129 $mntline #mount the pnd/folder
130 echo "mounting union!"
131 sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/pandora/appdata/$BASENAME=rw+nolwh:/mnt/pnd/$BASENAME=rr none /mnt/utmp/$BASENAME # put union on top
134 echo "Union already mounted"
137 if [ $mount ]; then echo "mounted /mnt/utmp/$BASENAME"; exit 1; fi;
140 cd /mnt/utmp/$BASENAME
141 if [ $STARTDIR ]; then cd $STARTDIR; fi #cd to folder specified by the optional arg -s
142 #echo "/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS"
143 #/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS
144 LD_LIBRARY_PATH=/mnt/utmp/$BASENAME ./$EXENAME $ARGUMENTS
145 #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
146 PID=`pidof -o %PPID -x $EXENAME`
150 PID=`pidof -o %PPID -x $EXENAME`
155 cd $oCWD #cd out of the mountpoint so we can umount, doesnt really matter to where...
157 elif [ ! $umount ]; then
159 if [ $mount ]; then echo "mounted /mnt/pnd/$BASENAME"; exit 1; fi;
160 cd /mnt/pnd/$BASENAME
161 if [ $STARTDIR ]; then cd $STARTDIR; fi
163 #/lib/ld-linux.so.2 --library-path /mnt/pnd/$BASENAME/ $EXENAME $ARGUMENTS
164 ./$EXENAME $ARGUMENTS
165 LD_LIBRARY_PATH=/mnt/pnd/$BASENAME ./$EXENAME $ARGUMENTS
166 #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
167 PID=`pidof -o %PPID -x $EXENAME`
171 PID=`pidof -o %PPID -x $EXENAME`
177 echo "-u set, nothing to do here"
182 if [ ! $NOUNION ] ; then sudo umount /mnt/utmp/$BASENAME; fi #umount union if -u wasnt set
183 if [ $NOUNION ] ; then sudo umount /mnt/pnd/$BASENAME; fi #umount iso if -u WAS set
184 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
185 if [ ! $NOUNION ] ; then
186 sudo umount /mnt/pnd/$BASENAME
187 sudo rmdir $MOUNTPOINT/pandora/appdata/$BASENAME/.wh..wh.plnk
188 sudo rmdir $MOUNTPOINT/pandora/appdata/$BASENAME/.wh..wh..tmp
189 sudo rmdir $MOUNTPOINT/pandora/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