lib/scripts/patch-scripts.bash
author wenzelm
Wed May 14 18:38:15 1997 +0200 (1997-05-14)
changeset 3185 7a6c933d51d0
parent 3052 b7922b9d7acd
child 4508 f102cb0140fe
permissions -rw-r--r--
tuned;
wenzelm@2651
     1
#
wenzelm@2651
     2
# $Id$
wenzelm@2651
     3
#
wenzelm@2744
     4
# patch-scripts.bash - relocate interpreter paths of executable scripts.
wenzelm@2651
     5
#
wenzelm@2651
     6
wenzelm@2651
     7
## find binaries
wenzelm@2651
     8
wenzelm@2651
     9
function findbin()
wenzelm@2651
    10
{
wenzelm@2651
    11
  local DEFAULT="$1"
wenzelm@3052
    12
  local BASE=$(basename "$DEFAULT")
wenzelm@2651
    13
  local BINARY=""
wenzelm@2651
    14
wenzelm@3052
    15
  BINARY=$(type -path "$BASE")
wenzelm@3052
    16
wenzelm@3052
    17
  if [ -n "$BINARY" ]; then
wenzelm@3052
    18
    echo "using $BINARY" >&2
wenzelm@3052
    19
    echo "$BINARY"
wenzelm@3052
    20
    return
wenzelm@3052
    21
  elif [ -f "$DEFAULT" ]; then
wenzelm@2760
    22
    echo "using $DEFAULT" >&2
wenzelm@2651
    23
    echo "$DEFAULT"
wenzelm@2651
    24
    return
wenzelm@3052
    25
  else
wenzelm@3052
    26
    echo "WARNING: $BASE not found!" >&2
wenzelm@3052
    27
    echo "$DEFAULT"
wenzelm@3052
    28
    return
wenzelm@2651
    29
  fi
wenzelm@2651
    30
}
wenzelm@2651
    31
wenzelm@2651
    32
wenzelm@2651
    33
## main
wenzelm@2651
    34
wenzelm@2651
    35
BASH=$(findbin /bin/bash)
wenzelm@2651
    36
PERL=$(findbin /usr/bin/perl)
wenzelm@2651
    37
wenzelm@2651
    38
for FILE in $(find . -type f -print)
wenzelm@2651
    39
do
wenzelm@2651
    40
  if [ -x "$FILE" ]; then
wenzelm@2651
    41
    sed -e "s:^#!.*/bash:#!$BASH:" -e "s:^#!.*/perl:#!$PERL:" $FILE >$FILE~~
wenzelm@2651
    42
    if cmp -s $FILE $FILE~~; then
wenzelm@2651
    43
      rm $FILE~~
wenzelm@2651
    44
    else
wenzelm@2651
    45
      rm -f $FILE
wenzelm@2651
    46
      mv $FILE~~ $FILE
wenzelm@2651
    47
      chmod +x $FILE
wenzelm@2651
    48
      echo fixed $FILE
wenzelm@2651
    49
    fi
wenzelm@2651
    50
  fi
wenzelm@2651
    51
done