2651
|
1 |
#
|
|
2 |
# $Id$
|
|
3 |
#
|
6974
|
4 |
# patch-scripts.bash - relocate interpreter paths of executable scripts and
|
|
5 |
# insert AUTO_BASH/AUTO_PERL values
|
2651
|
6 |
#
|
|
7 |
|
|
8 |
## find binaries
|
|
9 |
|
|
10 |
function findbin()
|
|
11 |
{
|
6974
|
12 |
local BASE="$1"
|
2651
|
13 |
local BINARY=""
|
|
14 |
|
3052
|
15 |
BINARY=$(type -path "$BASE")
|
|
16 |
|
|
17 |
if [ -n "$BINARY" ]; then
|
6974
|
18 |
echo "found $BINARY" >&2
|
3052
|
19 |
echo "$BINARY"
|
|
20 |
return
|
|
21 |
else
|
4508
|
22 |
echo "ERROR: $BASE not found!" >&2
|
3052
|
23 |
echo "$DEFAULT"
|
|
24 |
return
|
2651
|
25 |
fi
|
|
26 |
}
|
|
27 |
|
|
28 |
|
|
29 |
## main
|
|
30 |
|
6974
|
31 |
[ -z "$BASH_PATH" ] && BASH_PATH=$(findbin bash)
|
|
32 |
[ -z "$PERL_PATH" ] && PERL_PATH=$(findbin perl)
|
|
33 |
[ -z "$AUTO_BASH" ] && AUTO_BASH="$BASH_PATH"
|
|
34 |
[ -z "$AUTO_PERL" ] && AUTO_PERL="$PERL_PATH"
|
2651
|
35 |
|
|
36 |
for FILE in $(find . -type f -print)
|
|
37 |
do
|
|
38 |
if [ -x "$FILE" ]; then
|
6974
|
39 |
sed -e "s:^#!.*/bash:#!$BASH_PATH:" -e "s:^#!.*/perl:#!$PERL_PATH:" \
|
|
40 |
-e "s:^AUTO_BASH=.*bash:AUTO_BASH=$AUTO_BASH:" \
|
|
41 |
-e "s:^AUTO_PERL=.*perl:AUTO_PERL=$AUTO_PERL:" $FILE >$FILE~~
|
2651
|
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
|