$c{$_}='' foreach qw(
DebianPreseed
+ TftpPxeTemplatesReal
);
#---------- general setup and config reading ----------
logm("TftpScope is $tftpscope");
$ho->{Tftp} = { };
$ho->{Tftp}{$_} = $c{"Tftp${_}_${tftpscope}"} || $c{"Tftp${_}"}
- foreach qw(Path TmpDir PxeDir PxeGroup PxeTemplates DiBase);
+ foreach qw(Path TmpDir PxeDir PxeGroup PxeTemplates PxeTemplatesReal
+ DiBase);
#----- finalise -----
logm("wrote $fn". (defined $stash ? " (stashed as $stash)" : ""));
}
-sub host_pxefile ($) {
- my ($ho) = @_;
+sub host_pxefile ($;$) {
+ my ($ho, $templatekey) = @_;
my %v = %r;
+ $templatekey //= 'PxeTemplates';
+ my $templates = $ho->{Tftp}{$templatekey} || $ho->{Tftp}{PxeTemplates};
if (defined $ho->{Ether}) {
my $eth = $v{'ether'} = $ho->{Ether};
$eth =~ y/A-Z/a-z/;
$v{'ipaddr'} = $ip;
$v{'ipaddrhex'} = sprintf "%02X%02X%02X%02X", split /\./, $ip;
}
- foreach my $pat (split /\s+/, $ho->{Tftp}{PxeTemplates}) {
+ foreach my $pat (split /\s+/, $templates) {
# we skip patterns that contain any references to undefined %var%s
$pat =~ s{\%(\w*)\%}{
$1 eq '' ? '%' :
# and return the first pattern we managed to completely substitute
return $pat;
}
- die "no pxe template matched $ho->{Tftp}{PxeTemplates} ".
+ die "no pxe template ($templatekey) matched $templates ".
(join ",", sort keys %v)." ?";
}
(e.g. pxelinux.cfg)
PxeGroup The Unix group which should own files under `PxeDir'.
PxeTemplates See TftpPxeTemplates
+ PxeTemplatesReal
DiBase The path under `Path' to the root of the debian installer
images.
ip address - are skipped. The first template all of whose ingredients
are known is used, with TftpPath and TftpPxeDir prepended.
+TftpPxeTemplatesReal
+ Template filename which mg-hosts mkpxedir should make be a symlink to
+ the TftpPxeTemplates. Not used otherwise.
+
========================================
Host-specific config settigs
use DBI;
use Osstest;
use Osstest::TestSupport;
+use File::Basename;
csreadconfig();
my $sudo = $ENV{'OSSTEST_SUDO'} // 'sudo';
foreach my $hn (@ARGV) {
my $ho= selecthost("host=$hn");
- my $macdir= $ho->{Ether};
- $macdir =~ s/\:/-/g;
- system_checked(<<END);
+ my $pxefile = host_pxefile($ho);
+ my $pxerealfile = host_pxefile($ho, 'PxeTemplatesReal');
+ my $dirname = dirname $pxefile;
+ my $cmd = <<END;
set -e
cd $ho->{Tftp}{Path}$ho->{Tftp}{PxeDir}
- $sudo chown root.$ho->{Tftp}{PxeGroup} $macdir
- $sudo chmod 2775 $macdir
- $sudo rm -f $hn
- $sudo ln -s $macdir $hn
- ls -ald $hn $macdir
END
+ $cmd .= <<END if $dirname ne '.';
+ $sudo mkdir -p $dirname
+END
+ $cmd .= <<END;
+ $sudo chown root.$ho->{Tftp}{PxeGroup} $dirname
+ $sudo chmod 2775 $dirname
+END
+ if ($pxefile ne $pxerealfile) {
+ my $subdirs = "../" x $pxefile =~ m#/#;
+ $cmd .= <<END;
+ $sudo ln -sf $subdirs$pxefile $pxerealfile
+END
+ }
+ print $cmd;
+ system_checked($cmd) unless $dryrun;
}
}