lib/scripts/patch-scripts.bash
author wenzelm
Fri, 02 Jan 1998 13:24:53 +0100
changeset 4508 f102cb0140fe
parent 3052 b7922b9d7acd
child 6082 590f9e3bf4d8
permissions -rw-r--r--
do require perl;

#
# $Id$
#
# patch-scripts.bash - relocate interpreter paths of executable scripts.
#

## find binaries

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

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

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


## main

BASH=$(findbin /bin/bash)
PERL=$(findbin /usr/bin/perl)

for FILE in $(find . -type f -print)
do
  if [ -x "$FILE" ]; then
    sed -e "s:^#!.*/bash:#!$BASH:" -e "s:^#!.*/perl:#!$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