5 |
use autodie; |
use autodie; |
6 |
|
|
7 |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
8 |
|
use Storable; |
9 |
use server; |
use server; |
10 |
|
|
11 |
sub mirror_file { |
sub mirror_file { |
18 |
; |
; |
19 |
} |
} |
20 |
|
|
21 |
our $just_once; |
my $once_path = '/tmp/pxelator.once'; |
22 |
|
our $just_once = retrieve $once_path; |
23 |
|
sub first_time { |
24 |
|
my $what = shift; |
25 |
|
return if $just_once->{$what}++; |
26 |
|
store $just_once, $once_path; |
27 |
|
return 1; |
28 |
|
} |
29 |
|
|
30 |
sub iso { |
sub iso { |
31 |
my $url = shift; |
my $url = shift; |
32 |
|
|
33 |
return if $just_once->{$url}++; |
return if ! first_time($url); |
34 |
|
|
35 |
my $name = (caller(1))[3]; |
my $name = (caller(1))[3]; |
36 |
$name =~ s{config::}{} || die "caller isn't package config !"; |
$name =~ s{config::}{} || die "caller isn't package config !"; |
56 |
system("mount -t iso9660 | grep $name/iso || sudo mount $iso $mnt -o loop -t iso9660 -v") == 0; |
system("mount -t iso9660 | grep $name/iso || sudo mount $iso $mnt -o loop -t iso9660 -v") == 0; |
57 |
} |
} |
58 |
|
|
59 |
sub file { |
sub files { |
60 |
my ( $url, $file ) = @_; |
my $url = shift; |
61 |
my $path = "$server::base_dir/$file"; |
|
62 |
|
my $name = (caller(1))[3]; |
63 |
|
$name =~ s{config::}{} || die "caller isn't package config !"; |
64 |
|
|
65 |
|
my $path = "$server::base_dir/tftp/$name"; |
66 |
|
|
67 |
|
foreach my $file ( @_ ) { |
68 |
|
mirror_file "$url/$file", "$path/$file" |
69 |
|
if first_time( "$url/$file" ); |
70 |
|
} |
71 |
|
} |
72 |
|
|
73 |
|
sub mkpath { |
74 |
|
my $file = shift; |
75 |
|
|
76 |
my @file_parts = split m{/}, $file; |
my @file_parts = split m{/}, $file; |
77 |
foreach ( 1 .. $#file_parts - 1 ) { |
foreach ( 1 .. $#file_parts - 1 ) { |
78 |
my $path = splice @file_parts, 0, $_; |
my $path = splice @file_parts, 0, $_; |
79 |
warn "? $path\n"; |
warn "? $path\n"; |
80 |
mkdir $path unless -e $path; |
mkdir $path unless -e $path; |
81 |
} |
} |
|
mirror_file( $url, "$server::base_dir/$file" ); |
|
82 |
} |
} |
83 |
|
|
84 |
1; |
1; |