~samiam/MaraDNS

MaraDNS/build/fix.bang.path -rwxr-xr-x 1.8 KiB View raw
e83b594dSam Trenholme configure: Add Cygwin directions for making MaraDNS a service 4 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh

# Placed in the public domain 2002 by Sam Trenholme

# This is a script which fixes the bang path of a given program; e.g.
# we have a script which starts of #!/usr/bin/perl but perl is really in
# /usr/local/bin, this will make the bang path #!/usr/local/bin/perl

if [ $# -lt 1 ] ; then
	echo usage $0 script_to_fix_bang_path_of
	exit 1
fi

FILENAME="$1"

# Make sure that there is a file
if [ ! -f $FILENAME ] ; then
	echo Can not find the file $FILENAME
	exit 1
fi

# Make sure we have a bang path
# Deal with DOS newlines by zapping them
BANGPATH=`head -1 $1 | tr -d '\015'`
if ! echo $BANGPATH | egrep '^\#\!' > /dev/null ; then
	echo $FILENAME does not have a bangpath
	exit 1
fi

# See if the bang path points to something
BANGPATH=`echo $BANGPATH | cut -f2 -d\!`
# If it already does, we are gold
if [ -f $BANGPATH ] ; then
	chmod 755 $FILENAME
	exit 0
fi

# If not, see if the same script exists in /bin, /usr/bin, /usr/local/bin,
# /usr/share/bin, /usr/local/share/bin, /usr/share/local/bin, /sbin,
# /usr/sbin, /usr/local/sbin, /usr/share/sbin, /usr/local/share/sbin,
# or /usr/share/local/bin

SCRIPTNAME=`basename $BANGPATH`
DIRS="/ /usr/ /usr/local/ /usr/share/ /usr/local/share/ /usr/share/local/"
D=""
for dir in $DIRS ; do
	D="$D ${dir}bin ${dir}sbin"
done
DIRS=$D

# And, while we are at it, add anything in their $PATH
for dir in `echo $PATH | tr : ' '`; do
	DIRS="$DIRS $dir"
done

# Now, let us find out where that bang path should really point to
for dir in $DIRS ; do
	echo $dir/$SCRIPTNAME
	if [ -f $dir/$SCRIPTNAME ] ; then
		echo \#\!$dir/$SCRIPTNAME > $FILENAME.$$
		# Zap dos newlines as needed
		cat $FILENAME | tr -d '\015' >> $FILENAME.$$
		mv $FILENAME.$$ $FILENAME
		chmod 755 $FILENAME
		echo Bang path for $FILENAME fixed
		exit 0
	fi
done

echo Could not fix bang path for $FILENAME
exit 1