6 |
|
|
7 |
use server; |
use server; |
8 |
use pxelinux; |
use pxelinux; |
9 |
|
use client; |
10 |
|
use file; |
11 |
|
use ssh; |
12 |
|
use upstream; |
13 |
|
|
14 |
use File::Slurp; |
use File::Slurp; |
15 |
|
|
16 |
sub shared { |
our $mounted; |
|
my ($name, $value) = @_; |
|
17 |
|
|
18 |
my $path ="$server::base_dir/conf/$server::ip/$name"; |
our $server; |
19 |
if ( defined $value ) { |
our $server_ip; |
20 |
write_file $path, $value; |
|
21 |
} else { |
sub available { qw/ |
22 |
$value = read_file $path if -e $path; |
katalog debian_live webconverger |
23 |
|
debirf tinycore nfsroot |
24 |
|
openvz printer wrt |
25 |
|
clonezilla ubuntu memdisk vyatta android |
26 |
|
systemrescue |
27 |
|
memtest |
28 |
|
/ }; |
29 |
|
|
30 |
|
sub debian_live { |
31 |
|
my ($ip) = @_; |
32 |
|
|
33 |
|
my $from = 'http://cdimage.debian.org/cdimage/release/current-live/i386/web/'; |
34 |
|
$from = 'http://cdimage.debian.org/cdimage/squeeze_live_alpha2/i386/web/'; |
35 |
|
my $variant = 'standard'; |
36 |
|
|
37 |
|
my $dir = upstream::files $from => 'MD5SUMS'; |
38 |
|
|
39 |
|
my ( $vmlinuz, $initrd, $squashfs ); |
40 |
|
|
41 |
|
my @md5sum = read_file "$dir/MD5SUMS"; |
42 |
|
|
43 |
|
foreach ( @md5sum ) { |
44 |
|
$vmlinuz = $1 if m/\s+(\S*vmlinuz\S*)/; |
45 |
|
$initrd = $1 if m/\s+(\S*$variant\S*initrd\S*)/; |
46 |
|
$squashfs = $1 if m/\s+(\S*$variant\S*\.squashfs)$/; |
47 |
|
warn "# MD5SUM: $_\n"; |
48 |
} |
} |
49 |
return $value; |
|
50 |
|
upstream::files $from => $vmlinuz, $initrd, $squashfs; |
51 |
|
|
52 |
|
my $hostname = client::conf( $ip => 'hostname' ) || 'debian-live'; |
53 |
|
|
54 |
|
# FIXME drop in shell because users doesn't work in current image |
55 |
|
my $custom_init = 'init=/bin/hash'; |
56 |
|
|
57 |
|
if ( my $custom_squashfs = client::conf( $ip => 'squashfs' ) ) { |
58 |
|
$squashfs = $custom_squashfs; |
59 |
|
$custom_init = ''; |
60 |
|
} |
61 |
|
|
62 |
|
pxelinux::config_for_ip( $ip, qq{ |
63 |
|
|
64 |
|
default debian_live |
65 |
|
label debian_live |
66 |
|
kernel $vmlinuz |
67 |
|
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 |
68 |
|
}); |
69 |
|
|
70 |
} |
} |
71 |
|
|
72 |
sub debian_live { |
=head1 webconverger |
73 |
$dhcpd::file = "pxelinux.0"; |
|
74 |
$pxelinux::path_prefix = 'live-helper/tftpboot/'; |
Webconverger - the opensource Web Kiosk |
75 |
$pxelinux::config_file = 'pxelinux.cfg/default'; |
|
76 |
|
L<http://webconverger.org/> |
77 |
|
|
78 |
|
=cut |
79 |
|
|
80 |
|
sub _glob_first { |
81 |
|
my ( $dir, $path ) = @_; |
82 |
|
my @glob = glob "$dir/$path"; |
83 |
|
my $first = $glob[0] || die "no $dir/$path"; |
84 |
|
$dir =~ s{iso/*$}{}; |
85 |
|
$first =~ s{^\Q$dir\E}{}g; |
86 |
|
return $first; |
87 |
} |
} |
88 |
|
|
|
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
|
89 |
sub webconverger { |
sub webconverger { |
90 |
$dhcpd::file = "pxelinux.0"; |
my ($ip) = @_; |
|
$pxelinux::path_prefix = 'webconverger/'; |
|
91 |
|
|
92 |
my $dir = "$server::base_dir/tftp/$pxelinux::path_prefix"; |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-6.2.iso' ); |
93 |
|
|
94 |
mkdir $dir unless -d $dir; |
my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger'; |
95 |
|
|
96 |
my $cfg = "$dir/pxelinux.cfg"; |
my $homepage = client::conf( $ip => 'webconverger/homepage' |
97 |
return 1 if -e $cfg; |
, default => "http://$server_ip:7777/client" ); |
98 |
|
my $fetch = client::conf( $ip => 'webconverger/fetch' |
99 |
|
, default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" ); |
100 |
|
|
101 |
mkdir $cfg; |
my $mnt = "$server::base_dir/tftp/webconverger/iso"; |
102 |
|
warn "# mnt: $mnt\n"; |
103 |
|
my $kernel = _glob_first $mnt => 'live/vmlinuz*'; |
104 |
|
my $initrd = _glob_first $mnt => 'live/initrd.img*'; |
105 |
|
|
106 |
my $iso = '/srv/pxelator/iso/webc-5.2.iso'; |
pxelinux::config_for_ip( $ip, qq{ |
|
my $url = 'http://download.webconverger.com/webc-5.2.iso'; |
|
107 |
|
|
108 |
print STDERR "mirror $url"; |
default webconverger |
109 |
mirror( $url, $iso) |
label webconverger |
110 |
== RC_NOT_MODIFIED |
kernel $kernel |
111 |
&& warn(" not modified\n") |
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 |
|
|| warn(" done ", -s $iso, " bytes\n") |
|
|
; |
|
112 |
|
|
113 |
mkdir "$dir/iso" unless -e "$dir/iso"; |
}); |
114 |
|
|
115 |
system "mount -t iso9660 | grep webc-5.2 || sudo mount $iso $dir/iso/ -o loop -t iso9660 -v"; |
} |
116 |
|
|
117 |
symlink "/usr/lib/syslinux/pxelinux.0", "$dir/$dhcpd::file"; |
sub katalog { |
118 |
|
my ($ip) = @_; |
119 |
|
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' ); |
120 |
|
my $hostname = client::conf( $ip => 'hostname' ) || 'katalog'; |
121 |
|
my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" ); |
122 |
|
my $fetch = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" ); |
123 |
|
|
124 |
$cfg .= '/default'; |
pxelinux::config_for_ip( $ip, qq{ |
125 |
|
|
126 |
write_file $cfg, qq{ |
default katalog |
127 |
label webconverger |
label katalog |
128 |
kernel iso/live/vmlinuz-2.6.30-backports.1-486 |
kernel iso/live/vmlinuz-2.6.30-backports.1-486 |
129 |
append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=http://172.16.10.1/pxelator/webconverger/iso/live/filesystem.squashfs boot=live quiet homepage=http://172.16.10.1:7777/ nonetworking nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=webconverger union=aufs |
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 |
130 |
|
|
131 |
|
}); |
132 |
|
|
133 |
|
} |
134 |
|
=head1 debirf |
135 |
|
|
136 |
|
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. |
137 |
|
|
138 |
|
L<http://cmrg.fifthhorseman.net/wiki/debirf> |
139 |
|
|
140 |
|
=cut |
141 |
|
|
142 |
|
sub debirf { |
143 |
|
my $ip = shift; |
144 |
|
|
145 |
|
upstream::iso( 'http://cmrg.mayfirst.org/debirf/debirf-rescue_lenny_2.6.26-1-686.iso' ); |
146 |
|
|
147 |
|
pxelinux::config_for_ip( $ip, qq{ |
148 |
|
|
149 |
|
default linux |
150 |
|
label linux |
151 |
|
kernel iso/vmlinuz-2.6.26-1-686 |
152 |
|
append initrd=iso//debirf-rescue_lenny_2.6.26-1-686.cgz |
153 |
|
|
154 |
|
}); |
155 |
|
} |
156 |
|
|
157 |
|
sub tinycore { |
158 |
|
my $ip = shift; |
159 |
|
upstream::iso( 'http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/3.x/release/tinycore-current.iso' ); |
160 |
|
pxelinux::config_for_ip( $ip, qq{ |
161 |
|
|
162 |
|
default linux |
163 |
|
label linux |
164 |
|
kernel iso/boot/bzImage |
165 |
|
append initrd=iso/boot/tinycore.gz |
166 |
|
|
167 |
|
}); |
168 |
|
} |
169 |
|
|
170 |
|
sub clonezilla { |
171 |
|
my $ip = shift; |
172 |
|
upstream::iso( 'http://sourceforge.net/projects/clonezilla/files/clonezilla_live_alternative_testing/clonezilla-live-20100503-lucid.iso/download' ); |
173 |
|
pxelinux::config_for_ip( $ip, qq{ |
174 |
|
|
175 |
|
default linux |
176 |
|
label linux |
177 |
|
kernel iso/live/vmlinuz |
178 |
|
append initrd=iso/live/initrd.img boot=live union=aufs noswap noprompt vga=788 fetch=http://$server_ip:7777/clonezilla/iso/live/filesystem.squashfs |
179 |
|
|
180 |
|
}); |
181 |
|
} |
182 |
|
|
183 |
|
sub ubuntu { |
184 |
|
my $ip = shift; |
185 |
|
upstream::iso( 'http://mirrors.us.kernel.org/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso' ); |
186 |
|
|
187 |
|
my $export = "$server::base_dir/tftp/ubuntu/iso"; |
188 |
|
my $exported = `exportfs | grep $export`; |
189 |
|
if ( $exported ne $export ) { |
190 |
|
warn "exportfs $exported\n"; |
191 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
192 |
|
} |
193 |
|
pxelinux::config_for_ip( $ip, qq{ |
194 |
|
|
195 |
|
default linux |
196 |
|
label linux |
197 |
|
kernel iso/casper/vmlinuz |
198 |
|
append initrd=iso/casper/initrd.lz boot=casper netboot=nfs nfsroot=$server_ip:$export -- |
199 |
|
|
200 |
|
}); |
201 |
|
} |
202 |
|
|
203 |
|
sub memdisk { |
204 |
|
my $ip = shift; |
205 |
|
|
206 |
|
my $dir = "$server::base_dir/tftp/memdisk"; |
207 |
|
mkdir $dir unless -e $dir; |
208 |
|
|
209 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
210 |
|
|
211 |
|
my $image = client::conf( $ip => 'memdisk.image' ); |
212 |
|
|
213 |
|
if ( ! $image ) { |
214 |
|
$image = 'freedos.gz'; |
215 |
|
upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.imz' => "$dir/$image"; |
216 |
|
warn "using $image [default FreeDOS]\n"; |
217 |
|
symlink "$dir/$image", client::ip_path $ip . '/memdisk.image'; |
218 |
|
} else { |
219 |
|
$image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n"; |
220 |
|
} |
221 |
|
|
222 |
|
if ( my $kvm = client::conf $ip => 'kvm' ) { |
223 |
|
client::conf $ip => 'kvm.bin', 'qemu-system-i386'; # FIXME kvm doesn't seem to work |
224 |
|
} |
225 |
|
|
226 |
|
pxelinux::config_for_ip( $ip, qq{ |
227 |
|
|
228 |
|
default $image |
229 |
|
label $image |
230 |
|
kernel memdisk |
231 |
|
append initrd=$image |
232 |
|
|
233 |
|
}); |
234 |
|
} |
235 |
|
|
236 |
|
sub vyatta { |
237 |
|
my $ip = shift; |
238 |
|
upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' ); |
239 |
|
|
240 |
|
my $dir = "$server::base_dir/tftp/vyatta"; |
241 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
242 |
|
|
243 |
|
pxelinux::config_for_ip( $ip, qq{ |
244 |
|
|
245 |
|
default vyatta |
246 |
|
label vyatta |
247 |
|
|
248 |
|
kernel iso/live/vmlinuz1 |
249 |
|
append initrd=iso/live/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta fetch=http://$server_ip:7777/vyatta/iso/live/filesystem.squashfs |
250 |
|
|
251 |
|
}); |
252 |
|
} |
253 |
|
|
254 |
|
sub android { |
255 |
|
my $ip = shift; |
256 |
|
my $path = upstream::iso( 'http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso' ); |
257 |
|
|
258 |
|
my $dir = "$server::base_dir/tftp/android"; |
259 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
260 |
|
|
261 |
|
client::conf $ip => 'kvm.boot' => "n -cdrom $path"; |
262 |
|
|
263 |
|
pxelinux::config_for_ip( $ip, qq{ |
264 |
|
|
265 |
|
default android-1.6-donut |
266 |
|
label android-1.6-donut |
267 |
|
|
268 |
|
kernel iso/kernel |
269 |
|
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 |
270 |
|
|
271 |
|
}); |
272 |
|
} |
273 |
|
|
274 |
|
|
275 |
|
# http://www.sysresccd.org/Sysresccd-manual-en_PXE_network_booting |
276 |
|
sub systemrescue { |
277 |
|
my $ip = shift; |
278 |
|
my $path = upstream::iso( 'http://sourceforge.net/projects/systemrescuecd/files/sysresccd-x86/1.6.1/systemrescuecd-x86-1.6.1.iso/download' ); |
279 |
|
|
280 |
|
my $dir = "$server::base_dir/tftp/systemrescue"; |
281 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
282 |
|
|
283 |
|
client::conf $ip => 'kvm.boot' => "n -cdrom $path"; |
284 |
|
|
285 |
|
pxelinux::config_for_ip( $ip, qq{ |
286 |
|
|
287 |
|
default systemrescue |
288 |
|
label systemrescue |
289 |
|
|
290 |
|
kernel iso/isolinux/rescuecd |
291 |
|
append initrd=iso/isolinux/initram.igz dodhcp netboot=http://$server::ip:7777/systemrescue/iso/sysrcd.dat |
292 |
|
|
293 |
|
}); |
294 |
|
} |
295 |
|
|
296 |
|
# http://www.memtest.org/ |
297 |
|
sub memtest { |
298 |
|
my $ip = shift; |
299 |
|
|
300 |
|
my $dir = "$server::base_dir/tftp/memtest"; |
301 |
|
mkdir $dir unless -e $dir; |
302 |
|
symlink '/boot/memtest86+.bin', "$dir/memtest.bin" unless -e "$dir/memtest.bin"; |
303 |
|
|
304 |
|
pxelinux::config_for_ip( $ip, qq{ |
305 |
|
|
306 |
|
default memtest |
307 |
|
label memtest |
308 |
|
linux memtest.bin |
309 |
|
|
310 |
|
}); |
311 |
|
} |
312 |
|
|
313 |
|
sub in_chroot { |
314 |
|
my ( $dir, $command ) = @_; |
315 |
|
write_file "$dir/tmp/inside.sh", $command; |
316 |
|
system "sudo chroot $dir sh -x /tmp/inside.sh"; |
317 |
|
} |
318 |
|
|
319 |
|
sub nfsroot { |
320 |
|
my $ip = shift || die "no ip?"; |
321 |
|
|
322 |
|
my $dist = 'lenny'; |
323 |
|
$dist = 'squeeze'; |
324 |
|
|
325 |
|
my $nfsroot = "$server::base_dir/tftp/nfsroot"; |
326 |
|
my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' ); |
327 |
|
|
328 |
|
if ( ! -e $nfsroot ) { |
329 |
|
system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools"; |
330 |
|
mkdir $nfsroot; |
331 |
|
} |
332 |
|
|
333 |
|
my $debootstrap = "$nfsroot/debootstrap"; |
334 |
|
|
335 |
|
if ( ! -e $debootstrap ) { |
336 |
|
|
337 |
|
system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror"; |
338 |
|
|
339 |
|
file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n"; |
340 |
|
in_chroot $debootstrap => 'apt-get update'; |
341 |
|
|
342 |
|
file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n"; |
343 |
|
in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2'; |
344 |
|
|
345 |
|
# this can fails on some distros, so we run it alone |
346 |
|
in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686'; |
347 |
|
file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n"; |
348 |
|
|
349 |
|
file::change "$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs'; |
350 |
|
in_chroot $debootstrap => 'update-initramfs -u'; |
351 |
|
|
352 |
|
} |
353 |
|
|
354 |
|
my $export = "$nfsroot/$ip"; |
355 |
|
my $br = "$nfsroot/br/$ip"; |
356 |
|
|
357 |
|
$mounted->{"nfsroot/$ip"} ||= `mount | grep $export`; |
358 |
|
|
359 |
|
if ( ! $mounted->{"nfsroot/$ip"} ) { |
360 |
|
warn "mounting $export"; |
361 |
|
|
362 |
|
mkdir "$nfsroot/br" unless -e "$nfsroot/br"; |
363 |
|
mkdir $br unless -e $br; |
364 |
|
mkdir $export unless -e $export; |
365 |
|
|
366 |
|
system "sudo mount -t aufs -o br:$br:$debootstrap none $export"; |
367 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
368 |
|
|
369 |
|
} |
370 |
|
|
371 |
|
my $exported = `exportfs | grep $export`; |
372 |
|
if ( $exported ne $export ) { |
373 |
|
warn "exportfs $exported\n"; |
374 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
375 |
|
} |
376 |
|
|
377 |
|
my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot'; |
378 |
|
file::replace "$export/etc/hostname", $hostname; |
379 |
|
file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n"; |
380 |
|
file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n"; |
381 |
|
file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n"; |
382 |
|
|
383 |
|
file::append "$debootstrap/etc/network/interfaces", qq{ |
384 |
|
|
385 |
|
auto lo |
386 |
|
iface lo inet loopback |
387 |
|
|
388 |
|
allow-hotplug eth0 |
389 |
|
iface eth0 inet dhcp |
390 |
|
|
391 |
}; |
}; |
392 |
|
|
393 |
# $pxelinux::config_file = $cfg; |
map { |
394 |
|
file::copy_once $_ => "$export/$_"; |
395 |
|
file::append "$export/etc/rc.local", $_; |
396 |
|
} ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' ); |
397 |
|
|
398 |
|
pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" ); |
399 |
|
|
400 |
} |
} |
401 |
|
|
402 |
sub for_ip { |
sub openvz { |
403 |
my $ip = shift; |
my $ip = shift; |
404 |
# debian_live(); |
ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' ); |
405 |
webconverger(); |
} |
406 |
# $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix"; |
sub printer {} |
407 |
|
sub wrt {} |
408 |
|
|
409 |
|
sub for_ip { |
410 |
|
my $ip = shift || return; |
411 |
|
$server = server::as_hash_for $ip; |
412 |
|
$server_ip = $server->{ip} || die "no server ip"; |
413 |
|
my $config = client::conf( $ip => 'config' ) || return; |
414 |
|
my $ret = eval $config . '($ip)'; # must be last |
415 |
|
if ( $@ ) { |
416 |
|
warn "ERROR in executing $config($ip): $@\n"; |
417 |
|
$ret .= qq{<pre style="color:red">$@</pre>}; |
418 |
|
} |
419 |
|
return $ret; |
420 |
} |
} |
421 |
|
|
422 |
warn 'loaded'; |
warn 'loaded'; |