#!/bin/sh

# This script changes perl scripts to reference perl in an accurate location
# Not really need anymore XXX


exit 0
if test $# -lt 2
then
    echo "Usage: fix_perl location-of-perl-executable script-to-update"
    exit 1
fi

PERL=$1
SCRIPT=$2
TEMP=/tmp/fixperl.$USER

# figure out the script name and the args...

orig=`head -1 $2` 

discr=`echo $orig | grep -c '#! '`

if test $discr = 1
then
  pgm=`echo $orig | awk -F! '{print $2}' | awk '{print $1}'`
  args=`echo $orig | awk '{print $3 " " $4 " " $5 " " $6 }'`
else
  pgm=`echo $orig | awk '{print $1}' | sed -e 's/#\!//'`
  args=`echo $orig | awk '{print $2 " " $3 " " $4 " " $5}'`
fi

echo pgm = $pgm
echo args = $args

# See if script is correct already

if test "$pgm" = "$1"
then
#	echo ok
	exit 0
fi

# Make sure this is likely to work

pcount=`echo $pgm | grep -c perl`
if test "$pcount" != 1; then
	echo "fix_perl won't work, $SCRIPT is not a perl script"
	exit 1
fi

# Fix it

# echo fixing it

/bin/rm -f $TEMP
echo "#! $1 $args" > $TEMP
tail +2l $2 >> $TEMP
/bin/rm -f $2.orig
mv $2 $2.orig
cp $TEMP $2
chmod +x $2
/bin/rm -f $TEMP
