3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
|
our $base_dir = '/srv/pxelator'; |
7 |
|
|
8 |
our $ip = '172.16.10.1'; |
tie our $ip, 'server::tie', 'server_ip' => '172.16.10.1'; |
9 |
our $netmask = '255.255.255.0'; |
tie our $netmask, 'server::tie', 'natmask' => '255.255.255.0'; |
10 |
our $bcast = '172.16.10.255'; |
tie our $bcast, 'server::tie', 'bcast' => '172.16.10.254'; |
11 |
|
tie our $ip_from, 'server::tie', 'ip_from' => 10; |
12 |
if ( my $dev = $ENV{DEV} ) { |
tie our $ip_to, 'server::tie', 'ip_to' => 100; |
13 |
my $ifconfig = `ifconfig $dev`; |
tie our $domain, 'server::tie', 'domain' => 'pxelator.lan'; |
|
( $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 $domain_name = 'pxelator.lan'; |
|
14 |
|
|
15 |
our $base_dir = '/srv/pxelator'; |
warn "DEV $ip $bcast $netmask"; |
16 |
|
|
17 |
our $conf = "$base_dir/conf/$ip"; |
our $conf = "$base_dir/conf"; |
18 |
mkdir $conf unless -e $conf; |
mkdir $conf unless -e $conf; |
19 |
|
|
20 |
use Module::Refresh qw//; |
sub conf { |
21 |
sub refresh { Module::Refresh->refresh }; |
warn "## conf $conf"; |
22 |
|
$conf; |
23 |
|
} |
24 |
|
|
25 |
|
use Module::Refresh qw//; |
26 |
|
sub refresh { |
27 |
|
Module::Refresh->refresh; |
28 |
|
my $from = (caller(1))[3]; |
29 |
|
$from =~ s{^(\w+)::.+$}{$1}; |
30 |
|
my $eval = '$' . $from . '::debug = server::debug();'; |
31 |
|
warn "refresh $eval\n"; |
32 |
|
eval $eval; |
33 |
|
warn $@ if $@; |
34 |
|
}; |
35 |
|
|
36 |
mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' ); |
mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' ); |
37 |
|
|
49 |
return $value; |
return $value; |
50 |
} |
} |
51 |
|
|
52 |
|
sub conf_default { shared($_[0]) || $_[1] } |
53 |
|
|
54 |
sub debug { shared('debug', @_) || 0 } |
sub debug { shared('debug', @_) || 0 } |
55 |
|
|
56 |
warn "loaded"; |
warn "loaded"; |
57 |
|
|
58 |
1; |
|
59 |
|
package server::tie; |
60 |
|
|
61 |
|
use File::Slurp; |
62 |
|
use Data::Dump qw/dump/; |
63 |
|
|
64 |
|
use server; |
65 |
|
|
66 |
|
sub TIESCALAR { |
67 |
|
warn dump @_; |
68 |
|
my ($class,$name,$default) = @_; |
69 |
|
|
70 |
|
my $path = $server::base_dir . '/conf/' . $name; |
71 |
|
|
72 |
|
my $o = { |
73 |
|
path => $path, |
74 |
|
}; |
75 |
|
write_file $o->{path}, $default unless -f $o->{path}; |
76 |
|
|
77 |
|
warn "TIESCALAR $name ", $o->{path}, " [$default]"; |
78 |
|
|
79 |
|
bless \$o,$class; |
80 |
|
} |
81 |
|
|
82 |
|
sub STORE { |
83 |
|
warn dump @_; |
84 |
|
my ( $self, $value ) = @_; |
85 |
|
write_file $$self->{path}, $value; |
86 |
|
} |
87 |
|
|
88 |
|
sub FETCH { |
89 |
|
warn dump @_; |
90 |
|
my $self = shift; |
91 |
|
read_file $$self->{path}; |
92 |
|
} |
93 |
|
|
94 |
|
3; |