lib/scripts/patch-scripts.bash
author wenzelm
Sat, 03 Jun 2000 23:59:37 +0200
changeset 9032 ad0b9f048bbf
parent 6974 60b0e4bbe331
child 9789 7e5e6c47c0b5
permissions -rw-r--r--
block commands: marginal comment;
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
#
6974
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
     4
# patch-scripts.bash - relocate interpreter paths of executable scripts and
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
     5
#   insert AUTO_BASH/AUTO_PERL values
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     6
#
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     7
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     8
## find binaries
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
     9
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    10
function findbin()
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    11
{
6974
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    12
  local BASE="$1"
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
6974
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    18
    echo "found $BINARY" >&2
3052
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
  else
4508
f102cb0140fe do require perl;
wenzelm
parents: 3052
diff changeset
    22
    echo "ERROR: $BASE not found!" >&2
3052
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    23
    echo "$DEFAULT"
b7922b9d7acd no longer forces default;
wenzelm
parents: 2760
diff changeset
    24
    return
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    25
  fi
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    26
}
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    27
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    28
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    29
## main
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    30
6974
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    31
[ -z "$BASH_PATH" ] && BASH_PATH=$(findbin bash)
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    32
[ -z "$PERL_PATH" ] && PERL_PATH=$(findbin perl)
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    33
[ -z "$AUTO_BASH" ] && AUTO_BASH="$BASH_PATH"
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    34
[ -z "$AUTO_PERL" ] && AUTO_PERL="$PERL_PATH"
2651
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    35
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    36
for FILE in $(find . -type f -print)
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    37
do
60d8d06f84a5 file moved here;
wenzelm
parents:
diff changeset
    38
  if [ -x "$FILE" ]; then
6974
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    39
    sed -e "s:^#!.*/bash:#!$BASH_PATH:" -e "s:^#!.*/perl:#!$PERL_PATH:" \
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    40
      -e "s:^AUTO_BASH=.*bash:AUTO_BASH=$AUTO_BASH:" \
60b0e4bbe331 may get BASH_PATH etc. from env;
wenzelm
parents: 6105
diff changeset
    41
      -e "s:^AUTO_PERL=.*perl:AUTO_PERL=$AUTO_PERL:" $FILE >$FILE~~
2651
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