7 |
use server; |
use server; |
8 |
use pxelinux; |
use pxelinux; |
9 |
use client; |
use client; |
10 |
|
use file; |
11 |
|
use ssh; |
12 |
|
|
13 |
use File::Slurp; |
use File::Slurp; |
14 |
|
|
15 |
sub available { qw/debian_live webconverger debirf tinycore nfsroot/ }; |
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/ }; |
21 |
|
|
22 |
sub debian_live { |
sub debian_live { |
23 |
my ($ip) = @_; |
my ($ip) = @_; |
36 |
default debian_live |
default debian_live |
37 |
label debian_live |
label debian_live |
38 |
kernel vmlinuz1 |
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 |
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 |
} |
} |
54 |
sub webconverger { |
sub webconverger { |
55 |
my ($ip) = @_; |
my ($ip) = @_; |
56 |
|
|
57 |
upstream::iso( 'http://download.webconverger.com/webc-5.2.iso' ); |
$mounted->{"webconverger/$ip"} ||= upstream::iso( 'http://download.webconverger.com/webc-5.5.iso' ); |
58 |
|
|
|
my $homepage = client::conf( $ip => 'homepage', default => "http://${server::ip}:7777/client" ); |
|
59 |
my $hostname = client::conf( $ip => 'hostname' ) || 'webconverger'; |
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{ |
pxelinux::config_for_ip( $ip, qq{ |
67 |
|
|
68 |
default webconverger |
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://${server::ip}:7777/webconverger/iso/live/filesystem.squashfs boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage locale=hr |
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 |
=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. |
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. |
127 |
}); |
}); |
128 |
} |
} |
129 |
|
|
130 |
sub nfsroot { |
sub clonezilla { |
131 |
my $ip = shift; |
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 |
|
sub in_chroot { |
143 |
|
my ( $dir, $command ) = @_; |
144 |
|
write_file "$dir/tmp/inside.sh", $command; |
145 |
|
system "sudo chroot $dir sh -x /tmp/inside.sh"; |
146 |
|
} |
147 |
|
|
148 |
|
sub nfsroot { |
149 |
|
my $ip = shift || die "no ip?"; |
150 |
|
|
151 |
|
my $dist = 'lenny'; |
152 |
|
$dist = 'squeeze'; |
153 |
|
|
154 |
my $nfsroot = "$server::base_dir/tftp/nfsroot"; |
my $nfsroot = "$server::base_dir/tftp/nfsroot"; |
155 |
|
my $debian_mirror = server::conf_default( 'debian_mirror', 'http://ftp.debian.org/debian' ); |
156 |
|
|
157 |
if ( ! -e $nfsroot ) { |
if ( ! -e $nfsroot ) { |
158 |
system "apt-get install nfs-kernel-server debootstrap"; |
system "sudo apt-get install nfs-kernel-server debootstrap aufs-modules-`uname -r` aufs-tools"; |
159 |
|
mkdir $nfsroot; |
160 |
if ( ! -e $nfsroot ) { |
} |
161 |
mkdir $nfsroot; |
|
162 |
system "debootstrap --arch i386 lenny $nfsroot http://ftp.hr.debian.org/debian"; |
my $debootstrap = "$nfsroot/debootstrap"; |
163 |
} |
|
164 |
|
if ( ! -e $debootstrap ) { |
165 |
|
|
166 |
write_file "$nfsroot/tmp/configure.sh", qq{ |
system "sudo debootstrap --arch i386 $dist $debootstrap $debian_mirror"; |
|
echo "do_initrd = Yes" > /etc/kernel-img.conf |
|
167 |
|
|
168 |
# apt-get install kernel-image-686 |
file::append "$debootstrap/etc/apt/sources.list.d/non-free.list", "deb $debian_mirror $dist non-free\n"; |
169 |
apt-get install atl2-modules-2.6-686 |
in_chroot $debootstrap => 'apt-get update'; |
|
echo atl2 >> /etc/initramfs-tools/modules |
|
170 |
|
|
171 |
cat /etc/initramfs-tools/initramfs.conf | sed 's/BOOT=local/BOOT=nfs/' > /tmp/initramfs.conf \ |
file::append "$debootstrap/etc/kernel-img.conf", "do_initrd = Yes\n"; |
172 |
&& mv /tmp/initramfs.conf /etc/initramfs-tools/initramfs.conf |
in_chroot $debootstrap => 'apt-get -f install -y --force-yes locales linux-image-2.6-686 firmware-bnx2'; |
173 |
|
|
174 |
update-initramfs -u -v |
# this can fails on some distros, so we run it alone |
175 |
|
in_chroot $debootstrap => 'apt-get install -y --force-yes atl2-modules-2.6-686'; |
176 |
|
file::append "$debootstrap/etc/initramfs-tools/modules", "atl2\n"; |
177 |
|
|
178 |
}; |
file::change "$debootstrap/etc/initramfs-tools/initramfs.conf", 'BOOT=local' => 'BOOT=nfs'; |
179 |
|
in_chroot $debootstrap => 'update-initramfs -u'; |
180 |
|
|
181 |
system "chroot $nfsroot /tmp/configure.sh"; |
} |
182 |
|
|
183 |
|
my $export = "$nfsroot/$ip"; |
184 |
|
my $br = "$nfsroot/br/$ip"; |
185 |
|
|
186 |
|
$mounted->{"nfsroot/$ip"} ||= `mount | grep $export`; |
187 |
|
|
188 |
open(my $exports, '>>', '/etc/exports'); |
if ( ! $mounted->{"nfsroot/$ip"} ) { |
189 |
print $exports "$nfsroot\t$server::ip/$server::netmask(rw,async,no_root_squash,no_subtree_check)\n"; |
warn "mounting $export"; |
|
close($exports); |
|
190 |
|
|
191 |
system "exportfs -rva"; |
mkdir "$nfsroot/br" unless -e "$nfsroot/br"; |
192 |
|
mkdir $br unless -e $br; |
193 |
|
mkdir $export unless -e $export; |
194 |
|
|
195 |
|
system "sudo mount -t aufs -o br:$br:$debootstrap none $export"; |
196 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
197 |
|
|
198 |
} |
} |
199 |
|
|
200 |
pxelinux::config_for_ip( $ip, qq{ |
my $exported = `exportfs | grep $export`; |
201 |
|
if ( $exported ne $export ) { |
202 |
|
warn "exportfs $exported\n"; |
203 |
|
system "sudo exportfs -i -o rw,async,no_root_squash,no_subtree_check,fsid=999 $ip:$export"; |
204 |
|
} |
205 |
|
|
206 |
default nfsroot |
my $hostname = client::conf( $ip => 'hostname' ) || 'nfsroot'; |
207 |
label nfsroot |
file::replace "$export/etc/hostname", $hostname; |
208 |
kernel vmlinuz |
file::replace "$export/etc/hosts", "127.0.0.1\tlocalhost $hostname\n"; |
209 |
append initrd=initrd.img root=/dev/nfs nfsroot=$server::ip:$nfsroot ro ip=dhcp |
file::replace "$export/etc/resolv.conf", "domain $server->{domain}\nnameserver $server->{ip}\n"; |
210 |
|
file::replace "$export/etc/rsyslog.d/pxelator.conf", "*.*\t\@$server->{ip}\n"; |
211 |
|
|
212 |
|
file::append "$debootstrap/etc/network/interfaces", qq{ |
213 |
|
|
214 |
|
auto lo |
215 |
|
iface lo inet loopback |
216 |
|
|
217 |
|
allow-hotplug eth0 |
218 |
|
iface eth0 inet dhcp |
219 |
|
|
220 |
|
}; |
221 |
|
|
222 |
|
map { |
223 |
|
file::copy_once $_ => "$export/$_"; |
224 |
|
file::append "$export/etc/rc.local", $_; |
225 |
|
} ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' ); |
226 |
|
|
227 |
|
pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" ); |
228 |
|
|
|
}); |
|
229 |
} |
} |
230 |
|
|
231 |
sub for_ip { |
sub openvz { |
232 |
my $ip = shift; |
my $ip = shift; |
233 |
my $deploy = client::conf( $ip => 'deploy', default => 'webconverger' ); |
ssh::shell( $ip, 'cat /proc/vz/veinfo', 'vzlist -a', 'uptime', 'free', 'df', 'zfs list' ); |
234 |
eval $deploy . '($ip)'; |
} |
235 |
# $tftp::dir = "$server::base_dir/tftp/$pxelinux::path_prefix"; |
sub printer {} |
236 |
|
sub wrt {} |
237 |
|
|
238 |
|
sub for_ip { |
239 |
|
my $ip = shift || return; |
240 |
|
$server = server::as_hash_for $ip; |
241 |
|
$server_ip = $server->{ip} || die "no server ip"; |
242 |
|
my $config = client::conf( $ip => 'config' ) || return; |
243 |
|
eval $config . '($ip)'; # must be last |
244 |
} |
} |
245 |
|
|
246 |
warn 'loaded'; |
warn 'loaded'; |