/[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

Annotation of /lib/PXElator/config.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 565 - (hide annotations)
Wed Nov 9 11:58:06 2011 UTC (9 years, 8 months ago) by dpavlin
File size: 11543 byte(s)
use current-live debian images
1 dpavlin 74 package config;
2    
3     use warnings;
4     use strict;
5 dpavlin 135 use autodie;
6 dpavlin 74
7     use server;
8 dpavlin 129 use pxelinux;
9 dpavlin 156 use client;
10 dpavlin 271 use file;
11 dpavlin 348 use ssh;
12 dpavlin 534 use upstream;
13 dpavlin 271
14 dpavlin 74 use File::Slurp;
15    
16 dpavlin 273 our $mounted;
17    
18 dpavlin 470 our $server;
19     our $server_ip;
20    
21 dpavlin 546 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 dpavlin 550 memtest
28 dpavlin 546 / };
29 dpavlin 153
30 dpavlin 129 sub debian_live {
31 dpavlin 232 my ($ip) = @_;
32    
33 dpavlin 534 my $from = 'http://cdimage.debian.org/cdimage/release/current-live/i386/web/';
34     my $variant = 'standard';
35 dpavlin 232
36 dpavlin 534 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 dpavlin 234 my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live';
52    
53 dpavlin 538 # FIXME drop in shell because users doesn't work in current image
54     my $custom_init = 'init=/bin/hash';
55 dpavlin 534
56 dpavlin 538 if ( my $custom_squashfs = client::conf( $ip => 'squashfs' ) ) {
57     $squashfs = $custom_squashfs;
58     $custom_init = '';
59     }
60    
61 dpavlin 232 pxelinux::config_for_ip( $ip, qq{
62    
63     default debian_live
64     label debian_live
65 dpavlin 534 kernel $vmlinuz
66 dpavlin 538 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 dpavlin 234 });
68 dpavlin 232
69 dpavlin 129 }
70    
71 dpavlin 142 =head1 webconverger
72    
73     Webconverger - the opensource Web Kiosk
74    
75     L<http://webconverger.org/>
76    
77     =cut
78    
79 dpavlin 539 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 dpavlin 129 sub webconverger {
89 dpavlin 153 my ($ip) = @_;
90 dpavlin 129
91 dpavlin 539 $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-6.2.iso' );
92 dpavlin 129
93 dpavlin 201 my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger';
94 dpavlin 151
95 dpavlin 444 my $homepage = client::conf( $ip => 'webconverger/homepage'
96 dpavlin 470 , default => "http://$server_ip:7777/client" );
97 dpavlin 444 my $fetch = client::conf( $ip => 'webconverger/fetch'
98 dpavlin 470 , default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" );
99 dpavlin 444
100 dpavlin 539 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 dpavlin 138 pxelinux::config_for_ip( $ip, qq{
106 dpavlin 129
107 dpavlin 138 default webconverger
108 dpavlin 135 label webconverger
109 dpavlin 539 kernel $kernel
110     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 dpavlin 135
112 dpavlin 138 });
113    
114 dpavlin 129 }
115    
116 dpavlin 450 sub katalog {
117     my ($ip) = @_;
118     $mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' );
119     my $hostname = client::conf( $ip => 'hostname' ) || 'katalog';
120     my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" );
121 dpavlin 470 my $fetch = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" );
122 dpavlin 450
123     pxelinux::config_for_ip( $ip, qq{
124    
125     default katalog
126     label katalog
127     kernel iso/live/vmlinuz-2.6.30-backports.1-486
128 dpavlin 558 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
129 dpavlin 450
130     });
131    
132     }
133 dpavlin 142 =head1 debirf
134    
135     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.
136    
137     L<http://cmrg.fifthhorseman.net/wiki/debirf>
138    
139     =cut
140    
141     sub debirf {
142     my $ip = shift;
143    
144     upstream::iso( 'http://cmrg.mayfirst.org/debirf/debirf-rescue_lenny_2.6.26-1-686.iso' );
145    
146     pxelinux::config_for_ip( $ip, qq{
147    
148     default linux
149     label linux
150     kernel iso/vmlinuz-2.6.26-1-686
151     append initrd=iso//debirf-rescue_lenny_2.6.26-1-686.cgz
152    
153     });
154     }
155    
156 dpavlin 145 sub tinycore {
157     my $ip = shift;
158 dpavlin 531 upstream::iso( 'http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/3.x/release/tinycore-current.iso' );
159 dpavlin 145 pxelinux::config_for_ip( $ip, qq{
160    
161     default linux
162     label linux
163     kernel iso/boot/bzImage
164     append initrd=iso/boot/tinycore.gz
165    
166     });
167     }
168    
169 dpavlin 501 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 dpavlin 503
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 dpavlin 513 sub memdisk {
203 dpavlin 506 my $ip = shift;
204    
205 dpavlin 513 my $dir = "$server::base_dir/tftp/memdisk";
206 dpavlin 506 mkdir $dir unless -e $dir;
207    
208     symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
209    
210 dpavlin 511 my $image = client::conf( $ip => 'memdisk.image' );
211 dpavlin 506
212 dpavlin 511 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 dpavlin 513 warn "using $image [default FreeDOS]\n";
216 dpavlin 517 symlink "$dir/$image", client::ip_path $ip . '/memdisk.image';
217 dpavlin 511 } else {
218 dpavlin 513 $image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n";
219 dpavlin 511 }
220 dpavlin 506
221 dpavlin 517 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 dpavlin 506 pxelinux::config_for_ip( $ip, qq{
226    
227 dpavlin 513 default $image
228     label $image
229 dpavlin 506 kernel memdisk
230 dpavlin 511 append initrd=$image
231 dpavlin 506
232     });
233     }
234    
235 dpavlin 519 sub vyatta {
236     my $ip = shift;
237 dpavlin 520 upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' );
238 dpavlin 519
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 dpavlin 524 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 dpavlin 546
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 dpavlin 550 # http://www.memtest.org/
296     sub memtest {
297     my $ip = shift;
298    
299     my $dir = "$server::base_dir/tftp/memtest";
300     mkdir $dir unless -e $dir;
301     symlink '/boot/memtest86+.bin', "$dir/memtest.bin" unless -e "$dir/memtest.bin";
302    
303     pxelinux::config_for_ip( $ip, qq{
304    
305     default memtest
306     label memtest
307     linux memtest.bin
308    
309     });
310     }
311    
312 dpavlin 271 sub in_chroot {
313     my ( $dir, $command ) = @_;
314     write_file "$dir/tmp/inside.sh", $command;
315     system "sudo chroot $dir sh -x /tmp/inside.sh";
316     }
317    
318 dpavlin 268 sub nfsroot {
319 dpavlin 277 my $ip = shift || die "no ip?";
320 dpavlin 268
321 dpavlin 461 my $dist = 'lenny';
322     $dist = 'squeeze';
323    
324 dpavlin 268 my $nfsroot = "$server::base_dir/tftp/nfsroot";
325 dpavlin 270 my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );
326 dpavlin 268
327     if ( ! -e $nfsroot ) {
328 dpavlin 271 system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools";
329     mkdir $nfsroot;
330     }
331 dpavlin 270
332 dpavlin 271 my $debootstrap = "$nfsroot/debootstrap";
333 dpavlin 268
334 dpavlin 271 if ( ! -e $debootstrap ) {
335 dpavlin 268
336 dpavlin 461 system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror";
337 dpavlin 268
338 dpavlin 461 file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n";
339 dpavlin 457 in_chroot $debootstrap => 'apt-get update';
340    
341     file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n";
342 dpavlin 461 in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2';
343 dpavlin 268
344 dpavlin 461 # this can fails on some distros, so we run it alone
345     in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';
346 dpavlin 271 file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";
347 dpavlin 461
348     file::change "$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs';
349 dpavlin 271 in_chroot $debootstrap => 'update-initramfs -u';
350 dpavlin 268
351     }
352    
353 dpavlin 271 my $export = "$nfsroot/$ip";
354     my $br = "$nfsroot/br/$ip";
355    
356 dpavlin 277 $mounted->{"nfsroot/$ip"} ||= `mount | grep $export`;
357    
358     if ( ! $mounted->{"nfsroot/$ip"} ) {
359 dpavlin 271 warn "mounting $export";
360    
361     mkdir "$nfsroot/br" unless -e "$nfsroot/br";
362     mkdir $br unless -e $br;
363     mkdir $export unless -e $export;
364    
365     system "sudo mount -t aufs -o br:$br:$debootstrap none $export";
366     system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
367    
368     }
369    
370 dpavlin 499 my $exported = `exportfs | grep $export`;
371     if ( $exported ne $export ) {
372     warn "exportfs $exported\n";
373     system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
374     }
375 dpavlin 460
376 dpavlin 277 my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
377     file::replace "$export/etc/hostname", $hostname;
378     file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";
379 dpavlin 460 file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n";
380     file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n";
381 dpavlin 271
382 dpavlin 277 file::append "$debootstrap/etc/network/interfaces", qq{
383    
384     auto lo
385     iface lo inet loopback
386    
387     allow-hotplug eth0
388     iface eth0 inet dhcp
389    
390     };
391    
392 dpavlin 293 map {
393     file::copy_once $_ => "$export/$_";
394     file::append "$export/etc/rc.local", $_;
395     } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
396 dpavlin 277
397 dpavlin 463 pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
398 dpavlin 268
399     }
400    
401 dpavlin 350 sub openvz {
402 dpavlin 348 my $ip = shift;
403 dpavlin 434 ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' );
404 dpavlin 348 }
405 dpavlin 310 sub printer {}
406 dpavlin 317 sub wrt {}
407 dpavlin 310
408 dpavlin 110 sub for_ip {
409 dpavlin 285 my $ip = shift || return;
410 dpavlin 470 $server = server::as_hash_for $ip;
411     $server_ip = $server->{ip} || die "no server ip";
412 dpavlin 348 my $config = client::conf( $ip => 'config' ) || return;
413 dpavlin 533 my $ret = eval $config . '($ip)'; # must be last
414     if ( $@ ) {
415     warn "ERROR in executing $config($ip): $@\n";
416     $ret .= qq{<pre style="color:red">$@</pre>};
417     }
418     return $ret;
419 dpavlin 110 }
420    
421 dpavlin 135 warn 'loaded';
422    
423 dpavlin 74 1;

  ViewVC Help
Powered by ViewVC 1.1.26