/[pxelator]/lib/PXElator/pxelinux.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/pxelinux.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 467 - (show annotations)
Mon Jan 4 22:43:03 2010 UTC (14 years, 3 months ago) by dpavlin
File size: 1516 byte(s)
default boot target from conf/

1 package pxelinux;
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 our $magic = 0xF100747E;
8
9 our $config_file; #= 'pxelinux.cfg/default';
10 our $path_prefix;
11 our $reboot_time; # 300 s
12
13 use server;
14 use client;
15 use File::Slurp;
16 use Carp qw/confess/;
17
18 sub config_for_ip {
19 my ($ip,$config) = @_;
20 confess "$ip not IP" unless $ip =~ m{^\d+\.\d+\.\d+\.\d+$};
21
22 $path_prefix = (caller(1))[3];
23 $path_prefix = (caller(2))[3] unless $path_prefix =~ m{config::};
24 $path_prefix =~ s{config::}{} || warn "# caller isn't package config !";
25 $path_prefix .= '/';
26
27 warn "# $ip $path_prefix";
28
29 my $dir = "$server::base_dir/tftp";
30 $dhcpd::file = 'pxelinux.0';
31 symlink "/usr/lib/syslinux/pxelinux.0", "$dir/$dhcpd::file" unless -e "$dir/$dhcpd::file";
32
33 $dir .= "/$path_prefix";
34 mkdir $dir unless -d $dir;
35
36 mkdir "$dir/pxelinux.cfg" unless -e "$dir/pxelinux.cfg";
37
38 $config_file = 'pxelinux.cfg/' . uc sprintf "%02x%02x%02x%02x", split(/\./, $ip, 4);
39 warn "$ip config_file $config_file";
40
41 my $path = "$dir/$config_file";
42 write_file $path, $config;
43
44 warn "# config: $path ", -s $path;
45
46 return $config;
47 }
48
49 sub config_ip_boot {
50 my ( $ip, $boot, $append ) = @_;
51
52 my $default = client::conf $ip => 'default';
53 my $config;
54
55 foreach my $kernel ( glob "$boot/vmlinuz*" ) {
56 my $ver = $1 if $kernel =~ m{vmlinuz(.+)};
57 $default ||= $ver;
58
59 $config .= qq{
60
61 label boot$ver
62 kernel $ip/boot/vmlinuz$ver
63 append initrd=$ip/boot/initrd.img$ver $append
64
65 };
66 }
67
68 config_for_ip( $ip, qq{
69
70 default boot$default
71 prompt 5
72
73 $config
74
75 });
76
77 }
78
79 1;

  ViewVC Help
Powered by ViewVC 1.1.26