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