/[pxelator]/lib/PXElator/upstream.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/upstream.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 138 by dpavlin, Tue Aug 4 15:25:09 2009 UTC revision 233 by dpavlin, Sun Aug 16 23:31:30 2009 UTC
# Line 5  use strict; Line 5  use strict;
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  our $just_once;  sub mirror_file {
12            my ( $url, $file ) = @_;
13            print STDERR "mirror $url";
14            mirror( $url, $file )
15                    == RC_NOT_MODIFIED
16                    && warn(" not modified\n")
17                    || warn(" done ", -s $file, " bytes\n")
18                    ;
19    }
20    
21    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 !";
# Line 27  sub iso { Line 45  sub iso {
45    
46          my $iso = "$dir/$file";          my $iso = "$dir/$file";
47    
48          print STDERR "$name mirror $url";          mirror_file( $url, $iso );
         mirror( $url, $iso )  
                 == RC_NOT_MODIFIED  
                 && warn(" not modified\n")  
                 || warn(" done ", -s $iso, " bytes\n")  
                 ;  
49    
50          $file =~ s{\.iso$}{}i;          $file =~ s{\.iso$}{}i;
51          my $mnt = "$server::base_dir/tftp/$name";          my $mnt = "$server::base_dir/tftp/$name";
# Line 40  sub iso { Line 53  sub iso {
53          $mnt .= '/iso';          $mnt .= '/iso';
54          mkdir $mnt unless -d $mnt;          mkdir $mnt unless -d $mnt;
55    
56          system("mount -t iso9660 | grep $mnt || 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 files {
60            my $url = shift;
61    
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;
77            foreach ( 1 .. $#file_parts - 1 ) {
78                    my $path = splice @file_parts, 0, $_;
79                    warn "? $path\n";
80                    mkdir $path unless -e $path;
81            }
82  }  }
83    
84  1;  1;

Legend:
Removed from v.138  
changed lines
  Added in v.233

  ViewVC Help
Powered by ViewVC 1.1.26