6 |
|
|
7 |
use server; |
use server; |
8 |
use pxelinux; |
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; |
|
my ($name, $value) = @_; |
|
16 |
|
|
17 |
my $path ="$server::base_dir/conf/$server::ip/$name"; |
our $server; |
18 |
if ( defined $value ) { |
our $server_ip; |
19 |
write_file $path, $value; |
|
20 |
} else { |
sub available { qw/katalog debian_live webconverger debirf tinycore nfsroot openvz printer wrt clonezilla ubuntu freedos/ }; |
|
$value = read_file $path if -e $path; |
|
|
} |
|
|
return $value; |
|
|
} |
|
21 |
|
|
22 |
sub debian_live { |
sub debian_live { |
23 |
$dhcpd::file = "pxelinux.0"; |
my ($ip) = @_; |
|
$pxelinux::path_prefix = 'live-helper/tftpboot/'; |
|
|
$pxelinux::config_file = 'pxelinux.cfg/default'; |
|
|
} |
|
24 |
|
|
25 |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
upstream::files( qw{ |
26 |
sub webconverger { |
http://cdimage.debian.org/cdimage/release/current-live/i386/web/ |
27 |
$dhcpd::file = "pxelinux.0"; |
vmlinuz1 |
28 |
$pxelinux::path_prefix = 'webconverger/'; |
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 |
my $dir = "$server::base_dir/tftp/$pxelinux::path_prefix"; |
} |
43 |
|
|
44 |
|
use upstream; |
45 |
|
|
46 |
mkdir $dir unless -d $dir; |
=head1 webconverger |
47 |
|
|
48 |
my $cfg = "$dir/pxelinux.cfg"; |
Webconverger - the opensource Web Kiosk |
|
return 1 if -e $cfg; |
|
49 |
|
|
50 |
mkdir $cfg; |
L<http://webconverger.org/> |
51 |
|
|
52 |
my $iso = '/srv/pxelator/iso/webc-5.2.iso'; |
=cut |
|
my $url = 'http://download.webconverger.com/webc-5.2.iso'; |
|
53 |
|
|
54 |
print STDERR "mirror $url"; |
sub webconverger { |
55 |
mirror( $url, $iso) |
my ($ip) = @_; |
|
== RC_NOT_MODIFIED |
|
|
&& warn(" not modified\n") |
|
|
|| warn(" done ", -s $iso, " bytes\n") |
|
|
; |
|
56 |
|
|
57 |
mkdir "$dir/iso" unless -e "$dir/iso"; |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' ); |
58 |
|
|
59 |
system "mount -t iso9660 | grep webc-5.2 || sudo mount $iso $dir/iso/ -o loop -t iso9660 -v"; |
my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger'; |
60 |
|
|
61 |
symlink "/usr/lib/syslinux/pxelinux.0", "$dir/$dhcpd::file"; |
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 |
$cfg .= '/default'; |
pxelinux::config_for_ip( $ip, qq{ |
67 |
|
|
68 |
write_file $cfg, qq{ |
default webconverger |
69 |
label webconverger |
label webconverger |
70 |
kernel iso/live/vmlinuz-2.6.30-backports.1-486 |
kernel iso/live/vmlinuz-2.6.30-backports.1-486 |
71 |
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 kioskresetstation=10 |
72 |
|
|
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 clonezilla { |
131 |
|
my $ip = shift; |
132 |
|
upstream::iso( 'http://sourceforge.net/projects/clonezilla/files/clonezilla_live_alternative_testing/clonezilla-live-20100503-lucid.iso/download' ); |
133 |
|
pxelinux::config_for_ip( $ip, qq{ |
134 |
|
|
135 |
|
default linux |
136 |
|
label linux |
137 |
|
kernel iso/live/vmlinuz |
138 |
|
append initrd=iso/live/initrd.img boot=live union=aufs noswap noprompt vga=788 fetch=http://$server_ip:7777/clonezilla/iso/live/filesystem.squashfs |
139 |
|
|
140 |
|
}); |
141 |
|
} |
142 |
|
|
143 |
|
sub ubuntu { |
144 |
|
my $ip = shift; |
145 |
|
upstream::iso( 'http://mirrors.us.kernel.org/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso' ); |
146 |
|
|
147 |
|
my $export = "$server::base_dir/tftp/ubuntu/iso"; |
148 |
|
my $exported = `exportfs | grep $export`; |
149 |
|
if ( $exported ne $export ) { |
150 |
|
warn "exportfs $exported\n"; |
151 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
152 |
|
} |
153 |
|
pxelinux::config_for_ip( $ip, qq{ |
154 |
|
|
155 |
|
default linux |
156 |
|
label linux |
157 |
|
kernel iso/casper/vmlinuz |
158 |
|
append initrd=iso/casper/initrd.lz boot=casper netboot=nfs nfsroot=$server_ip:$export -- |
159 |
|
|
160 |
|
}); |
161 |
|
} |
162 |
|
|
163 |
|
sub freedos { |
164 |
|
my $ip = shift; |
165 |
|
|
166 |
|
my $dir = "$server::base_dir/tftp/freedos"; |
167 |
|
mkdir $dir unless -e $dir; |
168 |
|
|
169 |
|
symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk"; |
170 |
|
|
171 |
|
my $floppy = 'freedos.img'; |
172 |
|
|
173 |
|
upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.img' => "$dir/$floppy"; |
174 |
|
|
175 |
|
pxelinux::config_for_ip( $ip, qq{ |
176 |
|
|
177 |
|
default freedos |
178 |
|
label freedos |
179 |
|
kernel memdisk |
180 |
|
append initrd=freedos.imz |
181 |
|
|
182 |
|
}); |
183 |
|
} |
184 |
|
|
185 |
|
sub in_chroot { |
186 |
|
my ( $dir, $command ) = @_; |
187 |
|
write_file "$dir/tmp/inside.sh", $command; |
188 |
|
system "sudo chroot $dir sh -x /tmp/inside.sh"; |
189 |
|
} |
190 |
|
|
191 |
|
sub nfsroot { |
192 |
|
my $ip = shift || die "no ip?"; |
193 |
|
|
194 |
|
my $dist = 'lenny'; |
195 |
|
$dist = 'squeeze'; |
196 |
|
|
197 |
|
my $nfsroot = "$server::base_dir/tftp/nfsroot"; |
198 |
|
my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' ); |
199 |
|
|
200 |
|
if ( ! -e $nfsroot ) { |
201 |
|
system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools"; |
202 |
|
mkdir $nfsroot; |
203 |
|
} |
204 |
|
|
205 |
|
my $debootstrap = "$nfsroot/debootstrap"; |
206 |
|
|
207 |
|
if ( ! -e $debootstrap ) { |
208 |
|
|
209 |
|
system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror"; |
210 |
|
|
211 |
|
file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n"; |
212 |
|
in_chroot $debootstrap => 'apt-get update'; |
213 |
|
|
214 |
|
file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n"; |
215 |
|
in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2'; |
216 |
|
|
217 |
|
# this can fails on some distros, so we run it alone |
218 |
|
in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686'; |
219 |
|
file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n"; |
220 |
|
|
221 |
|
file::change "$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs'; |
222 |
|
in_chroot $debootstrap => 'update-initramfs -u'; |
223 |
|
|
224 |
|
} |
225 |
|
|
226 |
|
my $export = "$nfsroot/$ip"; |
227 |
|
my $br = "$nfsroot/br/$ip"; |
228 |
|
|
229 |
|
$mounted->{"nfsroot/$ip"} ||= `mount | grep $export`; |
230 |
|
|
231 |
|
if ( ! $mounted->{"nfsroot/$ip"} ) { |
232 |
|
warn "mounting $export"; |
233 |
|
|
234 |
|
mkdir "$nfsroot/br" unless -e "$nfsroot/br"; |
235 |
|
mkdir $br unless -e $br; |
236 |
|
mkdir $export unless -e $export; |
237 |
|
|
238 |
|
system "sudo mount -t aufs -o br:$br:$debootstrap none $export"; |
239 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
240 |
|
|
241 |
|
} |
242 |
|
|
243 |
|
my $exported = `exportfs | grep $export`; |
244 |
|
if ( $exported ne $export ) { |
245 |
|
warn "exportfs $exported\n"; |
246 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
247 |
|
} |
248 |
|
|
249 |
|
my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot'; |
250 |
|
file::replace "$export/etc/hostname", $hostname; |
251 |
|
file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n"; |
252 |
|
file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n"; |
253 |
|
file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n"; |
254 |
|
|
255 |
|
file::append "$debootstrap/etc/network/interfaces", qq{ |
256 |
|
|
257 |
|
auto lo |
258 |
|
iface lo inet loopback |
259 |
|
|
260 |
|
allow-hotplug eth0 |
261 |
|
iface eth0 inet dhcp |
262 |
|
|
263 |
}; |
}; |
264 |
|
|
265 |
# $pxelinux::config_file = $cfg; |
map { |
266 |
|
file::copy_once $_ => "$export/$_"; |
267 |
|
file::append "$export/etc/rc.local", $_; |
268 |
|
} ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' ); |
269 |
|
|
270 |
|
pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" ); |
271 |
|
|
272 |
} |
} |
273 |
|
|
274 |
sub for_ip { |
sub openvz { |
275 |
my $ip = shift; |
my $ip = shift; |
276 |
# debian_live(); |
ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' ); |
277 |
webconverger(); |
} |
278 |
# $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix"; |
sub printer {} |
279 |
|
sub wrt {} |
280 |
|
|
281 |
|
sub for_ip { |
282 |
|
my $ip = shift || return; |
283 |
|
$server = server::as_hash_for $ip; |
284 |
|
$server_ip = $server->{ip} || die "no server ip"; |
285 |
|
my $config = client::conf( $ip => 'config' ) || return; |
286 |
|
eval $config . '($ip)'; # must be last |
287 |
} |
} |
288 |
|
|
289 |
warn 'loaded'; |
warn 'loaded'; |