implement mirror and configuration creation for webconverger
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Aug 2009 13:19:08 +0000 (13:19 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Aug 2009 13:19:08 +0000 (13:19 +0000)
lib/PXElator/config.pm
lib/PXElator/t/config.t

index 7342c7d..0c0c816 100644 (file)
@@ -2,6 +2,7 @@ package config;
 
 use warnings;
 use strict;
+use autodie;
 
 use server;
 use pxelinux;
@@ -25,21 +26,45 @@ sub debian_live {
        $pxelinux::config_file = 'pxelinux.cfg/default';
 }
 
+use LWP::Simple qw/mirror RC_NOT_MODIFIED/;
 sub webconverger {
        $dhcpd::file = "pxelinux.0";
        $pxelinux::path_prefix = 'webconverger/';
-#      $pxelinux::config_file = 'default';
 
-       return; # FIXME
+       my $dir = "$server::base_dir/tftp/$pxelinux::path_prefix";
 
-       my $cfg = "$tftp::dir/pxelinux.cfg";
-       return if -e $cfg;
+       mkdir $dir unless -d $dir;
 
-       warn "using iso";
-#      system "mount -t 9660 | grep webc-5.2 || sudo mount /srv/pxelator/iso/webc-5.2.iso /srv/pxelator/tftp/webconverger/iso/ -o loop -t iso9660 -v";
+       my $cfg = "$dir/pxelinux.cfg";
+       return 1 if -e $cfg;
 
-       symlink "/usr/lib/syslinux/pxelinux.0", "$tftp::dir/$dhcpd::file";
+       mkdir $cfg;
 
+       my $iso = '/srv/pxelator/iso/webc-5.2.iso';
+       my $url = 'http://download.webconverger.com/webc-5.2.iso';
+
+       print STDERR "mirror $url";
+       mirror( $url, $iso)
+               == RC_NOT_MODIFIED
+               && warn(" not modified\n")
+               || warn(" done ", -s $iso, " bytes\n")
+               ;
+
+       mkdir "$dir/iso" unless -e "$dir/iso";
+
+       system "mount -t iso9660 | grep webc-5.2 || sudo mount $iso $dir/iso/ -o loop -t iso9660 -v";
+
+       symlink "/usr/lib/syslinux/pxelinux.0", "$dir/$dhcpd::file";
+
+       $cfg .= '/default';
+
+       write_file $cfg, qq{
+label webconverger
+       kernel iso/live/vmlinuz-2.6.30-backports.1-486
+       append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=http://172.16.10.1/pxelator/webconverger/iso/live/filesystem.squashfs boot=live quiet homepage=http://172.16.10.1:7777/ nonetworking nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=webconverger union=aufs
+       };
+
+#      $pxelinux::config_file = $cfg;
 }
 
 sub for_ip {
@@ -49,4 +74,6 @@ sub for_ip {
 #      $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix";
 }
 
+warn 'loaded';
+
 1;
index 3408c37..0d0ed97 100755 (executable)
@@ -4,7 +4,7 @@ use warnings;
 use strict;
 use autodie;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 use Data::Dump qw/dump/;
 
 use_ok 'config';
@@ -13,3 +13,4 @@ ok( my $test = config::shared( 'test', 42 ), 'set shared' );
 diag $test;
 cmp_ok( $test, '==', config::shared( 'test' ), 'get shared' );
 
+ok( config::webconverger(), 'webconverger' );