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/katalog 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 noprompt |
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 |
70 |
|
|
71 |
=cut |
=cut |
72 |
|
|
73 |
|
sub _glob_first { |
74 |
|
my ( $dir, $path ) = @_; |
75 |
|
my @glob = glob "$dir/$path"; |
76 |
|
my $first = $glob[0] || die "no $dir/$path"; |
77 |
|
$dir =~ s{iso/*$}{}; |
78 |
|
$first =~ s{^\Q$dir\E}{}g; |
79 |
|
return $first; |
80 |
|
} |
81 |
|
|
82 |
sub webconverger { |
sub webconverger { |
83 |
my ($ip) = @_; |
my ($ip) = @_; |
84 |
|
|
85 |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' ); |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-6.2.iso' ); |
86 |
|
|
87 |
my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger'; |
my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger'; |
88 |
|
|
89 |
my $homepage = client::conf( $ip => 'webconverger/homepage' |
my $homepage = client::conf( $ip => 'webconverger/homepage' |
90 |
, default => "http://${server::ip}:7777/client" ); |
, default => "http://$server_ip:7777/client" ); |
91 |
my $fetch = client::conf( $ip => 'webconverger/fetch' |
my $fetch = client::conf( $ip => 'webconverger/fetch' |
92 |
, default => "http://${server::ip}:7777/webconverger/iso/live/filesystem.squashfs" ); |
, default => "http://$server_ip:7777/webconverger/iso/live/filesystem.squashfs" ); |
93 |
|
|
94 |
|
my $mnt = "$server::base_dir/tftp/webconverger/iso"; |
95 |
|
warn "# mnt: $mnt\n"; |
96 |
|
my $kernel = _glob_first $mnt => 'live/vmlinuz*'; |
97 |
|
my $initrd = _glob_first $mnt => 'live/initrd.img*'; |
98 |
|
|
99 |
pxelinux::config_for_ip( $ip, qq{ |
pxelinux::config_for_ip( $ip, qq{ |
100 |
|
|
101 |
default webconverger |
default webconverger |
102 |
label webconverger |
label webconverger |
103 |
kernel iso/live/vmlinuz-2.6.30-backports.1-486 |
kernel $kernel |
104 |
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 |
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 |
105 |
|
|
106 |
}); |
}); |
107 |
|
|
112 |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' ); |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' ); |
113 |
my $hostname = client::conf( $ip => 'hostname' ) || 'katalog'; |
my $hostname = client::conf( $ip => 'hostname' ) || 'katalog'; |
114 |
my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" ); |
my $homepage = client::conf( $ip => 'webconverger/homepage' => "http://koha.ffzg.hr" ); |
115 |
my $fetch = client::conf( $ip => 'webconverger/fetch' => "http://${server::ip}:7777/webconverger/custom.squashfs" ); |
my $fetch = client::conf( $ip => 'webconverger/fetch' => "http://$server_ip:7777/webconverger/custom.squashfs" ); |
116 |
|
|
117 |
pxelinux::config_for_ip( $ip, qq{ |
pxelinux::config_for_ip( $ip, qq{ |
118 |
|
|
149 |
|
|
150 |
sub tinycore { |
sub tinycore { |
151 |
my $ip = shift; |
my $ip = shift; |
152 |
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' ); |
153 |
pxelinux::config_for_ip( $ip, qq{ |
pxelinux::config_for_ip( $ip, qq{ |
154 |
|
|
155 |
default linux |
default linux |
160 |
}); |
}); |
161 |
} |
} |
162 |
|
|
163 |
|
sub clonezilla { |
164 |
|
my $ip = shift; |
165 |
|
upstream::iso( 'http://sourceforge.net/projects/clonezilla/files/clonezilla_live_alternative_testing/clonezilla-live-20100503-lucid.iso/download' ); |
166 |
|
pxelinux::config_for_ip( $ip, qq{ |
167 |
|
|
168 |
|
default linux |
169 |
|
label linux |
170 |
|
kernel iso/live/vmlinuz |
171 |
|
append initrd=iso/live/initrd.img boot=live union=aufs noswap noprompt vga=788 fetch=http://$server_ip:7777/clonezilla/iso/live/filesystem.squashfs |
172 |
|
|
173 |
|
}); |
174 |
|
} |
175 |
|
|
176 |
|
sub ubuntu { |
177 |
|
my $ip = shift; |
178 |
|
upstream::iso( 'http://mirrors.us.kernel.org/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso' ); |
179 |
|
|
180 |
|
my $export = "$server::base_dir/tftp/ubuntu/iso"; |
181 |
|
my $exported = `exportfs | grep $export`; |
182 |
|
if ( $exported ne $export ) { |
183 |
|
warn "exportfs $exported\n"; |
184 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
185 |
|
} |
186 |
|
pxelinux::config_for_ip( $ip, qq{ |
187 |
|
|
188 |
|
default linux |
189 |
|
label linux |
190 |
|
kernel iso/casper/vmlinuz |
191 |
|
append initrd=iso/casper/initrd.lz boot=casper netboot=nfs nfsroot=$server_ip:$export -- |
192 |
|
|
193 |
|
}); |
194 |
|
} |
195 |
|
|
196 |
|
sub memdisk { |
197 |
|
my $ip = shift; |
198 |
|
|
199 |
|
my $dir = "$server::base_dir/tftp/memdisk"; |
200 |
|
mkdir $dir unless -e $dir; |
201 |
|
|
202 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
203 |
|
|
204 |
|
my $image = client::conf( $ip => 'memdisk.image' ); |
205 |
|
|
206 |
|
if ( ! $image ) { |
207 |
|
$image = 'freedos.gz'; |
208 |
|
upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.imz' => "$dir/$image"; |
209 |
|
warn "using $image [default FreeDOS]\n"; |
210 |
|
symlink "$dir/$image", client::ip_path $ip . '/memdisk.image'; |
211 |
|
} else { |
212 |
|
$image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n"; |
213 |
|
} |
214 |
|
|
215 |
|
if ( my $kvm = client::conf $ip => 'kvm' ) { |
216 |
|
client::conf $ip => 'kvm.bin', 'qemu-system-i386'; # FIXME kvm doesn't seem to work |
217 |
|
} |
218 |
|
|
219 |
|
pxelinux::config_for_ip( $ip, qq{ |
220 |
|
|
221 |
|
default $image |
222 |
|
label $image |
223 |
|
kernel memdisk |
224 |
|
append initrd=$image |
225 |
|
|
226 |
|
}); |
227 |
|
} |
228 |
|
|
229 |
|
sub vyatta { |
230 |
|
my $ip = shift; |
231 |
|
upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' ); |
232 |
|
|
233 |
|
my $dir = "$server::base_dir/tftp/vyatta"; |
234 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
235 |
|
|
236 |
|
pxelinux::config_for_ip( $ip, qq{ |
237 |
|
|
238 |
|
default vyatta |
239 |
|
label vyatta |
240 |
|
|
241 |
|
kernel iso/live/vmlinuz1 |
242 |
|
append initrd=iso/live/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta fetch=http://$server_ip:7777/vyatta/iso/live/filesystem.squashfs |
243 |
|
|
244 |
|
}); |
245 |
|
} |
246 |
|
|
247 |
|
sub android { |
248 |
|
my $ip = shift; |
249 |
|
my $path = upstream::iso( 'http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso' ); |
250 |
|
|
251 |
|
my $dir = "$server::base_dir/tftp/android"; |
252 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
253 |
|
|
254 |
|
client::conf $ip => 'kvm.boot' => "n -cdrom $path"; |
255 |
|
|
256 |
|
pxelinux::config_for_ip( $ip, qq{ |
257 |
|
|
258 |
|
default android-1.6-donut |
259 |
|
label android-1.6-donut |
260 |
|
|
261 |
|
kernel iso/kernel |
262 |
|
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 |
263 |
|
|
264 |
|
}); |
265 |
|
} |
266 |
|
|
267 |
sub in_chroot { |
sub in_chroot { |
268 |
my ( $dir, $command ) = @_; |
my ( $dir, $command ) = @_; |
269 |
write_file "$dir/tmp/inside.sh", $command; |
write_file "$dir/tmp/inside.sh", $command; |
273 |
sub nfsroot { |
sub nfsroot { |
274 |
my $ip = shift || die "no ip?"; |
my $ip = shift || die "no ip?"; |
275 |
|
|
276 |
|
my $dist = 'lenny'; |
277 |
|
$dist = 'squeeze'; |
278 |
|
|
279 |
my $nfsroot = "$server::base_dir/tftp/nfsroot"; |
my $nfsroot = "$server::base_dir/tftp/nfsroot"; |
280 |
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' ); |
281 |
|
|
288 |
|
|
289 |
if ( ! -e $debootstrap ) { |
if ( ! -e $debootstrap ) { |
290 |
|
|
291 |
system "sudo debootstrap --arch i386 lenny $debootstrap $debian_mirror"; |
system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror"; |
292 |
|
|
293 |
file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror lenny non-free\n"; |
file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n"; |
294 |
in_chroot $debootstrap => 'apt-get update'; |
in_chroot $debootstrap => 'apt-get update'; |
295 |
|
|
296 |
file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n"; |
file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n"; |
297 |
in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686 firmware-bnx2'; |
in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2'; |
|
in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales'; # linux-image-2.6-686 |
|
298 |
|
|
299 |
|
# this can fails on some distros, so we run it alone |
300 |
|
in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686'; |
301 |
file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n"; |
file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n"; |
302 |
file::change("$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs' ) && |
|
303 |
|
file::change "$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs'; |
304 |
in_chroot $debootstrap => 'update-initramfs -u'; |
in_chroot $debootstrap => 'update-initramfs -u'; |
305 |
|
|
306 |
} |
} |
322 |
|
|
323 |
} |
} |
324 |
|
|
325 |
|
my $exported = `exportfs | grep $export`; |
326 |
|
if ( $exported ne $export ) { |
327 |
|
warn "exportfs $exported\n"; |
328 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
329 |
|
} |
330 |
|
|
331 |
my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot'; |
my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot'; |
332 |
file::replace "$export/etc/hostname", $hostname; |
file::replace "$export/etc/hostname", $hostname; |
333 |
file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n"; |
file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n"; |
334 |
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"; |
335 |
file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server::ip\n"; |
file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n"; |
336 |
|
|
337 |
file::append "$debootstrap/etc/network/interfaces", qq{ |
file::append "$debootstrap/etc/network/interfaces", qq{ |
338 |
|
|
349 |
file::append "$export/etc/rc.local", $_; |
file::append "$export/etc/rc.local", $_; |
350 |
} ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' ); |
} ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' ); |
351 |
|
|
352 |
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 |
|
353 |
|
|
|
}); |
|
354 |
} |
} |
355 |
|
|
356 |
sub openvz { |
sub openvz { |
362 |
|
|
363 |
sub for_ip { |
sub for_ip { |
364 |
my $ip = shift || return; |
my $ip = shift || return; |
365 |
|
$server = server::as_hash_for $ip; |
366 |
|
$server_ip = $server->{ip} || die "no server ip"; |
367 |
my $config = client::conf( $ip => 'config' ) || return; |
my $config = client::conf( $ip => 'config' ) || return; |
368 |
eval $config . '($ip)'; |
my $ret = eval $config . '($ip)'; # must be last |
369 |
# $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix"; |
if ( $@ ) { |
370 |
|
warn "ERROR in executing $config($ip): $@\n"; |
371 |
|
$ret .= qq{<pre style="color:red">$@</pre>}; |
372 |
|
} |
373 |
|
return $ret; |
374 |
} |
} |
375 |
|
|
376 |
warn 'loaded'; |
warn 'loaded'; |