--- lib/PXElator/pxe.pm 2009/07/29 22:04:58 45 +++ lib/PXElator/pxe.pm 2009/07/31 22:36:06 102 @@ -2,10 +2,11 @@ use warnings; use strict; +use autodie; use File::Slurp; -use server; +use httpd; use tftpd; our $file = 'gpxelinux.0'; @@ -13,22 +14,45 @@ symlink '/usr/lib/syslinux/gpxelinux.0', $path unless -l $path; warn "file $path ", -s $path; -my $url = "http://$server::ip/pxelator/debian-live/"; -my $squash = tftpd::path('debian-live/*squashfs'); +my $url = $httpd::url; +#$url = "tftp://$server::ip/"; # fallback to tftp +#$url = "http://$server::ip/pxelator/"; + +use LWP::Simple qw/mirror RC_NOT_MODIFIED/; +foreach my $file ( 'vmlinuz1', 'initrd1.img', 'debian-live-501-i386-rescue.squashfs' ) { + my $path = "$tftpd::dir/debian-live"; + mkdir $path unless -e $path; +# next if -e "$path/$file"; + print STDERR "mirror $file "; + mirror( "http://cdimage.debian.org/cdimage/release/current-live/i386/web/$file", "$path/$file") + == RC_NOT_MODIFIED + && warn("not modified\n") + || warn("mirrored ", -s "$path/$file", "\n") + ; +} + +sub config_for_ip { + + my $ip = shift; + $ip = uc sprintf "%02x%02x%02x%02x", split /\./,$ip; + + my $config = "$tftpd::dir/pxelinux.cfg"; + mkdir $config unless -d $config; + $config .= '/' . $ip; + + my $squash = $url . tftpd::path('debian-live/*squashfs'); + write_file $config, qq{ + + default linux + label linux + kernel $url/debian-live/vmlinuz1 + append initrd=$url/debian-live/initrd1.img boot=live union=aufs noswap noprompt vga=normal fetch=$squash + }; -my $config = "$ftpd::dir/pxelinux.cfg/default"; + warn "config $config ", -s $config if $server::debug; -write_file $config, qq{ - -default linux -label linux - kernel $url/vmlinuz1 - append initrd=$url/initrd1.img boot=live union=aufs noswap noprompt vga=normal fetch=$url/$squash - -}; - -warn "config $config ", -s $config; +} warn "loaded";