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