lib/scripts/patch-scripts.bash
author paulson
Thu, 05 Jun 1997 13:22:25 +0200
changeset 3403 6cc663f6d62e
parent 3052 b7922b9d7acd
child 4508 f102cb0140fe
permissions -rw-r--r--
A slight simplification of optstring The new "simpset" keyword in the "recdef" declaration
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     1
#
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     2
# $Id$
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     3
#
2744
34993cdffbf7 tuned comment;
wenzelm
parents: 2651
diff changeset
     4
# patch-scripts.bash - relocate interpreter paths of executable scripts.
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     5
#
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     6
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     7
## find binaries
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     8
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     9
function findbin()
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    10
{
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    11
  local DEFAULT="$1"
3052
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    12
  local BASE=$(basename "$DEFAULT")
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    13
  local BINARY=""
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    14
3052
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    15
  BINARY=$(type -path "$BASE")
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    16
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    17
  if [ -n "$BINARY" ]; then
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    18
    echo "using $BINARY" >&2
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    19
    echo "$BINARY"
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    20
    return
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    21
  elif [ -f "$DEFAULT" ]; then
2760
c2a90e8b4831 tuned comments;
wenzelm
parents: 2744
diff changeset
    22
    echo "using $DEFAULT" >&2
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    23
    echo "$DEFAULT"
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    24
    return
3052
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    25
  else
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    26
    echo "WARNING: $BASE not found!" >&2
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    27
    echo "$DEFAULT"
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    28
    return
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    29
  fi
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    30
}
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    31
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    32
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    33
## main
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    34
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    35
BASH=$(findbin /bin/bash)
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    36
PERL=$(findbin /usr/bin/perl)
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    37
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    38
for FILE in $(find . -type f -print)
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    39
do
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    40
  if [ -x "$FILE" ]; then
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    41
    sed -e "s:^#!.*/bash:#!$BASH:" -e "s:^#!.*/perl:#!$PERL:" $FILE >$FILE~~
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    42
    if cmp -s $FILE $FILE~~; then
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    43
      rm $FILE~~
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    44
    else
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    45
      rm -f $FILE
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    46
      mv $FILE~~ $FILE
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    47
      chmod +x $FILE
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    48
      echo fixed $FILE
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    49
    fi
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    50
  fi
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    51
done