-main() {
- if [ $nox ]; then #the app doesnt want x to run, so we kill it and restart it once the app quits
- if [ ! $(pidof X) ]; then
- unset $nox
- else
- applist=$(lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq)
- whitelist=$(cat ~/pndtest/whitelist) #adjust this to a fixed whitelist, maybe in the config dir
- filteredlist=$(echo -e "$applist\n\n$whitelist\n\n$whitelist" | sort | uniq -u) #whitelist appended two times so those items are always removed
- if [ ${#filteredlist} -ge 1 ]; then
- message=$(echo -e "The following applications are still running, are you sure you want to close x? \n$filteredlist")
- echo -e "?ae[34me[30m?"
- xmessage -center "$message", -buttons yes,no
- if [ $? = 102 ]; then
- exit 1
- fi
- sudo /etc/init.d/slim-init stop
- sleep 5s
- else
- echo -e "?ae[34me[30m?"
- xmessage -center "killing x, nothing of value will be lost", -buttons ok,cancel
- if [ $? = 102 ]; then
- exit 1
- fi
- # close x now, do we want to use slim stop or just kill x?
- sudo /etc/init.d/slim-init stop
- sleep 5s
+cleanups() {
+ #delete folders created by aufs if empty
+ rmdir -rf "${APPDATADIR}/.wh..wh.plnk" 2>/dev/null
+ rmdir -rf "${APPDATADIR}/.wh..wh..tmp" 2>/dev/null
+ rmdir "${APPDATADIR}/.wh..wh.orph" 2>/dev/null
+ rm "${APPDATADIR}/.aufs.xino" 2>/dev/null
+
+ #delete appdata folder and ancestors if _empty_
+ rmdir -p "${APPDATADIR}" 2>/dev/null
+
+ # Clean the loopback device
+ if [ $PND_FSTYPE = ISO ] || [ $PND_FSTYPE = Squashfs ]; then # check if we where running an iso, clean up loop device if we did
+ LOOP=$(/sbin/losetup -a | grep "$(basename $PND)" | tail -n1 | awk -F: '{print $1}')
+ /sbin/losetup -d $LOOP
+ #rm $LOOP
+ fi
+ /sbin/losetup -a|cut -d':' -f 1|while read l;do
+ if ! mount|grep -q $l;then
+ echo "WARNING Found $l loop as unused. flushing"
+ /sbin/losetup -d $l
+ fi
+ done
+
+ echo cleanup done
+}
+
+umountPnd() {
+ MOUNT_TARGET="${1:-$PND_MOUNT_DIR}"
+ if is_pnd_mounted;then
+ PND_WaitFor noMoreProcessPnd "Waiting the PND mount dir to be free"
+ umount "$MOUNT_TARGET/$PND_NAME"
+ fi
+ if is_pnd_mounted; then
+ echo WARNING umount PND failed, didnt clean up. Process still using this FS :
+ list_using_fs "$MOUNT_TARGET/$PND_NAME"
+ show_mounted_info
+ else
+ # removing the now useless mountpoint
+ if [ -d "$MOUNT_TARGET/$PND_NAME" ];then
+ rmdir "$MOUNT_TARGET/$PND_NAME"
+ fi
+ if [ -h "$PND_MOUNT_DIR/$PND_NAME" ];then
+ rm "$PND_MOUNT_DIR/$PND_NAME"
+ fi
+
+ # All went well, cleaning
+ cleanups
+ fi
+}
+
+umountUnion() {
+ # Are we root yet ?
+ if [ $(id -u) -ne 0 ];then
+ sudo /usr/pandora/scripts/pnd_run.sh -u -p "$PND" -b "$PND_NAME"
+ return $?
+ fi
+
+ # Make sure the Union FS is unmounted
+ #PND_INTERACTIVE=2
+ if is_union_mounted;then
+ PND_WaitFor noMoreProcessUnion "Waiting the Union to be available"
+ umount "$UNION_MOUNT_DIR/$PND_NAME" #umount union
+ fi
+ if is_union_mounted; then
+ echo "WARNING umount UNION failed, didnt clean up. Process still using this FS :"
+ list_using_fs "$UNION_MOUNT_DIR/$PND_NAME"
+ show_mounted_info
+ else
+ # the Union is umounted, removing the now empty mountpoint
+ if [[ "$PND_MOUNT_DIR" != "$UNION_MOUNT_DIR" ]];then
+ if [ -d "$UNION_MOUNT_DIR/$PND_NAME" ];then
+ rmdir "$UNION_MOUNT_DIR/$PND_NAME"
+ elif [ -e "$UNION_MOUNT_DIR/$PND_NAME" ];then
+ rm "$UNION_MOUNT_DIR/$PND_NAME" >/dev/null 2>&1 # as it might be a symlink