/[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

Contents of /lib/PXElator/upstream.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 508 - (show annotations)
Wed Jul 21 16:17:46 2010 UTC (13 years, 9 months ago) by dpavlin
File size: 1476 byte(s)
check once in mirror_file so we can call it directly

1 package upstream;
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 use Data::Dump qw/dump/;
8 use LWP::Simple qw/mirror RC_NOT_MODIFIED/;
9 use server;
10 use once;
11
12 sub mirror_file {
13 my ( $url, $file ) = @_;
14
15 return if ! once::first_time $url;
16
17 warn "mirror_file $url -> $file\n";
18 mirror( $url, $file )
19 == RC_NOT_MODIFIED
20 && warn(" not modified\n")
21 || warn(" done ", -s $file, " bytes\n")
22 ;
23 }
24
25 sub iso {
26 my $url = shift;
27
28 my $name = (caller(1))[3];
29 $name =~ s{config::}{} || die "caller isn't package config !";
30
31 warn "$name $url";
32
33 my $dir = "$server::base_dir/iso";
34 mkdir $dir unless -e $dir;
35
36 my $file = $1 if $url =~ m{/([^/]+\.iso)}i;
37 die "can't find iso file in $url" unless $file;
38
39 my $iso = "$dir/$file";
40
41 mirror_file( $url, $iso );
42
43 $file =~ s{\.iso$}{}i;
44 my $mnt = "$server::base_dir/tftp/$name";
45 mkdir $mnt unless -d $mnt;
46 $mnt .= '/iso';
47 mkdir $mnt unless -d $mnt;
48
49 system("mount -t iso9660 | grep $name/iso || sudo mount $iso $mnt -o loop -t iso9660 -v") == 0;
50 }
51
52 sub files {
53 my $url = shift;
54 my @files = @_;
55
56 if ( ! @files ) {
57 push @files, $1 if $url =~ s{/([^/]+)$}{};
58 }
59
60 my $name = (caller(1))[3];
61 $name =~ s{config::}{} || die "caller isn't package config !";
62
63 my $path = "$server::base_dir/tftp/$name";
64 mkdir $path unless -d $path;
65
66 warn "# files $url ",dump( @files ), " -> $path\n";
67
68 foreach my $file ( @files ) {
69 mirror_file( "$url/$file", "$path/$file" )
70 if ! -e "$path/$file" || once::first_time( "$url/$file" );
71 }
72 }
73
74 1;

  ViewVC Help
Powered by ViewVC 1.1.26