6 use Data::Dump qw(dump);
9 our $base_dir = '/srv/pxelator';
13 tie our $ip, 'ties', 'server_ip' => '172.16.10.1';
14 tie our $netmask, 'ties', 'netmask' => '255.255.255.0';
15 tie our $bcast, 'ties', 'bcast' => '172.16.10.254';
16 tie our $ip_from, 'ties', 'ip_from' => 10;
17 tie our $ip_to, 'ties', 'ip_to' => 100;
18 tie our $domain, 'ties', 'domain' => 'pxelator.lan';
19 tie our $new_clients, 'ties', 'new_clients' => $ip_to - $ip_from;
21 if ( my $dev = $ENV{DEV} ) {
22 my $ifconfig = `ifconfig $dev`;
23 die "can't ifconfig $dev" unless $ifconfig;
24 die "device $dev not up: ifconfig $dev\n$ifconfig" unless $ifconfig =~ m/UP/;
25 $ip = $1 if $ifconfig =~ m/inet addr:(\S+)/s;
26 $netmask = $1 if $ifconfig =~ m/Mask:(\S+)/s;
27 $bcast = $1 if $ifconfig =~ m/Bcast:(\S)/s;
30 warn "DEV $ip $bcast $netmask";
32 our $conf = "$base_dir/conf";
33 mkdir $conf unless -e $conf;
40 use Module::Refresh qw//;
42 Module::Refresh->refresh;
43 my $from = (caller(1))[3];
44 $from =~ s{^(\w+)::.+$}{$1};
45 my $eval = '$' . $from . '::debug = server::debug();';
46 warn "refresh $eval\n";
51 mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' );
55 my ($name, $value) = @_;
57 my $path ="$conf/$name";
58 if ( defined $value ) {
59 write_file $path, $value;
60 warn "update $path = $value";
62 $value = read_file $path if -e $path;
67 sub conf_default { shared($_[0]) || $_[1] }
69 sub debug { shared('debug', @_) || 0 }
75 map { $server->{ $_ } = eval '$server::' . $_ } ( 'ip', 'netmask', 'bcast', 'domain', 'ip_from', 'ip_to', 'new_clients' );
77 my $server_path = "$server::conf/ip/$ip/server.yaml";
78 $server = YAML::LoadFile $server_path if -e $server_path;