#!/opt/bin/perl5 $self = $0; $self =~ s!^.*/!!; $licence = "/u/sb/boot_bi/bin/liz.txt"; $target = "/u/sb/boot_bi/nach"; unless (open(LICENCE, "<$licence")) { die "$self: can't read file '$licence': $!\n"; } chop(@licence = ); close(LICENCE); unless (opendir(TARGET, $target)) { die "$self: can't read directory '$target': $!\n"; } @entry = readdir(TARGET); closedir(TARGET); $index = 0; foreach $file (sort special @entry) { next if $file eq '.'; next if $file eq '..'; next unless -f "$target/$file"; unless (open(FILE, "<$target/$file")) { warn "$self: can't read file '$target/$file': $!\n"; next; } $host = ''; $addr = ''; $ethr = ''; while () { chop; if (/^\s*hostname\s*=\s*(\S+)\s*$/) { $host = $1; } elsif (/^\s*ip-nr\s*=\s*(\S+)\s*$/) { $addr = $1; } elsif (/^\s*ether-nr\s*=\s*(\S+)\s*$/) { $ethr = $1; } else { } } close(FILE); if (($host eq '') || ($addr eq '') || ($ethr eq '')) { warn "$self: item missing in file '$file'!\n"; next; } @bytes = split(/[:.]/,$ethr); foreach $byte (@bytes) { $byte = sprintf("%.2x", hex($byte)) } $ethr = join('.',@bytes); unless (rename("$target/$file","$target/$file.bak")) { warn "$self: unable to rename '$file' to '$file.bak': $!\n"; next; } unless (open(FILE, ">$target/$file")) { warn "$self: can't write file '$target/$file': $!\n"; next; } ($snum,$akey) = ($licence[$index] =~ /T131="([\d-]+)";T132="([\d-]+)";/i); $licence[$index] .= $host; print FILE "hostname = $host\n"; print FILE "ip-nr = $addr\n"; print FILE "ether-nr = $ethr\n"; print FILE "pctcp-sernr = $snum\n"; print FILE "pctcp-authkey = $akey\n"; print FILE <<"VERBATIM"; domain = bi.sdm.de subnet-mask = 255.255.252.0 dns-server = 193.102.180.4 time-server = sun exe-server = sun spool-server = sun broadcast-address = 193.102.255.255 adm-server = sun completion-domain = bi.sdm.de sdm.de fi.sdm.de router = 193.102.180.110 VERBATIM close(FILE); $index++; } unless (rename($licence,"$licence.bak")) { warn "$self: unable to rename '$licence' to '$licence.bak': $!\n"; } unless (open(LICENCE, ">$licence")) { die "$self: can't write file '$licence': $!\n"; } foreach $line (@licence) { print LICENCE "$line\n"; } close(LICENCE); exit; sub special { my($i,$j); my($m,$n); ($i,$m) = ($a =~ /^([A-Za-z]+)(\d*)$/); ($j,$n) = ($b =~ /^([A-Za-z]+)(\d*)$/); if ($i eq $j) { return( $m <=> $n ); } else { return( $a cmp $b ); } } __END__