| 1 | #! @SHELL@ |
| 2 | # |
| 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 |
| 86 | for f in "$srcfile"/* |
| 87 | do |
| 88 | test -f $f || continue |
| 89 | cat "$f" || return |
| 90 | done |
| 91 | fi |
| 92 | else |
| 93 | cat "$srcfile" || return |
| 94 | fi |
| 95 | echo "." |
| 96 | } |
| 97 | |
| 98 | docidr() { |
| 99 | if test "$cidr" = 1 |
| 100 | then |
| 101 | @PERL@ -e ' |
| 102 | eval "use Net::CIDR;"; |
| 103 | |
| 104 | while (<>) |
| 105 | { |
| 106 | unless ( $Net::CIDR::VERSION && |
| 107 | /^([a-fA-F0-9:\.]+[\-\/][a-fA-F0-9:\.]+)\s+(.*)$/) |
| 108 | { |
| 109 | print; |
| 110 | next; |
| 111 | } |
| 112 | |
| 113 | my ($net, $line)=($1, $2); |
| 114 | |
| 115 | foreach ( Net::CIDR::cidr2octets( |
| 116 | Net::CIDR::range2cidr($net))) |
| 117 | { |
| 118 | print "$_\t$line\n"; |
| 119 | } |
| 120 | } |
| 121 | ' |
| 122 | else |
| 123 | @CAT@ |
| 124 | fi |
| 125 | } |
| 126 | |
| 127 | get_access | docidr | @makedatprogpath@ - "$tmpfile" "$dstfile" || exit 1 |
| 128 | |
| 129 | if test "$hupfile" != "" |
| 130 | then |
| 131 | if test -f $hupfile |
| 132 | then |
| 133 | kill -HUP `cat "$hupfile"` |
| 134 | fi |
| 135 | fi |