Merge branch 'vendor/GMP' into gcc441
[dragonfly.git] / contrib / amd / scripts / amd2ldif.in
1 #!@PERL@
2
3 $usage=<<EOU;
4 Usage $0 mapname base < mapfile >mapfile.ldif
5
6 mapname: name of the amd map beeing converted to ldif
7 base   : The LDAP search base. Do not forget the quotes!
8
9 This script should/could be used in a Makefile together
10 with ldif2ldbm(8C) to automagically update the ldap
11 databases and restart slapd whenever a master copy of
12 the maps have changed. Remember "cd /var/yp; make" ?
13 EOU
14
15 my $fmt = "%-12s: %s\n";
16 my $tfmt = "%-15s: %s\n";
17 my $mapname = $ARGV[0] or die $usage;
18 my $base = $ARGV[1] or die $usage;
19 $time = time();
20
21 print "dn: cn=amdmap timestamp, $base\n";
22 printf "$tfmt", "cn", "amdmap timestamp";
23 printf "$tfmt", "objectClass", "amdmapTimestamp";
24 printf "$tfmt", "amdmapTimestamp", $time;
25 print "\n";
26
27 my $line = "";
28 my $done = 0;
29
30 while (<STDIN>) {
31   chomp;
32   if (/\s*(.+)\\\s*/) {
33     if ($line) {
34       $line .= " ".$1;
35     } else {
36       $line = $1;
37     }
38     $done = 0;
39   } else {
40     s/^\s+//g;
41     $line .= $_;
42     $done = 1;
43   }
44   if ($done) {
45     my @vals = split(/\s+/,$line);
46     my $key = shift @vals;
47     my $entry;
48
49     print "dn: cn=amdmap $mapname\[$key\], $base\n";
50     printf "$fmt","cn","amdmap $mapname\[$key\]";
51     printf "$fmt","objectClass", "amdmap";
52     printf "$fmt","amdmapName", $mapname;
53     printf "$fmt","amdmapKey", $key;
54     printf "$fmt","amdmapValue", join(' ',@vals);
55     print "\n";
56     $line = ""; $done = 0;
57   }
58 }