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"; |
|
15 |
|
return unless once::first_time $file; |
16 |
|
|
17 |
|
warn "mirror_file $url -> $file\n"; |
18 |
mirror( $url, $file ) |
mirror( $url, $file ) |
19 |
== RC_NOT_MODIFIED |
== RC_NOT_MODIFIED |
20 |
&& warn(" not modified\n") |
&& warn(" not modified\n") |
22 |
; |
; |
23 |
} |
} |
24 |
|
|
|
our $just_once; |
|
|
|
|
25 |
sub iso { |
sub iso { |
26 |
my $url = shift; |
my $url = shift; |
27 |
|
|
|
return if $just_once->{$url}++; |
|
|
|
|
28 |
my $name = (caller(1))[3]; |
my $name = (caller(1))[3]; |
29 |
$name =~ s{config::}{} || die "caller isn't package config !"; |
$name =~ s{config::}{} || die "caller isn't package config !"; |
30 |
|
|
33 |
my $dir = "$server::base_dir/iso"; |
my $dir = "$server::base_dir/iso"; |
34 |
mkdir $dir unless -e $dir; |
mkdir $dir unless -e $dir; |
35 |
|
|
36 |
my $file = $1 if $url =~ m{/([^/]+\.iso$)}i; |
my $file = $1 if $url =~ m{/([^/]+\.iso)}i; |
37 |
die "can't find iso file in $url" unless $file; |
die "can't find iso file in $url" unless $file; |
38 |
|
|
39 |
my $iso = "$dir/$file"; |
my $iso = "$dir/$file"; |
47 |
mkdir $mnt unless -d $mnt; |
mkdir $mnt unless -d $mnt; |
48 |
|
|
49 |
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; |
50 |
|
return $iso; |
51 |
} |
} |
52 |
|
|
53 |
sub file { |
sub files { |
54 |
my ( $url, $file ) = @_; |
my $url = shift; |
55 |
my $path = "$server::base_dir/$file"; |
my @files = @_; |
56 |
my @file_parts = split m{/}, $file; |
|
57 |
foreach ( 1 .. $#file_parts - 1 ) { |
if ( ! @files ) { |
58 |
my $path = splice @file_parts, 0, $_; |
push @files, $1 if $url =~ s{/([^/]+)$}{}; |
59 |
warn "? $path\n"; |
} |
60 |
mkdir $path unless -e $path; |
|
61 |
|
my $name = (caller(1))[3]; |
62 |
|
$name =~ s{config::}{} || die "caller isn't package config !"; |
63 |
|
|
64 |
|
my $path = "$server::base_dir/tftp/$name"; |
65 |
|
mkdir $path unless -d $path; |
66 |
|
|
67 |
|
warn "# files $url ",dump( @files ), " -> $path\n"; |
68 |
|
|
69 |
|
foreach my $file ( @files ) { |
70 |
|
mirror_file( "$url/$file", "$path/$file" ) |
71 |
|
if ! -e "$path/$file" || once::first_time( "$url/$file" ); |
72 |
} |
} |
|
mirror_file( $url, "$server::base_dir/$file" ); |
|
73 |
} |
} |
74 |
|
|
75 |
1; |
1; |