d9898ee8 |
1 | #! @SHELL@ |
2 | # |
d9898ee8 |
3 | # |
4 | # Copyright 1998 - 2004 Double Precision, Inc. See COPYING for |
5 | # distribution information. |
6 | # |
7 | # Generic wrapper for makedat. |
8 | # |
9 | # Usage: makedat.sh -src=src -file=file -tmp=tmpfile -hup=hupfile [ -cidr ] |
10 | # |
11 | # Create [file] from [src]. [src] can be either a plain text file, or a |
12 | # directory. [tmpfile] is used. if [hupfile] is specified and it exists, |
13 | # this file contains a PID, which is SIGHUPed. |
14 | # |
15 | # -cidr - [src] contains a list of IP netblocks. Expand entries in [src] |
16 | # that use CIDR or start-end notation using the Net::CIDR Perl |
17 | # module. Download the Net::CIDR module from |
18 | # http://www.cpan.org/authors/id/M/MR/MRSAM/ |
19 | |
20 | prefix="@prefix@"; |
21 | exec_prefix="@exec_prefix@"; |
22 | |
23 | srcfile="" |
24 | dstfile="" |
25 | tmpfile="" |
26 | hupfile="" |
27 | |
28 | usage() { |
29 | echo "Usage: $0 -src=src -file=file -tmp=tmpfile -hup=hupfile [-cidr]" >&2 |
30 | exit 1 |
31 | } |
32 | |
33 | cidr="" |
34 | |
35 | while test $# -gt 0 |
36 | do |
37 | case $1 in |
38 | -cidr) |
39 | cidr=1 |
40 | shift |
41 | ;; |
42 | -src=*) |
43 | srcfile=`echo "$1" | sed 's/-src=//'`; |
44 | shift |
45 | ;; |
46 | -tmp=*) |
47 | tmpfile=`echo "$1" | sed 's/-tmp=//'`; |
48 | shift |
49 | ;; |
50 | -file=*) |
51 | dstfile=`echo "$1" | sed 's/-file=//'`; |
52 | shift |
53 | ;; |
54 | -hup=*) |
55 | hupfile=`echo "$1" | sed 's/-hup=//'`; |
56 | shift |
57 | ;; |
58 | *) |
59 | usage |
60 | ;; |
61 | esac |
62 | done |
63 | |
64 | if test "$dstfile" = "" |
65 | then |
66 | usage |
67 | fi |
68 | |
69 | if test "$srcfile" = "" |
70 | then |
71 | usage |
72 | fi |
73 | |
74 | if test "$tmpfile" = "" |
75 | then |
76 | usage |
77 | fi |
78 | |
79 | |
80 | get_access() { |
81 | |
82 | if test -d "$srcfile" |
83 | then |
84 | if test "$srcfile" != "CVS" |
85 | then |
0e333c05 |
86 | find -L "$srcfile" -maxdepth 1 -type f -not -name "*~" -not -regex ".*\.dpkg-[a-z]*" -exec cat {} \; |
d9898ee8 |
87 | fi |
88 | else |
89 | cat "$srcfile" || return |
90 | fi |
91 | echo "." |
92 | } |
93 | |
94 | docidr() { |
95 | if test "$cidr" = 1 |
96 | then |
97 | @PERL@ -e ' |
98 | eval "use Net::CIDR;"; |
99 | |
100 | while (<>) |
101 | { |
102 | unless ( $Net::CIDR::VERSION && |
103 | /^([a-fA-F0-9:\.]+[\-\/][a-fA-F0-9:\.]+)\s+(.*)$/) |
104 | { |
105 | print; |
106 | next; |
107 | } |
108 | |
109 | my ($net, $line)=($1, $2); |
110 | |
111 | foreach ( Net::CIDR::cidr2octets( |
112 | Net::CIDR::range2cidr($net))) |
113 | { |
0e333c05 |
114 | print ":" if $net =~ /:/; |
d9898ee8 |
115 | print "$_\t$line\n"; |
116 | } |
117 | } |
118 | ' |
119 | else |
120 | @CAT@ |
121 | fi |
122 | } |
123 | |
124 | get_access | docidr | @makedatprogpath@ - "$tmpfile" "$dstfile" || exit 1 |
125 | |
126 | if test "$hupfile" != "" |
127 | then |
128 | if test -f $hupfile |
129 | then |
130 | kill -HUP `cat "$hupfile"` |
131 | fi |
132 | fi |