/[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 268 by dpavlin, Wed Aug 19 17:01:57 2009 UTC revision 534 by dpavlin, Fri Sep 17 20:57:11 2010 UTC
# Line 7  use autodie; Line 7  use autodie;
7  use server;  use server;
8  use pxelinux;  use pxelinux;
9  use client;  use client;
10    use file;
11    use ssh;
12    use upstream;
13    
14  use File::Slurp;  use File::Slurp;
15    
16  sub available { qw/debian_live webconverger debirf tinycore nfsroot/ };  our $mounted;
17    
18    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 we can't create user
48    
49          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
50    
51  default debian_live  default debian_live
52  label debian_live  label debian_live
53          kernel vmlinuz1          kernel $vmlinuz
54          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 init=/bin/bash
55          });          });
56    
57  }  }
58    
 use upstream;  
   
59  =head1 webconverger  =head1 webconverger
60    
61  Webconverger - the opensource Web Kiosk  Webconverger - the opensource Web Kiosk
# Line 46  L<http://webconverger.org/> Line 67  L<http://webconverger.org/>
67  sub webconverger {  sub webconverger {
68          my ($ip) = @_;          my ($ip) = @_;
69    
70          upstream::iso( 'http://download.webconverger.com/webc-5.2.iso' );          $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
71    
         my $homepage = client::conf( $ip => 'homepage', default => "http://${server::ip}:7777/client" );  
72          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';          my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';
73    
74            my $homepage = client::conf( $ip => 'webconverger/homepage'
75                    , default => "http://$server_ip:7777/client" );
76            my $fetch    = client::conf( $ip => 'webconverger/fetch'
77                    , default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" );
78    
79          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
80    
81  default webconverger  default webconverger
82  label webconverger  label webconverger
83          kernel iso/live/vmlinuz-2.6.30-backports.1-486          kernel iso/live/vmlinuz-2.6.30-backports.1-486
84          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
85    
86          });          });
87    
88  }  }
89    
90    sub katalog {
91            my ($ip) = @_;
92            $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
93            my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';
94            my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );
95            my $fetch    = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" );
96    
97            pxelinux::config_for_ip( $ip, qq{
98    
99    default katalog
100    label katalog
101            kernel iso/live/vmlinuz-2.6.30-backports.1-486
102            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
103    
104            });
105    
106    }
107  =head1 debirf  =head1 debirf
108    
109  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 87  label linux Line 129  label linux
129    
130  sub tinycore {  sub tinycore {
131          my $ip = shift;          my $ip = shift;
132          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' );
133          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
134    
135  default linux  default linux
# Line 98  label linux Line 140  label linux
140          });          });
141  }  }
142    
143  sub nfsroot {  sub clonezilla {
144          my $ip = shift;          my $ip = shift;
145            upstream::iso( 'http://sourceforge.net/projects/clonezilla/files/clonezilla_live_alternative_testing/clonezilla-live-20100503-lucid.iso/download' );
146            pxelinux::config_for_ip( $ip, qq{
147    
148          my $nfsroot = "$server::base_dir/tftp/nfsroot";  default linux
149    label linux
150            kernel iso/live/vmlinuz
151            append initrd=iso/live/initrd.img boot=live union=aufs noswap noprompt vga=788 fetch=http://$server_ip:7777/clonezilla/iso/live/filesystem.squashfs
152    
153          if ( ! -e $nfsroot ) {          });
154                  system "apt-get install nfs-kernel-server debootstrap";  }
           
                 if ( ! -e $nfsroot ) {  
                         mkdir $nfsroot;  
                         system "debootstrap --arch i386 lenny $nfsroot http://ftp.hr.debian.org/debian";  
                 }  
155    
156                  write_file "$nfsroot/tmp/configure.sh", qq{  sub ubuntu {
157  echo "do_initrd = Yes" > /etc/kernel-img.conf          my $ip = shift;
158            upstream::iso( 'http://mirrors.us.kernel.org/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso' );
159    
160  # apt-get install kernel-image-686          my $export = "$server::base_dir/tftp/ubuntu/iso";
161  apt-get install atl2-modules-2.6-686          my $exported = `exportfs | grep $export`;
162  echo atl2 >> /etc/initramfs-tools/modules          if ( $exported ne $export ) {
163                    warn "exportfs $exported\n";
164                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
165            }
166            pxelinux::config_for_ip( $ip, qq{
167    
168    default linux
169    label linux
170            kernel iso/casper/vmlinuz
171            append initrd=iso/casper/initrd.lz boot=casper netboot=nfs nfsroot=$server_ip:$export --
172    
173  cat /etc/initramfs-tools/initramfs.conf | sed 's/BOOT=local/BOOT=nfs/' > /tmp/initramfs.conf \          });
174          && mv /tmp/initramfs.conf /etc/initramfs-tools/initramfs.conf  }
175    
176  update-initramfs -u -v  sub memdisk {
177            my $ip = shift;
178    
179  };          my $dir = "$server::base_dir/tftp/memdisk";
180            mkdir $dir unless -e $dir;
181    
182                  system "chroot $nfsroot /tmp/configure.sh";          symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
183    
184                  open(my $exports, '>>', '/etc/exports');          my $image = client::conf( $ip => 'memdisk.image' );
                 print $exports "$nfsroot\t$server::ip/$server::netmask(rw,async,no_root_squash,no_subtree_check)\n";  
                 close($exports);  
185    
186                  system "exportfs -rva";          if ( ! $image ) {
187                    $image = 'freedos.gz';
188                    upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.imz' => "$dir/$image";
189                    warn "using $image [default FreeDOS]\n";
190                    symlink "$dir/$image", client::ip_path $ip . '/memdisk.image';
191            } else {
192                    $image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n";
193            }
194    
195            if ( my $kvm = client::conf $ip => 'kvm' ) {
196                    client::conf $ip => 'kvm.bin', 'qemu-system-i386'; # FIXME kvm doesn't seem to work
197          }          }
198    
199          pxelinux::config_for_ip( $ip, qq{          pxelinux::config_for_ip( $ip, qq{
200    
201  default nfsroot  default $image
202  label nfsroot  label $image
203          kernel vmlinuz          kernel memdisk
204          append initrd=initrd.img root=/dev/nfs nfsroot=$server::ip:$nfsroot ro ip=dhcp          append initrd=$image
205    
206          });          });
207  }  }
208    
209  sub for_ip {  sub vyatta {
210            my $ip = shift;
211            upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' );
212    
213            my $dir = "$server::base_dir/tftp/vyatta";
214            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
215    
216            pxelinux::config_for_ip( $ip, qq{
217    
218    default vyatta
219    label vyatta
220    
221            kernel iso/live/vmlinuz1
222            append initrd=iso/live/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta fetch=http://$server_ip:7777/vyatta/iso/live/filesystem.squashfs
223    
224            });
225    }
226    
227    sub android {
228          my $ip = shift;          my $ip = shift;
229          my $deploy = client::conf( $ip => 'deploy', default => 'webconverger' );          my $path = upstream::iso( 'http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso' );
230          eval $deploy . '($ip)';  
231  #       $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix";          my $dir = "$server::base_dir/tftp/android";
232            symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
233    
234            client::conf $ip => 'kvm.boot' => "n -cdrom $path";
235    
236            pxelinux::config_for_ip( $ip, qq{
237    
238    default android-1.6-donut
239    label android-1.6-donut
240    
241            kernel iso/kernel
242            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
243    
244            });
245    }
246    
247    sub in_chroot {
248            my ( $dir, $command ) = @_;
249            write_file "$dir/tmp/inside.sh", $command;
250            system "sudo chroot $dir sh -x /tmp/inside.sh";
251    }
252    
253    sub nfsroot {
254            my $ip = shift || die "no ip?";
255    
256            my $dist = 'lenny';
257            $dist = 'squeeze';
258    
259            my $nfsroot = "$server::base_dir/tftp/nfsroot";
260            my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );
261    
262            if ( ! -e $nfsroot ) {
263                    system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools";
264                    mkdir $nfsroot;
265            }
266    
267            my $debootstrap = "$nfsroot/debootstrap";
268    
269            if ( ! -e $debootstrap ) {
270    
271                    system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror";
272    
273                    file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n";
274                    in_chroot     $debootstrap => 'apt-get update';
275    
276                    file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n";
277                    in_chroot     $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2';
278    
279                    # this can fails on some distros, so we run it alone
280                    in_chroot     $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';
281                    file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";
282    
283                    file::change "$debootstrap/etc/initramfs-tools/initramfs.conf",  'BOOT=local' => 'BOOT=nfs';
284                    in_chroot     $debootstrap => 'update-initramfs -u';
285    
286            }
287    
288            my $export = "$nfsroot/$ip";
289            my $br     = "$nfsroot/br/$ip";
290    
291            $mounted->{"nfsroot/$ip"} ||= `mount | grep $export`;
292    
293            if ( ! $mounted->{"nfsroot/$ip"} ) {
294                    warn "mounting $export";
295    
296                    mkdir "$nfsroot/br"     unless -e "$nfsroot/br";
297                    mkdir $br                       unless -e $br;
298                    mkdir $export           unless -e $export;
299    
300                    system "sudo mount -t aufs -o br:$br:$debootstrap none $export";
301                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
302            
303            }
304    
305            my $exported = `exportfs | grep $export`;
306            if ( $exported ne $export ) {
307                    warn "exportfs $exported\n";
308                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
309            }
310    
311            my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
312            file::replace "$export/etc/hostname", $hostname;
313            file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";
314            file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n";
315            file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n";
316    
317            file::append "$debootstrap/etc/network/interfaces", qq{
318    
319    auto lo
320    iface lo inet loopback
321    
322    allow-hotplug eth0
323    iface eth0 inet dhcp
324    
325            };
326    
327            map {
328                    file::copy_once $_ => "$export/$_";
329                    file::append "$export/etc/rc.local", $_;
330            } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
331    
332            pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
333    
334    }
335    
336    sub openvz {
337            my $ip = shift;
338            ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' );
339    }
340    sub printer     {}
341    sub wrt         {}
342    
343    sub for_ip {
344            my $ip = shift || return;
345            $server = server::as_hash_for $ip;
346            $server_ip = $server->{ip} || die "no server ip";
347            my $config = client::conf( $ip => 'config' ) || return;
348            my $ret = eval $config . '($ip)'; # must be last
349            if ( $@ ) {
350                    warn "ERROR in executing $config($ip): $@\n";
351                    $ret .= qq{<pre style="color:red">$@</pre>};
352            }
353            return $ret;
354  }  }
355    
356  warn 'loaded';  warn 'loaded';

Legend:
Removed from v.268  
changed lines
  Added in v.534

  ViewVC Help
Powered by ViewVC 1.1.26