-if [ $1 ]; then cd $1; fi
-
-for x in $(pwd)/*
-do
-if [ -x $x ] && [ ! -d $x ] && [ ! $(echo $x | cut -d . -f 2 -s) ] ; then exe=$x; break; fi
-done
-BASENAMEnoex=$(basename "$exe" | cut -d'.' -f1)
-BASENAME=$(basename "$exe")
-rnd=$RANDOM;
-loc=$(dirname "$0")
-
-echo '
-<?xml version="1.0" encoding="UTF-8"?>
-<PXML xmlns="http://openpandora.org/namespaces/PXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PXML_schema.xsd">
-
- <application id="'$BASENAME-$rnd'">
-
- <exec command="'$BASENAME'"/>
-
- <title lang="en_US">'$BASENAMEnoex'</title>
- <title lang="de_DE">'$BASENAMEnoex' - German (lol!)</title><!--optional, only one title tag required-->
-
- <author name="'$USERNAME'" website="http://www.openpandora.org"/><!--Optional email and website, name required-->
-
- <version major="1" minor="1" release="1" build="2"/><!--This programs version-->
- <osversion major="1" minor="0" release="0" build="0"/><!--The minimum OS version required, optional-->
-
- <description lang="en_US">en_US Automatically generated pxml from'$(pwd)' exe='$BASENAME'</description>
- <description lang="de_DE">de_DE Automatisch generiertes pxml aus'$(pwd)' exe='$BASENAME'</description>
-
- <!-- if you want to provide an icon, uncomment the following line and set correct filename! -->
- <!-- <icon src="icon.png"/> -->
-
- <previewpics>'
-#add all images in the folder as preview pics
-for image in $(file -i -0 * | grep -a image | cut -d" " -f1)
-do
-echo " <pic src="$image"/>"
-done
-echo ' </previewpics>
-
- <!-- if you want to provide a manual, uncomment the following line and set correct values! -->
- <!-- <info name="'$BASENAMEnoex' manual" type="text/html" src="manual.html"/> -->
-
+
+help(){
+cat >&2 <<ENDHELP
+$0 [args] :
+-s|--src <src dir> : Define source directory (default: $SRCDIR)
+-n|--name <name> : Define the pnd base name (default: $PND_NAME)
+-d|--dest <dest dir> : Define destination directory (default: $DESTDIR)
+-a|--author <name> : programmers names (default: $AUTHOR)
+-v|--version <version> : Define the version (default: $VERSION)
+-w|--website <url> : Define the url (default: $WEBSITE)
+-b|--build <build id> : Define the build number (default: $BUILD)
+-f|--force : overide PXML.xml file if found
+-h|--help : show this screen
+ENDHELP
+}
+
+DEBUG(){
+ echo $*>&2
+}
+
+buildApplicationList(){
+ #output "<appname> [<desktopfile>]" lines
+ cd $DESTDIR
+ DESTLST=$(find $SRCDIR -name "*desktop";find $DESTDIR -name "*desktop")
+ if [ ! -z "$DESTLST" ];then
+ {
+ for d in $DESTLST;do
+ EXE=$(awk -F= '/Exec/{print $2}'<$d|awk '{print $1}'|head -1)
+ if [[ "x$EXE" != "x" ]];then
+ BIN=$(find . -executable -type f -name $(basename $EXE)|head -1)
+ echo ${BIN:-$EXE} $d
+ fi
+ done
+ }|sort|awk 'BEGIN{P=""}$1!=P{print}{P=$1}'
+ else
+ find . -executable -type f \! -name "*sh"
+ fi
+}
+
+getPATH(){
+ cd $DESTDIR
+ L=$(find . -type d -name bin)
+ echo $L|sed "s#\./#$(pwd)/#g;s# #:#g"
+}
+getLIBPATH(){
+ cd $DESTDIR
+ L=$(find . -type d -name lib)
+ echo $L|sed "s#\./#$(pwd)/#g;s# #:#g"
+}
+
+genLaunchScript() {
+ S="$DESTDIR/scripts/$(basename $1).sh"
+ if [ -e $S ];then
+ mv $S ${S}.old
+ fi
+ cat>$S<<ENDSCRIPT
+#!/bin/sh
+export PATH="$(getPATH):\${PATH:-"/usr/bin:/bin:/usr/local/bin"}"
+export LD_LIBRARY_PATH="$(getLIBPATH):\${LD_LIBRARY_PATH:-"/usr/lib:/lib"}"
+export HOME="/mnt/utmp/$PND_NAME" XDG_CONFIG_HOME="/mnt/utmp/$PND_NAME"
+
+if [ -d /mnt/utmp/$PND_NAME/share ];then
+ export XDG_DATA_DIRS=/mnt/utmp/$PND_NAME/share:\$XDG_DATA_DIRS:/usr/share
+fi
+export SDL_AUDIODRIVER="alsa"
+cd \$HOME
+[ -e "\$HOME/scripts/pre_script.sh" ] && . \$HOME/scripts/pre_script.sh
+if [ -e "\$HOME/scripts/post_script.sh" ];then
+ $1 \$*
+ . \$HOME/scripts/post_script.sh
+else
+ exec $1 \$*
+fi
+ENDSCRIPT
+ chmod 755 $S
+}
+
+desktop2application(){ #generate PXML application info out of a desktop file passed as parameter
+ DESK=$1
+ if [ ! -z "$DESK" ];then
+ DVERSION=$(awk -F= '$1=="Version"{print $2}'<$1)
+ if [ -z "$DVERSION" ] || [[ "$DVERSION" = "1.0" ]];then
+ DVERSION=$VERSION
+ fi
+ else
+ DVERSION=$VERSION
+ fi
+ MAJOR=$(echo $DVERSION|awk -F. '{print $1}')
+ MINOR=$(echo $DVERSION|awk -F. '{print $2}')
+ REL=$(echo $DVERSION|awk -F. '{print $3}')
+ MINOR=${MINOR:-"0"}
+ REL=${REL:-"0"}
+
+ # Exec --------------------------
+ echo " <exec command=\"scripts/${BASEB}.sh\"/>"
+
+ # title -------------------------
+ if [ ! -z "$DESK" ];then
+ #awk -F= '($1~/^Name/)||$1=="Name"{print $1" "$2}'<$1|while read DN DNV;do
+ awk -F= '($1~/^Name/&&/en_US/)||$1=="Name"{print $1" "$2}'<$1|while read DN DNV;do
+ l=$(echo $DN|sed 's/Name//;s/\[//;s/\]//')
+ echo " <title lang=\"${l:-"en_US"}\">$DNV</title>"
+ done
+ else
+ echo " <title lang=\"en_US\">$PND_NAME</title>"
+ fi
+ echo
+
+ # Author ------------------------
+ echo " <author name=\"$AUTHOR\" website=\"$WEBSITE\"/>"
+
+ # Version -----------------------
+ echo " <version major=\"$MAJOR\" minor=\"$MINOR\" release=\"$REL\" build=\"$BUILD\"/> <!--This programs version-->"
+
+ # OS Version --------------------
+ echo " <osversion major=\"1\" minor=\"0\" release=\"0\" build=\"0\"/> <!--The minimum OS version required-->"
+ echo
+
+ # Description -------------------
+ if [ ! -z "$DESK" ];then
+ #awk -F= '($1~/^Comment/)||$1=="Comment"{print $1" "$2}'<$1|while read DN DNV;do
+ awk -F= '($1~/^Comment/&&/en_US/)||$1=="Comment"{print $1" "$2}'<$1|while read DN DNV;do
+ l=$(echo $DN|sed 's/Comment//;s/\[//;s/\]//')
+ echo " <description lang=\"${l:-"en_US"}\">$DNV</description>"
+ done
+ else
+ echo " <description lang=\"en_US\">Automatically generated description from $(pwd) for PND=$PND_NAME</description>"
+ fi
+ echo
+
+ # Icon --------------------------
+ ICON=""
+ if [ ! -z "$DESK" ];then
+ ICON=$(awk -F= '$1~/^Icon/{print $2}'<$1)
+ fi
+ if [ ! -z "$ICON" ];then
+ F=$(find $DESTDIR -name ${ICON}.png|head -1)
+ if [ -z "$F" ];then
+ F=$DESTDIR/icon.png
+ fi
+ echo " <icon src="'"'$F'"/>'
+ if [ ! -e "$DESTDIR/icon.png" ] && [ ! -z "$(find $DESTDIR -name ${ICON}.png|head -1)" ];then
+ cp $(find $DESTDIR -name ${ICON}.png|head -1) $DESTDIR/icon.png
+ fi
+ elif [ -e "$DESTDIR/icon.png" ];then
+ echo " <icon src=\"$DESTDIR/icon.png\"/>"
+ else
+ echo " <!--<icon src=\"path/to/icon.pnd\"/>-->"
+ fi
+ echo
+
+ # Preview pics ------------------
+ if [ ! -z "$(find $DESTDIR/previews -name "$BASEB*")" ];then
+ echo " <previewpics>"
+ for i in $(find $DESTDIR/previews -name "$BASEB*");do
+ echo " <pic src=\"previews/$(basename $i)\"/>"
+ done
+ echo " </previewpics>"
+ else
+ cat <<ENDASSO
+<!--
+ <previewpics>
+ <pic src="previews/${BASEB}.png"/>
+ </previewpics>
+-->
+ENDASSO
+ fi
+ echo
+
+ # Documentation -----------------
+ HTML=$(find $DESTDIR -type d -name index.html|head -1)
+ DOC=$DESTDIR/readme.txt
+ if [ ! -z "$HTML" ];then
+ for i in $(find $DESTDIR -type d -name index.html);do
+ echo " <info name=\"${BASEB} documentation\" type=\"text/html\" src=\"$i\"/>"
+ done
+ elif [ -e "$DOC" ];then
+ echo " <info name=\"${BASEB} documentation\" type=\"text/plain\" src=\"$DOC\"/>"
+ else
+ echo " <!--<info name=\"${BASEB} documentation\" type=\"text/plain\" src=\"$DOC\"/>-->"
+ fi
+
+ # Categories --------------------
+ cat <<ENDCATEGORIES
+