lib/scripts/patch-scripts.bash
author paulson
Mon, 17 Jan 2000 14:10:32 +0100
changeset 8129 29e239c7b8c2
parent 6974 60b0e4bbe331
child 9789 7e5e6c47c0b5
permissions -rw-r--r--
Thm.instantiate no longer normalizes, but Drule.instantiate does

#
# $Id$
#
# patch-scripts.bash - relocate interpreter paths of executable scripts and
#   insert AUTO_BASH/AUTO_PERL values
#

## find binaries

function findbin()
{
  local BASE="$1"
  local BINARY=""

  BINARY=$(type -path "$BASE")

  if [ -n "$BINARY" ]; then
    echo "found $BINARY" >&2
    echo "$BINARY"
    return
  else
    echo "ERROR: $BASE not found!" >&2
    echo "$DEFAULT"
    return
  fi
}


## main

[ -z "$BASH_PATH" ] && BASH_PATH=$(findbin bash)
[ -z "$PERL_PATH" ] && PERL_PATH=$(findbin perl)
[ -z "$AUTO_BASH" ] && AUTO_BASH="$BASH_PATH"
[ -z "$AUTO_PERL" ] && AUTO_PERL="$PERL_PATH"

for FILE in $(find . -type f -print)
do
  if [ -x "$FILE" ]; then
    sed -e "s:^#!.*/bash:#!$BASH_PATH:" -e "s:^#!.*/perl:#!$PERL_PATH:" \
      -e "s:^AUTO_BASH=.*bash:AUTO_BASH=$AUTO_BASH:" \
      -e "s:^AUTO_PERL=.*perl:AUTO_PERL=$AUTO_PERL:" $FILE >$FILE~~
    if cmp -s $FILE $FILE~~; then
      rm $FILE~~
    else
      rm -f $FILE
      mv $FILE~~ $FILE
      chmod +x $FILE
      echo fixed $FILE
    fi
  fi
done