10512
|
1 |
# -*- shell-script -*-
|
2651
|
2 |
# $Id$
|
9789
|
3 |
# Author: Markus Wenzel, TU Muenchen
|
2651
|
4 |
#
|
6974
|
5 |
# patch-scripts.bash - relocate interpreter paths of executable scripts and
|
|
6 |
# insert AUTO_BASH/AUTO_PERL values
|
2651
|
7 |
#
|
|
8 |
|
|
9 |
## find binaries
|
|
10 |
|
|
11 |
function findbin()
|
|
12 |
{
|
6974
|
13 |
local BASE="$1"
|
2651
|
14 |
local BINARY=""
|
|
15 |
|
3052
|
16 |
BINARY=$(type -path "$BASE")
|
|
17 |
|
|
18 |
if [ -n "$BINARY" ]; then
|
6974
|
19 |
echo "found $BINARY" >&2
|
3052
|
20 |
echo "$BINARY"
|
|
21 |
return
|
|
22 |
else
|
4508
|
23 |
echo "ERROR: $BASE not found!" >&2
|
3052
|
24 |
echo "$DEFAULT"
|
|
25 |
return
|
2651
|
26 |
fi
|
|
27 |
}
|
|
28 |
|
|
29 |
|
|
30 |
## main
|
|
31 |
|
6974
|
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"
|
2651
|
36 |
|
|
37 |
for FILE in $(find . -type f -print)
|
|
38 |
do
|
|
39 |
if [ -x "$FILE" ]; then
|
6974
|
40 |
sed -e "s:^#!.*/bash:#!$BASH_PATH:" -e "s:^#!.*/perl:#!$PERL_PATH:" \
|
|
41 |
-e "s:^AUTO_BASH=.*bash:AUTO_BASH=$AUTO_BASH:" \
|
9789
|
42 |
-e "s:^AUTO_PERL=.*perl:AUTO_PERL=$AUTO_PERL:" "$FILE" > "$FILE~~"
|
|
43 |
if cmp -s "$FILE" "$FILE~~"; then
|
|
44 |
rm "$FILE~~"
|
2651
|
45 |
else
|
9789
|
46 |
rm -f "$FILE"
|
|
47 |
mv "$FILE~~" "$FILE"
|
|
48 |
chmod +x "$FILE"
|
|
49 |
echo "fixed $FILE"
|
2651
|
50 |
fi
|
|
51 |
fi
|
|
52 |
done
|