/[pxelator]/lib/PXElator/config.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/config.pm

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

revision 461 by dpavlin, Sat Jan 2 22:55:33 2010 UTC revision 546 by dpavlin, Sat Oct 9 15:28:42 2010 UTC
# Line 9  use pxelinux; Line 9  use pxelinux;
9  use client;  use client;
10  use file;  use file;
11  use ssh;  use ssh;
12    use upstream;
13    
14  use File::Slurp;  use File::Slurp;
15    
16  our $mounted;  our $mounted;
17    
18  sub available { qw/katalog debian_live webconverger debirf tinycore nfsroot openvz printer wrt/ };  our $server;
19    our $server_ip;
20    
21    sub available { qw/
22            katalog debian_live webconverger
23            debirf tinycore nfsroot
24            openvz printer wrt
25            clonezilla ubuntu memdisk vyatta android
26            systemrescue
27    / };
28    
29  sub debian_live {  sub debian_live {
30          my ($ip) = @_;          my ($ip) = @_;
31    
32          upstream::files( qw{          my $from = 'http://cdimage.debian.org/cdimage/release/current-live/i386/web/';
33                  http://cdimage.debian.org/cdimage/release/current-live/i386/web/          $from = 'http://cdimage.debian.org/cdimage/squeeze_live_alpha2/i386/web/';
34                  vmlinuz1          my $variant = 'standard';
35                  initrd1.img  
36                  debian-live-501-i386-standard.squashfs          my $dir = upstream::files $from => 'MD5SUMS';
37          });  
38            my ( $vmlinuz, $initrd, $squashfs );
39            
40            my @md5sum = read_file "$dir/MD5SUMS";
41    
42            foreach ( @md5sum ) {
43                    $vmlinuz = $1 if m/\s+(\S*vmlinuz\S*)/;
44                    $initrd = $1 if m/\s+(\S*$variant\S*initrd\S*)/;
45                    $squashfs = $1 if m/\s+(\S*$variant\S*\.squashfs)$/;
46                    warn "# MD5SUM: $_\n";
47            }
48    
49            upstream::files $from => $vmlinuz, $initrd, $squashfs;
50    
51          my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live';          my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live';
52    
53            # FIXME drop in shell because users doesn't work in current image
54            my $custom_init = 'init=/bin/hash';
55    
56            if ( my $custom_squashfs = client::conf( $ip => 'squashfs' ) ) {
57                    $squashfs = $custom_squashfs;
58                    $custom_init = '';
59            }
60    
61          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
62    
63  default debian_live  default debian_live
64  label debian_live  label debian_live
65          kernel vmlinuz1          kernel $vmlinuz
66          append initrd=initrd1.img fetch=http://${server::ip}:7777/debian_live/debian-live-501-i386-standard.squashfs boot=live nopersistent hostname=$hostname union=aufs noprompt          append initrd=$initrd fetch=http://$server_ip:7777/debian_live/$squashfs boot=live nopersistent hostname=$hostname union=aufs noprompt autologin username=user debug $custom_init
67          });          });
68    
69  }  }
70    
 use upstream;  
   
71  =head1 webconverger  =head1 webconverger
72    
73  Webconverger - the opensource Web Kiosk  Webconverger - the opensource Web Kiosk
# Line 48  L<http://webconverger.org/> Line 76  L<http://webconverger.org/>
76    
77  =cut  =cut
78    
79    sub _glob_first {
80            my ( $dir, $path ) = @_;
81            my @glob = glob "$dir/$path";
82            my $first = $glob[0] || die "no $dir/$path";
83            $dir   =~ s{iso/*$}{};
84            $first =~ s{^\Q$dir\E}{}g;
85            return $first;
86    }
87    
88  sub webconverger {  sub webconverger {
89          my ($ip) = @_;          my ($ip) = @_;
90    
91          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-6.2.iso' );
92    
93          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';
94    
95          my $homepage = client::conf( $ip => 'webconverger/homepage'          my $homepage = client::conf( $ip => 'webconverger/homepage'
96                  , default => "http://${server::ip}:7777/client" );                  , default => "http://$server_ip:7777/client" );
97          my $fetch    = client::conf( $ip => 'webconverger/fetch'          my $fetch    = client::conf( $ip => 'webconverger/fetch'
98                  , default => "http://${server::ip}:7777/webconverger/iso/live/filesystem.squashfs" );                  , default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" );
99    
100            my $mnt = "$server::base_dir/tftp/webconverger/iso";
101            warn "# mnt: $mnt\n";
102            my $kernel = _glob_first $mnt => 'live/vmlinuz*';
103            my $initrd = _glob_first $mnt => 'live/initrd.img*';
104    
105          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
106    
107  default webconverger  default webconverger
108  label webconverger  label webconverger
109          kernel iso/live/vmlinuz-2.6.30-backports.1-486          kernel $kernel
110          append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=$fetch boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr noprompt          append initrd=$initrd fetch=$fetch boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr noprompt kioskresetstation=10
111    
112          });          });
113    
# Line 76  sub katalog { Line 118  sub katalog {
118          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
119          my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';          my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';
120          my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );          my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );
121          my $fetch    = client::conf( $ip => 'webconverger/fetch' => "http://${server::ip}:7777/webconverger/custom.squashfs" );          my $fetch    = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" );
122    
123          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
124    
# Line 113  label linux Line 155  label linux
155    
156  sub tinycore {  sub tinycore {
157          my $ip = shift;          my $ip = shift;
158          upstream::iso( 'http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/2.x/release/tinycore_2.2.iso' );          upstream::iso( 'http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/3.x/release/tinycore-current.iso' );
159          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
160    
161  default linux  default linux
# Line 124  label linux Line 166  label linux
166          });          });
167  }  }
168    
169    sub clonezilla {
170            my $ip = shift;
171            upstream::iso( 'http://sourceforge.net/projects/clonezilla/files/clonezilla_live_alternative_testing/clonezilla-live-20100503-lucid.iso/download' );
172            pxelinux::config_for_ip( $ip, qq{
173    
174    default linux
175    label linux
176            kernel iso/live/vmlinuz
177            append initrd=iso/live/initrd.img boot=live union=aufs noswap noprompt vga=788 fetch=http://$server_ip:7777/clonezilla/iso/live/filesystem.squashfs
178    
179            });
180    }
181    
182    sub ubuntu {
183            my $ip = shift;
184            upstream::iso( 'http://mirrors.us.kernel.org/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso' );
185    
186            my $export = "$server::base_dir/tftp/ubuntu/iso";
187            my $exported = `exportfs | grep $export`;
188            if ( $exported ne $export ) {
189                    warn "exportfs $exported\n";
190                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
191            }
192            pxelinux::config_for_ip( $ip, qq{
193    
194    default linux
195    label linux
196            kernel iso/casper/vmlinuz
197            append initrd=iso/casper/initrd.lz boot=casper netboot=nfs nfsroot=$server_ip:$export --
198    
199            });
200    }
201    
202    sub memdisk {
203            my $ip = shift;
204    
205            my $dir = "$server::base_dir/tftp/memdisk";
206            mkdir $dir unless -e $dir;
207    
208            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
209    
210            my $image = client::conf( $ip => 'memdisk.image' );
211    
212            if ( ! $image ) {
213                    $image = 'freedos.gz';
214                    upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.imz' => "$dir/$image";
215                    warn "using $image [default FreeDOS]\n";
216                    symlink "$dir/$image", client::ip_path $ip . '/memdisk.image';
217            } else {
218                    $image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n";
219            }
220    
221            if ( my $kvm = client::conf $ip => 'kvm' ) {
222                    client::conf $ip => 'kvm.bin', 'qemu-system-i386'; # FIXME kvm doesn't seem to work
223            }
224    
225            pxelinux::config_for_ip( $ip, qq{
226    
227    default $image
228    label $image
229            kernel memdisk
230            append initrd=$image
231    
232            });
233    }
234    
235    sub vyatta {
236            my $ip = shift;
237            upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' );
238    
239            my $dir = "$server::base_dir/tftp/vyatta";
240            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
241    
242            pxelinux::config_for_ip( $ip, qq{
243    
244    default vyatta
245    label vyatta
246    
247            kernel iso/live/vmlinuz1
248            append initrd=iso/live/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta fetch=http://$server_ip:7777/vyatta/iso/live/filesystem.squashfs
249    
250            });
251    }
252    
253    sub android {
254            my $ip = shift;
255            my $path = upstream::iso( 'http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso' );
256    
257            my $dir = "$server::base_dir/tftp/android";
258            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
259    
260            client::conf $ip => 'kvm.boot' => "n -cdrom $path";
261    
262            pxelinux::config_for_ip( $ip, qq{
263    
264    default android-1.6-donut
265    label android-1.6-donut
266    
267            kernel iso/kernel
268            append initrd=iso/initrd.img root=/dev/ram0 androidboot_hardware=eeepc acpi_sleep=s3_bios,s3_mode quiet SRC= DATA= SDCARD= vga=788 DEBUG=1
269    
270            });
271    }
272    
273    
274    # http://www.sysresccd.org/Sysresccd-manual-en_PXE_network_booting
275    sub systemrescue {
276            my $ip = shift;
277            my $path = upstream::iso( 'http://sourceforge.net/projects/systemrescuecd/files/sysresccd-x86/1.6.1/systemrescuecd-x86-1.6.1.iso/download' );
278    
279            my $dir = "$server::base_dir/tftp/systemrescue";
280            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
281    
282            client::conf $ip => 'kvm.boot' => "n -cdrom $path";
283    
284            pxelinux::config_for_ip( $ip, qq{
285    
286    default systemrescue
287    label systemrescue
288    
289            kernel iso/isolinux/rescuecd
290            append initrd=iso/isolinux/initram.igz dodhcp netboot=http://$server::ip:7777/systemrescue/iso/sysrcd.dat
291    
292            });
293    }
294    
295  sub in_chroot {  sub in_chroot {
296          my ( $dir, $command ) = @_;          my ( $dir, $command ) = @_;
297          write_file "$dir/tmp/inside.sh", $command;          write_file "$dir/tmp/inside.sh", $command;
# Line 182  sub nfsroot { Line 350  sub nfsroot {
350                    
351          }          }
352    
353          my $server = server::as_hash_for $ip;          my $exported = `exportfs | grep $export`;
354            if ( $exported ne $export ) {
355                    warn "exportfs $exported\n";
356                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
357            }
358    
359          my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';          my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
360          file::replace "$export/etc/hostname", $hostname;          file::replace "$export/etc/hostname", $hostname;
# Line 205  iface eth0 inet dhcp Line 377  iface eth0 inet dhcp
377                  file::append "$export/etc/rc.local", $_;                  file::append "$export/etc/rc.local", $_;
378          } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );          } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
379    
380          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
   
 default nfsroot  
 label nfsroot  
         kernel $ip/vmlinuz  
         append initrd=$ip/initrd.img root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp  
   
 label old  
         kernel $ip/vmlinuz.old  
         append initrd=$ip/initrd.img.old root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp  
381    
         });  
382  }  }
383    
384  sub openvz {  sub openvz {
# Line 228  sub wrt         {} Line 390  sub wrt         {}
390    
391  sub for_ip {  sub for_ip {
392          my $ip = shift || return;          my $ip = shift || return;
393            $server = server::as_hash_for $ip;
394            $server_ip = $server->{ip} || die "no server ip";
395          my $config = client::conf( $ip => 'config' ) || return;          my $config = client::conf( $ip => 'config' ) || return;
396          eval $config . '($ip)';          my $ret = eval $config . '($ip)'; # must be last
397  #       $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix";          if ( $@ ) {
398                    warn "ERROR in executing $config($ip): $@\n";
399                    $ret .= qq{<pre style="color:red">$@</pre>};
400            }
401            return $ret;
402  }  }
403    
404  warn 'loaded';  warn 'loaded';

Legend:
Removed from v.461  
changed lines
  Added in v.546

  ViewVC Help
Powered by ViewVC 1.1.26