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

Contents of /lib/PXElator/config.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 531 - (show annotations)
Fri Sep 17 18:51:36 2010 UTC (13 years, 7 months ago) by dpavlin
File size: 9538 byte(s)
upgrade tinycore to 3.x-current
1 package config;
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 use server;
8 use pxelinux;
9 use client;
10 use file;
11 use ssh;
12
13 use File::Slurp;
14
15 our $mounted;
16
17 our $server;
18 our $server_ip;
19
20 sub available { qw/katalog debian_live webconverger debirf tinycore nfsroot openvz printer wrt clonezilla ubuntu memdisk vyatta android/ };
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 default webconverger
69 label webconverger
70 kernel iso/live/vmlinuz-2.6.30-backports.1-486
71 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/3.x/release/tinycore-current.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 memdisk {
164 my $ip = shift;
165
166 my $dir = "$server::base_dir/tftp/memdisk";
167 mkdir $dir unless -e $dir;
168
169 symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
170
171 my $image = client::conf( $ip => 'memdisk.image' );
172
173 if ( ! $image ) {
174 $image = 'freedos.gz';
175 upstream::mirror_file 'http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/unofficial/balder/balder10.imz' => "$dir/$image";
176 warn "using $image [default FreeDOS]\n";
177 symlink "$dir/$image", client::ip_path $ip . '/memdisk.image';
178 } else {
179 $image =~ s{^.+/tftp/memdisk/}{} && warn "using $image\n";
180 }
181
182 if ( my $kvm = client::conf $ip => 'kvm' ) {
183 client::conf $ip => 'kvm.bin', 'qemu-system-i386'; # FIXME kvm doesn't seem to work
184 }
185
186 pxelinux::config_for_ip( $ip, qq{
187
188 default $image
189 label $image
190 kernel memdisk
191 append initrd=$image
192
193 });
194 }
195
196 sub vyatta {
197 my $ip = shift;
198 upstream::iso( 'http://www.vyatta.com/downloads/vc6.1/vyatta-livecd_VC6.1-2010.08.20_i386.iso' );
199
200 my $dir = "$server::base_dir/tftp/vyatta";
201 symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
202
203 pxelinux::config_for_ip( $ip, qq{
204
205 default vyatta
206 label vyatta
207
208 kernel iso/live/vmlinuz1
209 append initrd=iso/live/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta fetch=http://$server_ip:7777/vyatta/iso/live/filesystem.squashfs
210
211 });
212 }
213
214 sub android {
215 my $ip = shift;
216 my $path = upstream::iso( 'http://android-x86.googlecode.com/files/android-x86-1.6-r2.iso' );
217
218 my $dir = "$server::base_dir/tftp/android";
219 symlink '/usr/lib/syslinux/memdisk', "$dir/memdisk" unless -e "$dir/memdisk";
220
221 client::conf $ip => 'kvm.boot' => "n -cdrom $path";
222
223 pxelinux::config_for_ip( $ip, qq{
224
225 default android-1.6-donut
226 label android-1.6-donut
227
228 kernel iso/kernel
229 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
230
231 });
232 }
233
234 sub in_chroot {
235 my ( $dir, $command ) = @_;
236 write_file "$dir/tmp/inside.sh", $command;
237 system "sudo chroot $dir sh -x /tmp/inside.sh";
238 }
239
240 sub nfsroot {
241 my $ip = shift || die "no ip?";
242
243 my $dist = 'lenny';
244 $dist = 'squeeze';
245
246 my $nfsroot = "$server::base_dir/tftp/nfsroot";
247 my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' );
248
249 if ( ! -e $nfsroot ) {
250 system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools";
251 mkdir $nfsroot;
252 }
253
254 my $debootstrap = "$nfsroot/debootstrap";
255
256 if ( ! -e $debootstrap ) {
257
258 system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror";
259
260 file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n";
261 in_chroot $debootstrap => 'apt-get update';
262
263 file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n";
264 in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2';
265
266 # this can fails on some distros, so we run it alone
267 in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686';
268 file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n";
269
270 file::change "$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs';
271 in_chroot $debootstrap => 'update-initramfs -u';
272
273 }
274
275 my $export = "$nfsroot/$ip";
276 my $br = "$nfsroot/br/$ip";
277
278 $mounted->{"nfsroot/$ip"} ||= `mount | grep $export`;
279
280 if ( ! $mounted->{"nfsroot/$ip"} ) {
281 warn "mounting $export";
282
283 mkdir "$nfsroot/br" unless -e "$nfsroot/br";
284 mkdir $br unless -e $br;
285 mkdir $export unless -e $export;
286
287 system "sudo mount -t aufs -o br:$br:$debootstrap none $export";
288 system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
289
290 }
291
292 my $exported = `exportfs | grep $export`;
293 if ( $exported ne $export ) {
294 warn "exportfs $exported\n";
295 system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export";
296 }
297
298 my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot';
299 file::replace "$export/etc/hostname", $hostname;
300 file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n";
301 file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n";
302 file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n";
303
304 file::append "$debootstrap/etc/network/interfaces", qq{
305
306 auto lo
307 iface lo inet loopback
308
309 allow-hotplug eth0
310 iface eth0 inet dhcp
311
312 };
313
314 map {
315 file::copy_once $_ => "$export/$_";
316 file::append "$export/etc/rc.local", $_;
317 } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
318
319 pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
320
321 }
322
323 sub openvz {
324 my $ip = shift;
325 ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' );
326 }
327 sub printer {}
328 sub wrt {}
329
330 sub for_ip {
331 my $ip = shift || return;
332 $server = server::as_hash_for $ip;
333 $server_ip = $server->{ip} || die "no server ip";
334 my $config = client::conf( $ip => 'config' ) || return;
335 eval $config . '($ip)'; # must be last
336 }
337
338 warn 'loaded';
339
340 1;

  ViewVC Help
Powered by ViewVC 1.1.26