# Silly install script to ensure correct #! lines
# in wish scripts. Michael Weller (eowmob@exp-math.uni-essen.de)
# Use at will, no copyright for this silly file.
#
# Change to find wishx if you like:
WISHNAME=wish

# Sigh, the usual which alias for bash doesn't work here.. ok we'll do it by hand
PATHDIR=`echo $PATH|sed 's/:/ /g'`
WISH=""
for i in $PATHDIR
do
	if [ -x $i/$WISHNAME ]
	then
		WISH=$i/$WISHNAME
		break
	fi
done
if [ -z "$WISH" ]
then
	echo "Sorry, can't locate a $WISHNAME binary."
	exit 1
fi

if [ $# -lt 2 ]
then
cat <<EOM
Usage: install-wish destdir wish-files

copies wishfiles to destdir/basename(wish-files) removing
any #! entry in the first line and placing a correct #! line
for wish in it instead.
EOM
fi
destdir=$1
shift
for i in $*
do
	base=`basename $i`
	echo "#!$WISH -f" >$destdir/$base
# Sorry for the ugly sed line, but I didn't the idea of an additional
# sed-file, btw the sed script does delete any #! line that is in the first line
# of the file..
	sed '1b1
n
:1
/^#!.*$/d
n' <$i >>$destdir/$base
	chmod 755 $destdir/$base
done
