#!/bin/sh # klik wrapper 0.7.1 # by probono at myrealbox.com # genericized - allows moving the AppDir around APPNAME="DHWPageViewer" SUBSTUSR="" ARGS="" ######### there should be no need to edit below # cd to the AppDir DIRNAME=`cd \`dirname $0\` && pwd` cd $DIRNAME # our normal prefix PRE="$DIRNAME/usr" # link substitute for /usr in case we need it if [ -n "$SUBSTUSR" ] then sudo ln -sf $PRE $SUBSTUSR PRE="$SUBSTUSR" fi # determine whether we want to run in GUI mode export GUIMODE=$(tty -s ; echo $?) # ( echo $GUIMODE | grep 1 >/dev/null ) # && echo "Running in GUI mode" # determine DIALOG if [ -z $DIALOG ] then dialog=Xdialog pidof -x kdesktop >/dev/null && DIALOG=kdialog pidof -x gnome-panel >/dev/null && DIALOG=zenity # if we are running GNOME fi # replace relative with absolute paths in command line arguments, thanks bfree NEWCMD=$(perl -e '$newcmd=shift(@ARGV);foreach $arg (@ARGV){ @part=split(/\=/,$arg); foreach $part (@part){ (-e "$ENV{PWD}/$part") && ($part="$ENV{PWD}/$part");}$newcmd.=" ".join ("=",@part);} print "$newcmd";' $@) set -- $NEWCMD # set paths export PATH=$DIRNAME/sbin:$DIRNAME/bin:$PRE/sbin:$PRE/bin:$PRE/X11R6/bin:$PRE/local/sbin:$PRE/local/bin:$PRE/games:$PATH export LD_LIBRARY_PATH=$DIRNAME/lib:$PRE/lib/:$DIRNAME/opt/kde3/lib:$DIRNAME/usr/X11R6/lib/:$LD_LIBRARY_PATH export LD_PRELOAD=$PRE/lib/libQtGui.so.4:$PRE/lib/libQtCore.so.4 # support for KDE export KDEDIRS=$PRE/:$KDEDIRS # support for man pages (interpreted by KDE) export MANPATH=$PRE/share/man:$PRE/X11R6/man:$MANPATH # support for PYTHON MYPYTHONPATH=$(find $PRE/lib/python2.3/site-packages/ -type d -printf %p: 2>/dev/null) MYPYTHONPATH2=$(find $PRE/lib/python2.4/site-packages/ -type d -printf %p: 2>/dev/null) export PYTHONPATH=$MYPYTHONPATH:$MYPYTHONPATH2:$PYTHONPATH # support for PERL export PERL5LIB=./local/lib/perl/5.8.4:./local/share/perl/5.8.4:./lib/perl5:./share/perl5:./lib/perl/5.8:./share/perl/5.8:./local/lib/site_perl # support for GTK # still to be done, as patching seems to do the trick # $GTK_EXE_PREFIX=$PRE # see http://www-eleves-isia.cma.fr/documentation/GtkDoc/gtk/gtk-running.html # if commandline arguments are passed, use the first argument as the name of the application to be called, and remove $1 from $@ if [ $1 ] ; then APPNAME=$1; shift; fi # ask the user which application to use if APPNAME is not correct if [ ! $(which $APPNAME) ] then BINARIES="$(find $DIRNAME/sbin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $DIRNAME/bin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $PRE/sbin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $PRE/bin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $PRE/X11R6/bin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $PRE/local/sbin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $PRE/local/bin/* -perm +1 -type f 2>/dev/null) $BINARIES" BINARIES="$(find $PRE/games/* -perm +1 -type f 2>/dev/null) $BINARIES" for BINARI in $BINARIES do OPTIONSTRING="$BINARI $(basename $BINARI) $OPTIONSTRING" done export APPNAME=$(kdialog --menu "" --caption "" $OPTIONSTRING) fi BINARY=$(which $APPNAME) || exit 1 # kdialog --error "Can't find the binary to run." --caption "" # doesn't work: # if [ -z $BINARY ] ; then echo "Can't find the binary to run." > /dev/stderr; exit 1 ; fi #perl -pi -e "s|/usr|$PRE|g" $BINARY # check whether this is a commandline app, in this case run it in konsole # TODO: find a more reliable way to thell whether an app is a commandline tool KONSOLE="konsole --noclose --notoolbar --nomenubar --caption $(basename $APPNAME) -e" [ $DIALOG = "zenity" ] && KONSOLE="gnome-terminal -x " ( ldd $BINARY | grep libX11 >/dev/null ) && export KONSOLE="" # if we don't run in GUI mode, then we don't need konsole since we are on a cmdline # ( echo $GUIMODE | grep 0 >/dev/null ) && export KONSOLE="" ( tty | grep ^/dev/tty >/dev/null ) && export KONSOLE="" ( tty | grep ^/dev/pts >/dev/null ) && export KONSOLE="" # start the app together with all command line arguments cd $PRE/ # neccessary for patched apps $KONSOLE $BINARY $ARGS "$@" if [ "$?" = "0" ] then while pidof -x $BINARY &>/dev/null; do sleep 1; done else RESULT="error" fi # remove link substitute for /usr in case we needed it if [ -n "$SUBSTUSR" ] then sudo rm -f $SUBSTUSR fi if [ "$RESULT" = "error" ] then exit 1 else exit 0 fi