lib/scripts/patch-scripts.bash
author kleing
Mon Jun 21 10:25:57 2004 +0200 (2004-06-21)
changeset 14981 e73f8140af78
parent 10512 d34192966cd8
permissions -rw-r--r--
Merged in license change from Isabelle2004
     1 # -*- shell-script -*-
     2 # $Id$
     3 # Author: Markus Wenzel, TU Muenchen
     4 #
     5 # patch-scripts.bash - relocate interpreter paths of executable scripts and
     6 #   insert AUTO_BASH/AUTO_PERL values
     7 #
     8 
     9 ## find binaries
    10 
    11 function findbin()
    12 {
    13   local BASE="$1"
    14   local BINARY=""
    15 
    16   BINARY=$(type -path "$BASE")
    17 
    18   if [ -n "$BINARY" ]; then
    19     echo "found $BINARY" >&2
    20     echo "$BINARY"
    21     return
    22   else
    23     echo "ERROR: $BASE not found!" >&2
    24     echo "$DEFAULT"
    25     return
    26   fi
    27 }
    28 
    29 
    30 ## main
    31 
    32 [ -z "$BASH_PATH" ] && BASH_PATH=$(findbin bash)
    33 [ -z "$PERL_PATH" ] && PERL_PATH=$(findbin perl)
    34 [ -z "$AUTO_BASH" ] && AUTO_BASH="$BASH_PATH"
    35 [ -z "$AUTO_PERL" ] && AUTO_PERL="$PERL_PATH"
    36 
    37 for FILE in $(find . -type f -print)
    38 do
    39   if [ -x "$FILE" ]; then
    40     sed -e "s:^#!.*/bash:#!$BASH_PATH:" -e "s:^#!.*/perl:#!$PERL_PATH:" \
    41       -e "s:^AUTO_BASH=.*bash:AUTO_BASH=$AUTO_BASH:" \
    42       -e "s:^AUTO_PERL=.*perl:AUTO_PERL=$AUTO_PERL:" "$FILE" > "$FILE~~"
    43     if cmp -s "$FILE" "$FILE~~"; then
    44       rm "$FILE~~"
    45     else
    46       rm -f "$FILE"
    47       mv "$FILE~~" "$FILE"
    48       chmod +x "$FILE"
    49       echo "fixed $FILE"
    50     fi
    51   fi
    52 done