Import Upstream version 0.69.0
[hcoop/debian/courier-authlib.git] / libs / makedat / makedat.in
CommitLineData
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
20prefix="@prefix@";
21exec_prefix="@exec_prefix@";
22
23srcfile=""
24dstfile=""
25tmpfile=""
26hupfile=""
27
28usage() {
29 echo "Usage: $0 -src=src -file=file -tmp=tmpfile -hup=hupfile [-cidr]" >&2
30 exit 1
31}
32
33cidr=""
34
35while test $# -gt 0
36do
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
62done
63
64if test "$dstfile" = ""
65then
66 usage
67fi
68
69if test "$srcfile" = ""
70then
71 usage
72fi
73
74if test "$tmpfile" = ""
75then
76 usage
77fi
78
79
80get_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
94docidr() {
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
124get_access | docidr | @makedatprogpath@ - "$tmpfile" "$dstfile" || exit 1
125
126if test "$hupfile" != ""
127then
128 if test -f $hupfile
129 then
130 kill -HUP `cat "$hupfile"`
131 fi
132fi