/[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 110 by dpavlin, Sun Aug 2 02:04:00 2009 UTC revision 470 by dpavlin, Mon Jan 4 23:19:31 2010 UTC
# Line 2  package config; Line 2  package config;
2    
3  use warnings;  use warnings;
4  use strict;  use strict;
5    use autodie;
6    
7  use server;  use server;
8    use pxelinux;
9    use client;
10    use file;
11    use ssh;
12    
13  use File::Slurp;  use File::Slurp;
14    
15  sub shared {  our $mounted;
16          my ($name, $value) = @_;  
17    our $server;
18    our $server_ip;
19    
20    sub available { qw/katalog debian_live webconverger debirf tinycore nfsroot openvz printer wrt/ };
21    
22    sub debian_live {
23            my ($ip) = @_;
24    
25            upstream::files( qw{
26                    http://cdimage.debian.org/cdimage/release/current-live/i386/web/
27                    vmlinuz1
28                    initrd1.img
29                    debian-live-501-i386-standard.squashfs
30            });
31    
32            my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live';
33    
34            pxelinux::config_for_ip( $ip, qq{
35    
36    default debian_live
37    label debian_live
38            kernel vmlinuz1
39            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
40            });
41    
42    }
43    
44    use upstream;
45    
46    =head1 webconverger
47    
48    Webconverger - the opensource Web Kiosk
49    
50    L<http://webconverger.org/>
51    
52    =cut
53    
54    sub webconverger {
55            my ($ip) = @_;
56    
57            $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
58    
59            my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';
60    
61            my $homepage = client::conf( $ip => 'webconverger/homepage'
62                    , default => "http://$server_ip:7777/client" );
63            my $fetch    = client::conf( $ip => 'webconverger/fetch'
64                    , default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" );
65    
66            pxelinux::config_for_ip( $ip, qq{
67    
68          my $path ="$server::base_dir/conf/$server::ip/$name";  default webconverger
69          if ( defined $value ) {  label webconverger
70                  write_file $path, $value;          kernel iso/live/vmlinuz-2.6.30-backports.1-486
71          } else {          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
72                  $value = read_file $path if -e $path;  
73            });
74    
75    }
76    
77    sub katalog {
78            my ($ip) = @_;
79            $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
80            my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';
81            my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );
82            my $fetch    = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" );
83    
84            pxelinux::config_for_ip( $ip, qq{
85    
86    default katalog
87    label katalog
88            kernel iso/live/vmlinuz-2.6.30-backports.1-486
89            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
90    
91            });
92    
93    }
94    =head1 debirf
95    
96    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.
97    
98    L<http://cmrg.fifthhorseman.net/wiki/debirf>
99    
100    =cut
101    
102    sub debirf {
103            my $ip = shift;
104    
105            upstream::iso( 'http://cmrg.mayfirst.org/debirf/debirf-rescue_lenny_2.6.26-1-686.iso' );
106    
107            pxelinux::config_for_ip( $ip, qq{
108    
109    default linux
110    label linux
111            kernel iso/vmlinuz-2.6.26-1-686
112            append initrd=iso//debirf-rescue_lenny_2.6.26-1-686.cgz
113    
114            });
115    }
116    
117    sub tinycore {
118            my $ip = shift;
119            upstream::iso( 'http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/2.x/release/tinycore_2.2.iso' );
120            pxelinux::config_for_ip( $ip, qq{
121    
122    default linux
123    label linux
124            kernel iso/boot/bzImage
125            append initrd=iso/boot/tinycore.gz
126    
127            });
128    }
129    
130    sub in_chroot {
131            my ( $dir, $command ) = @_;
132            write_file "$dir/tmp/inside.sh", $command;
133            system "sudo chroot $dir sh -x /tmp/inside.sh";
134    }
135    
136    sub nfsroot {
137            my $ip = shift || die "no ip?";
138    
139            my $dist = 'lenny';
140            $dist = 'squeeze';
141    
142            my $nfsroot = "$server::base_dir/tftp/nfsroot";
143            my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );
144    
145            if ( ! -e $nfsroot ) {
146                    system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools";
147                    mkdir $nfsroot;
148            }
149    
150            my $debootstrap = "$nfsroot/debootstrap";
151    
152            if ( ! -e $debootstrap ) {
153    
154                    system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror";
155    
156                    file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n";
157                    in_chroot     $debootstrap => 'apt-get update';
158    
159                    file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n";
160                    in_chroot     $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2';
161    
162                    # this can fails on some distros, so we run it alone
163                    in_chroot     $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';
164                    file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";
165    
166                    file::change "$debootstrap/etc/initramfs-tools/initramfs.conf",  'BOOT=local' => 'BOOT=nfs';
167                    in_chroot     $debootstrap => 'update-initramfs -u';
168    
169            }
170    
171            my $export = "$nfsroot/$ip";
172            my $br     = "$nfsroot/br/$ip";
173    
174            $mounted->{"nfsroot/$ip"} ||= `mount | grep $export`;
175    
176            if ( ! $mounted->{"nfsroot/$ip"} ) {
177                    warn "mounting $export";
178    
179                    mkdir "$nfsroot/br"     unless -e "$nfsroot/br";
180                    mkdir $br                       unless -e $br;
181                    mkdir $export           unless -e $export;
182    
183                    system "sudo mount -t aufs -o br:$br:$debootstrap none $export";
184                    system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
185            
186          }          }
187          return $value;  
188    
189            my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
190            file::replace "$export/etc/hostname", $hostname;
191            file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";
192            file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n";
193            file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n";
194    
195            file::append "$debootstrap/etc/network/interfaces", qq{
196    
197    auto lo
198    iface lo inet loopback
199    
200    allow-hotplug eth0
201    iface eth0 inet dhcp
202    
203            };
204    
205            map {
206                    file::copy_once $_ => "$export/$_";
207                    file::append "$export/etc/rc.local", $_;
208            } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
209    
210            pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
211    
212  }  }
213    
214  sub for_ip {  sub openvz {
215          my $ip = shift;          my $ip = shift;
216          $tftp::dir = "$server::base_dir/tftp/live-helper/tftpboot";          ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' );
         $dhcpd::file = "pxelinux.0";  
217  }  }
218    sub printer     {}
219    sub wrt         {}
220    
221    sub for_ip {
222            my $ip = shift || return;
223            $server = server::as_hash_for $ip;
224            $server_ip = $server->{ip} || die "no server ip";
225            my $config = client::conf( $ip => 'config' ) || return;
226            eval $config . '($ip)'; # must be last
227    }
228    
229    warn 'loaded';
230    
231  1;  1;

Legend:
Removed from v.110  
changed lines
  Added in v.470

  ViewVC Help
Powered by ViewVC 1.1.26