#!/usr/bin/perl $origserver="172.31.100.254"; # changed from $origserver="192.168.0.254" $orignetwork="172.31.100.0"; # changed from $orignetwork="192.168.0.0" $orignetmask="255.255.255.0"; # the following line is buggy as it outputs "BROADCAST=aaa.bbb.ccc.ddd" it will be corrected $origbroadcast = `/bin/ipcalc -b $orignetwork $orignetmask`; # correction code for above bug added in following line @obcast=split '=',$origbroadcast; $origbroadcast = @obcast[1]; # corrected form of $origbroadcast $config_file = "/etc/ltsp/dhcpd.conf"; $bkup_file = $config_file . ".ltsp.orig"; $tmp_file = $config_file . ".ltsp.tmp"; # don't bother to continue unless the target file exists $exists = stat ($config_file); if (! $exists) { print "\n". $config_file ." not found\n\n"; exit; } # open target file open (IN, "< $config_file"); open (OUT, "> $tmp_file"); if ( $ARGV[2] ) { $server = $ARGV[0]; $network = $ARGV[1]; $netmask = $ARGV[2]; } else { $server="172.31.100.254"; $network="172.31.100.0"; $netmask="255.255.255.0"; } # the following line is buggy as it outputs "BROADCAST=aaa.bbb.ccc.ddd" it will be corrected $broadcast = `/bin/ipcalc -b $network $netmask`; # correction code for above bug is added in the following line @bc=split '=',$broadcast; $broadcast = @bc[1]; # corrected form of $broadcast @orignw = split '\.', $orignetwork; @nw = split '\.', $network; @nm = split '\.', $netmask; $i = 0; while ($nm[$i] == "255") { if ($net) { $net = $net . "."; $orignet = $orignet . "."; } $net = $net . $nw[$i]; $orignet = $orignet . $orignw[$i]; ++$i; } while () { s/$origserver/$server/g; s/$orignetwork/$network/g; s/$orignetmask/$netmask/g; s/$origbroadcast/$broadcast/g; s/$orignet/$net/g; print OUT $_; } # close up the files close (IN); close (OUT); # out with the old, in with the new rename ($config_file, $bkup_file); rename ($tmp_file, $config_file); exit;