4 |
use strict; |
use strict; |
5 |
use autodie; |
use autodie; |
6 |
|
|
7 |
|
use Data::Dump qw/dump/; |
8 |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
9 |
use server; |
use server; |
10 |
|
use once; |
11 |
|
|
12 |
sub mirror_file { |
sub mirror_file { |
13 |
my ( $url, $file ) = @_; |
my ( $url, $file ) = @_; |
14 |
print STDERR "mirror $url"; |
warn "mirror_file $url -> $file\n"; |
15 |
mirror( $url, $file ) |
mirror( $url, $file ) |
16 |
== RC_NOT_MODIFIED |
== RC_NOT_MODIFIED |
17 |
&& warn(" not modified\n") |
&& warn(" not modified\n") |
19 |
; |
; |
20 |
} |
} |
21 |
|
|
|
our $just_once; |
|
|
|
|
22 |
sub iso { |
sub iso { |
23 |
my $url = shift; |
my $url = shift; |
24 |
|
|
|
return if $just_once->{$url}++; |
|
|
|
|
25 |
my $name = (caller(1))[3]; |
my $name = (caller(1))[3]; |
26 |
$name =~ s{config::}{} || die "caller isn't package config !"; |
$name =~ s{config::}{} || die "caller isn't package config !"; |
27 |
|
|
35 |
|
|
36 |
my $iso = "$dir/$file"; |
my $iso = "$dir/$file"; |
37 |
|
|
38 |
mirror_file( $url, $iso ); |
mirror_file( $url, $iso ) if once::first_time $url; |
39 |
|
|
40 |
$file =~ s{\.iso$}{}i; |
$file =~ s{\.iso$}{}i; |
41 |
my $mnt = "$server::base_dir/tftp/$name"; |
my $mnt = "$server::base_dir/tftp/$name"; |
46 |
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; |
47 |
} |
} |
48 |
|
|
49 |
sub file { |
sub files { |
50 |
my ( $url, $file ) = @_; |
my $url = shift; |
51 |
my $path = "$server::base_dir/$file"; |
my @files = @_; |
52 |
my @file_parts = split m{/}, $file; |
|
53 |
foreach ( 1 .. $#file_parts - 1 ) { |
if ( ! @files ) { |
54 |
my $path = splice @file_parts, 0, $_; |
push @files, $1 if $url =~ s{/([^/]+)$}{}; |
55 |
warn "? $path\n"; |
} |
56 |
mkdir $path unless -e $path; |
|
57 |
|
my $name = (caller(1))[3]; |
58 |
|
$name =~ s{config::}{} || die "caller isn't package config !"; |
59 |
|
|
60 |
|
my $path = "$server::base_dir/tftp/$name"; |
61 |
|
mkdir $path unless -d $path; |
62 |
|
|
63 |
|
warn "# files $url ",dump( @files ), " -> $path\n"; |
64 |
|
|
65 |
|
foreach my $file ( @files ) { |
66 |
|
mirror_file( "$url/$file", "$path/$file" ) |
67 |
|
if ! -e "$path/$file" || once::first_time( "$url/$file" ); |
68 |
} |
} |
|
mirror_file( $url, "$server::base_dir/$file" ); |
|
69 |
} |
} |
70 |
|
|
71 |
1; |
1; |