--- lib/PXElator/server.pm 2009/07/30 21:31:30 67 +++ lib/PXElator/server.pm 2009/08/09 16:37:46 179 @@ -2,25 +2,48 @@ use warnings; use strict; -use File::Slurp; + our $ip = '172.16.10.1'; our $netmask = '255.255.255.0'; +our $bcast = '172.16.10.255'; + +if ( my $dev = $ENV{DEV} ) { + my $ifconfig = `ifconfig $dev`; + ( $ip, $bcast, $netmask ) = ( $1, $2, $3 ) if $ifconfig =~ m{inet addr:(\S+)\s+Bcast:(\S+)\s+Mask:(\S+)}s; + warn "DEV $dev $ip $bcast $netmask"; +} our ( $ip_from, $ip_to ) = ( 10, 100 ); -our $base_dir = '/home/dpavlin/llin/pxelator'; +our $domain_name = 'pxelator.lan'; + +our $base_dir = '/srv/pxelator'; + +our $conf = "$base_dir/conf/$ip"; + +use Module::Refresh qw//; +sub refresh { Module::Refresh->refresh }; -our $debug = 0; -sub debug { - my $new = shift; - my $path ="$base_dir/conf/debug"; - if ( defined $new ) { - write_file $path, $debug = $new; + +mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' ); + +use File::Slurp; +sub shared { + my ($name, $value) = @_; + + my $path ="$conf/$name"; + if ( defined $value ) { + write_file $path, $value; + warn "update $path = $value"; } else { - $debug = read_file $path if -e $path; + $value = read_file $path if -e $path; } - return $debug; + return $value; } +sub debug { shared('debug', @_) || 0 } + warn "loaded"; + +1;