/[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 350 by dpavlin, Sat Aug 29 21:09:55 2009 UTC revision 538 by dpavlin, Fri Sep 17 22:00:49 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/debian_live webconverger debirf tinycore nfsroot openvz printer wrt/ };  our $server;
19    our $server_ip;
20    
21    sub available { qw/katalog debian_live webconverger debirf tinycore nfsroot openvz printer wrt clonezilla ubuntu memdisk vyatta android/ };
22    
23  sub debian_live {  sub debian_live {
24          my ($ip) = @_;          my ($ip) = @_;
25    
26          upstream::files( qw{          my $from = 'http://cdimage.debian.org/cdimage/release/current-live/i386/web/';
27                  http://cdimage.debian.org/cdimage/release/current-live/i386/web/          $from = 'http://cdimage.debian.org/cdimage/squeeze_live_alpha2/i386/web/';
28                  vmlinuz1          my $variant = 'standard';
29                  initrd1.img  
30                  debian-live-501-i386-standard.squashfs          my $dir = upstream::files $from => 'MD5SUMS';
31          });  
32            my ( $vmlinuz, $initrd, $squashfs );
33            
34            my @md5sum = read_file "$dir/MD5SUMS";
35    
36            foreach ( @md5sum ) {
37                    $vmlinuz = $1 if m/\s+(\S*vmlinuz\S*)/;
38                    $initrd = $1 if m/\s+(\S*$variant\S*initrd\S*)/;
39                    $squashfs = $1 if m/\s+(\S*$variant\S*\.squashfs)$/;
40                    warn "# MD5SUM: $_\n";
41            }
42    
43            upstream::files $from => $vmlinuz, $initrd, $squashfs;
44    
45          my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live';          my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live';
46    
47            # FIXME drop in shell because users doesn't work in current image
48            my $custom_init = 'init=/bin/hash';
49    
50            if ( my $custom_squashfs = client::conf( $ip => 'squashfs' ) ) {
51                    $squashfs = $custom_squashfs;
52                    $custom_init = '';
53            }
54    
55          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
56    
57  default debian_live  default debian_live
58  label debian_live  label debian_live
59          kernel vmlinuz1          kernel $vmlinuz
60          append initrd=initrd1.img fetch=http://${server::ip}:7777/debian_live/debian-live-501-i386-standard.squashfs boot=live nopersistent hostname=$hostname union=aufs          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
61          });          });
62    
63  }  }
64    
 use upstream;  
   
65  =head1 webconverger  =head1 webconverger
66    
67  Webconverger - the opensource Web Kiosk  Webconverger - the opensource Web Kiosk
# Line 51  L<http://webconverger.org/> Line 73  L<http://webconverger.org/>
73  sub webconverger {  sub webconverger {
74          my ($ip) = @_;          my ($ip) = @_;
75    
76          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.2.iso' );          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
77    
         my $homepage = client::conf( $ip => 'homepage', default => "http://${server::ip}:7777/client" );  
78          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';
79    
80            my $homepage = client::conf( $ip => 'webconverger/homepage'
81                    , default => "http://$server_ip:7777/client" );
82            my $fetch    = client::conf( $ip => 'webconverger/fetch'
83                    , default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" );
84    
85          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
86    
87  default webconverger  default webconverger
88  label webconverger  label webconverger
89          kernel iso/live/vmlinuz-2.6.30-backports.1-486          kernel iso/live/vmlinuz-2.6.30-backports.1-486
90          append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=http://${server::ip}:7777/webconverger/iso/live/filesystem.squashfs boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr          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 kioskresetstation=10
91    
92          });          });
93    
94  }  }
95    
96    sub katalog {
97            my ($ip) = @_;
98            $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
99            my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';
100            my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );
101            my $fetch    = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" );
102    
103            pxelinux::config_for_ip( $ip, qq{
104    
105    default katalog
106    label katalog
107            kernel iso/live/vmlinuz-2.6.30-backports.1-486
108            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
109    
110            });
111    
112    }
113  =head1 debirf  =head1 debirf
114    
115  debirf is a system that will create diskless, all-in-ram images (kernel and initramfs) that boot entirely into ram and leave the user in a fully functional Debian system.  debirf is a system that will create diskless, all-in-ram images (kernel and initramfs) that boot entirely into ram and leave the user in a fully functional Debian system.
# Line 92  label linux Line 135  label linux
135    
136  sub tinycore {  sub tinycore {
137          my $ip = shift;          my $ip = shift;
138          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' );
139          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
140    
141  default linux  default linux
# Line 103  label linux Line 146  label linux
146          });          });
147  }  }
148    
149    sub clonezilla {
150            my $ip = shift;
151            upstream::iso( 'http://sourceforge.net/projects/clonezilla/files/clonezilla_live_alternative_testing/clonezilla-live-20100503-lucid.iso/download' );
152            pxelinux::config_for_ip( $ip, qq{
153    
154    default linux
155    label linux
156            kernel iso/live/vmlinuz
157            append initrd=iso/live/initrd.img boot=live union=aufs noswap noprompt vga=788 fetch=http://$server_ip:7777/clonezilla/iso/live/filesystem.squashfs
158    
159            });
160    }
161    
162    sub ubuntu {
163            my $ip = shift;
164            upstream::iso( 'http://mirrors.us.kernel.org/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso' );
165    
166            my $export = "$server::base_dir/tftp/ubuntu/iso";
167            my $exported = `exportfs | grep $export`;
168            if ( $exported ne $export ) {
169                    warn "exportfs $exported\n";
170                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
171            }
172            pxelinux::config_for_ip( $ip, qq{
173    
174    default linux
175    label linux
176            kernel iso/casper/vmlinuz
177            append initrd=iso/casper/initrd.lz boot=casper netboot=nfs nfsroot=$server_ip:$export --
178    
179            });
180    }
181    
182    sub memdisk {
183            my $ip = shift;
184    
185            my $dir = "$server::base_dir/tftp/memdisk";
186            mkdir $dir unless -e $dir;
187    
188            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
189    
190            my $image = client::conf( $ip => 'memdisk.image' );
191    
192            if ( ! $image ) {
193                    $image = 'freedos.gz';
194                    upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.imz' => "$dir/$image";
195                    warn "using $image [default FreeDOS]\n";
196                    symlink "$dir/$image", client::ip_path $ip . '/memdisk.image';
197            } else {
198                    $image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n";
199            }
200    
201            if ( my $kvm = client::conf $ip => 'kvm' ) {
202                    client::conf $ip => 'kvm.bin', 'qemu-system-i386'; # FIXME kvm doesn't seem to work
203            }
204    
205            pxelinux::config_for_ip( $ip, qq{
206    
207    default $image
208    label $image
209            kernel memdisk
210            append initrd=$image
211    
212            });
213    }
214    
215    sub vyatta {
216            my $ip = shift;
217            upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' );
218    
219            my $dir = "$server::base_dir/tftp/vyatta";
220            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
221    
222            pxelinux::config_for_ip( $ip, qq{
223    
224    default vyatta
225    label vyatta
226    
227            kernel iso/live/vmlinuz1
228            append initrd=iso/live/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta fetch=http://$server_ip:7777/vyatta/iso/live/filesystem.squashfs
229    
230            });
231    }
232    
233    sub android {
234            my $ip = shift;
235            my $path = upstream::iso( 'http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso' );
236    
237            my $dir = "$server::base_dir/tftp/android";
238            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
239    
240            client::conf $ip => 'kvm.boot' => "n -cdrom $path";
241    
242            pxelinux::config_for_ip( $ip, qq{
243    
244    default android-1.6-donut
245    label android-1.6-donut
246    
247            kernel iso/kernel
248            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
249    
250            });
251    }
252    
253  sub in_chroot {  sub in_chroot {
254          my ( $dir, $command ) = @_;          my ( $dir, $command ) = @_;
255          write_file "$dir/tmp/inside.sh", $command;          write_file "$dir/tmp/inside.sh", $command;
# Line 112  sub in_chroot { Line 259  sub in_chroot {
259  sub nfsroot {  sub nfsroot {
260          my $ip = shift || die "no ip?";          my $ip = shift || die "no ip?";
261    
262            my $dist = 'lenny';
263            $dist = 'squeeze';
264    
265          my $nfsroot = "$server::base_dir/tftp/nfsroot";          my $nfsroot = "$server::base_dir/tftp/nfsroot";
266          my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );          my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );
267    
# Line 124  sub nfsroot { Line 274  sub nfsroot {
274    
275          if ( ! -e $debootstrap ) {          if ( ! -e $debootstrap ) {
276    
277                  system "sudo debootstrap --arch i386 lenny $debootstrap $debian_mirror";                  system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror";
278    
279                  file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n" &&                  file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n";
280                  in_chroot     $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';                  in_chroot     $debootstrap => 'apt-get update';
281                  in_chroot     $debootstrap => 'apt-get -f install -y --force-yes locales';      # linux-image-2.6-686  
282                    file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n";
283                    in_chroot     $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2';
284    
285                    # this can fails on some distros, so we run it alone
286                    in_chroot     $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';
287                  file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";                  file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";
288                  file::change("$debootstrap/etc/initramfs-tools/initramfs.conf",  'BOOT=local' => 'BOOT=nfs' ) &&  
289                    file::change "$debootstrap/etc/initramfs-tools/initramfs.conf",  'BOOT=local' => 'BOOT=nfs';
290                  in_chroot     $debootstrap => 'update-initramfs -u';                  in_chroot     $debootstrap => 'update-initramfs -u';
291    
292          }          }
# Line 153  sub nfsroot { Line 308  sub nfsroot {
308                    
309          }          }
310    
311            my $exported = `exportfs | grep $export`;
312            if ( $exported ne $export ) {
313                    warn "exportfs $exported\n";
314                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
315            }
316    
317          my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';          my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
318          file::replace "$export/etc/hostname", $hostname;          file::replace "$export/etc/hostname", $hostname;
319          file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";          file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";
320          file::replace "$export/etc/resolv.conf", "domain $server::domain_name\nnameserver $server::ip\n";          file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n";
321          file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server::ip\n";          file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n";
322    
323          file::append "$debootstrap/etc/network/interfaces", qq{          file::append "$debootstrap/etc/network/interfaces", qq{
324    
# Line 174  iface eth0 inet dhcp Line 335  iface eth0 inet dhcp
335                  file::append "$export/etc/rc.local", $_;                  file::append "$export/etc/rc.local", $_;
336          } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );          } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
337    
338          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 debootstrap/vmlinuz  
         append initrd=debootstrap/initrd.img root=/dev/nfs nfsroot=$server::ip:$export ro ip=dhcp  
339    
         });  
340  }  }
341    
342  sub openvz {  sub openvz {
343          my $ip = shift;          my $ip = shift;
344          ssh::shell( $ip, 'cat /proc/vz/veinfo', 'uptime', 'free', 'df' );          ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' );
345  }  }
346  sub printer     {}  sub printer     {}
347  sub wrt         {}  sub wrt         {}
348    
349  sub for_ip {  sub for_ip {
350          my $ip = shift || return;          my $ip = shift || return;
351            $server = server::as_hash_for $ip;
352            $server_ip = $server->{ip} || die "no server ip";
353          my $config = client::conf( $ip => 'config' ) || return;          my $config = client::conf( $ip => 'config' ) || return;
354          eval $config . '($ip)';          my $ret = eval $config . '($ip)'; # must be last
355  #       $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix";          if ( $@ ) {
356                    warn "ERROR in executing $config($ip): $@\n";
357                    $ret .= qq{<pre style="color:red">$@</pre>};
358            }
359            return $ret;
360  }  }
361    
362  warn 'loaded';  warn 'loaded';

Legend:
Removed from v.350  
changed lines
  Added in v.538

  ViewVC Help
Powered by ViewVC 1.1.26