+ STATUS=FAILED
+ COLOR="\\033[31m"
+ fi
+
+ printf "[%7s]--- $PND_TASK_NAME ----------\n" "$STATUS"
+ if [ $PND_isInteractive -eq 1 ];then
+ printf "\r%s\033[70G[$COLOR%7s\033[m]\n" "$PND_TASK_NAME" "$STATUS" >&3
+ fi
+ unset PND_TASK_NAME
+ return $RC
+}
+
+PND_WaitFor() {
+ [ $# -gt 0 ]||return 1
+ local l_test="$1"
+ local l_name=${2:-"Wait succes of $1"}
+ local l_cnt=${3:-12}
+ local l_sleep=${4:-10}
+ local C=0
+ PND_BeginTask $l_name
+ while [ $C -lt $l_cnt ] && ! eval $l_test;do
+ sleep $l_sleep;C=$(($C + 1));
+ done
+ [ $C -lt $l_cnt ]
+ PND_EndTask
+}
+
+PND_Exec() {
+ local CMD="$*"
+ {
+ if [ $PND_ISEXEC -eq 0 ];then
+ PND_ISEXEC=1
+ exec 3>&1 #
+ fi
+ export PND_INTERACTIVE=2
+ $* 2>&1
+ RES=$(( $? + $PND_ERRORS ))
+ echo "<result>$RES</result>"
+ PND_ISEXEC=0
+ exec 3>&-
+ }|{
+ while read line;do
+ if echo "$line"|grep -q "<result>.*</result>";then
+ return $(( $(echo $line|sed 's/<[^>]*>//g') + $PND_ERRORS ))
+ elif ! echo "$line"| $(eval $PND_OUT_CHECK); then
+ PND_Error "$line";
+ else
+ PND_Print "$line";
+ fi
+ done
+ return $PND_ERRORS
+ }
+}
+
+
+
+#=============================================================================
+# Utility functions
+
+showHelp() {
+ cat <<endHELP
+Usage:
+ pnd_run.sh -p file.pnd -e cmd [-a args] [-b pndid] [-s path] [-c speed] [-d [path]] [-x] [-m] [-u]
+ -p file.pnd : Specify the pnd file to execute
+ -e cmd : Command to run
+ -a args : Arguments to the command
+ -b pndid : name of the directory mount-point ($UNION_MOUNT_DIR/pndid) (Default: name of the pnd file)
+ -s path : Directory in the union to start the command from
+ -o speed : Set the CPU speed
+ -d [path] : Use path as source of the overlay. (Default: pandora/appdata/pndid)
+ -x : Stop X before starting the apps
+ -m : Only mount the pnd, dont run it (-e become optional)
+ -u : Only umount the pnd, dont run it (-e become optional)
+endHELP
+}
+
+list_using_fs() {
+ for p in $(fuser -m $1 2>/dev/null);do ps hf $p;done
+}
+
+
+#=============================================================================
+# CPU speed functions
+PND_getCPUSpeed() {
+ cat /proc/pandora/cpu_mhz_max
+}
+
+PND_setCPUSpeed() {
+ unset CURRENTSPEED
+ if ! [ -f "$CPUSPEED_FILE" ] && [ ! -z "$PND_CPUSPEED" ]; then
+ if [ ${PND_CPUSPEED} -gt $(PND_getCPUSpeed) ]; then
+ CURRENTSPEED=$(PND_getCPUSpeed)
+ case "$(zenity --title="set cpu speed" --height=350 --list --column "id" --column "Please select" --hide-column=1 \
+ --text="$PND_NAME suggests to set the cpu speed to $PND_CPUSPEED MHz to make it run properly.\n\n Do you want to change the cpu speed? (current speed: $(PND_getCPUSpeed) MHz)\n\nWarning: Setting the clock speed above 600MHz can be unstable and it NOT recommended!" \
+ "yes" "Yes, set it to $PND_CPUSPEED MHz" \
+ "custom" "Yes, select custom value" \
+ "yessave" "Yes, set it to $PND_CPUSPEED MHz and don't ask again" \
+ "customsave" "Yes, set it to custom speed and don't ask again" \
+ "no" "No, don't change the speed" \
+ "nosave" "No, don't chage the speed and don't ask again")" in
+ "yes")
+ sudo $CPUSPEEDSCRIPT $PND_CPUSPEED
+ ;;
+ "custom")
+ sudo $CPUSPEEDSCRIPT
+ ;;
+ "customsave")
+ sudo $CPUSPEEDSCRIPT
+ zenity --info --title="Note" --text="Speed saved.\n\nTo re-enable this dialogue, please delete the file\n$CPUSPEED_FILE"
+ PND_getCPUSpeed > $CPUSPEED_FILE
+ ;;
+ "yessave")
+ zenity --info --title="Note" --text="Speed saved.\n\nTo re-enable this dialogue, please delete the file\n$CPUSPEED_FILE"
+ sudo $CPUSPEEDSCRIPT $PND_CPUSPEED
+ PND_getCPUSpeed > $CPUSPEED_FILE
+ ;;
+ "nosave")
+ unset CURRENTSPEED
+ zenity --info --title="Note" --text="Speed will not be changed.\n\nTo re-enable this dialogue, please delete the file\n$CPUSPEED_FILE"
+ echo 9999 > $CPUSPEED_FILE
+ ;;
+ *) unset CURRENTSPEED;;
+ esac
+ fi
+ elif [ "$PND_CPUSPEED" -lt "1500" ]; then
+ CURRENTSPEED=$(PND_getCPUSpeed)
+ echo Setting to CPU-Speed $PND_CPUSPEED MHz
+ sudo $CPUSPEEDSCRIPT $PND_CPUSPEED
+ fi
+}
+
+PND_resetCPUSpeed() {
+ if [ ! -z "$CURRENTSPEED" ]; then
+ sudo $CPUSPEEDSCRIPT $CURRENTSPEED
+ fi
+}
+
+#=============================================================================
+# X management functions
+
+PND_CloseX(){
+ if [ $CLOSE_X ]; then #the app doesnt want x to run, so we kill it and restart it once the app quits
+ if [ ! $(pidof X) ]; then
+ unset $CLOSE_X
+ 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
+ fi