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

Diff of /lib/PXElator/pxelinux.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 129 by dpavlin, Mon Aug 3 20:53:46 2009 UTC revision 469 by dpavlin, Mon Jan 4 22:48:03 2010 UTC
# Line 1  Line 1 
1  package pxelinux;  package pxelinux;
2    
3    use warnings;
4    use strict;
5    use autodie;
6    
7  our $magic = 0xF100747E;  our $magic = 0xF100747E;
8    
9  our $config_file; #= 'pxelinux.cfg/default';  our $config_file; #= 'pxelinux.cfg/default';
10  our $path_prefix;  our $path_prefix;
11  our $reboot_time; # 300 s  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 ||= 'boot' . $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 $default
71    prompt 1
72    timeout 30
73    
74    $config
75    
76            });
77    
78    }
79    
80  1;  1;

Legend:
Removed from v.129  
changed lines
  Added in v.469

  ViewVC Help
Powered by ViewVC 1.1.26