From 4fb276fb2876a0e8bbf8c2721738954d9b5d9eaa Mon Sep 17 00:00:00 2001 From: linggao Date: Wed, 7 Apr 2010 15:14:29 +0000 Subject: [PATCH] added #INCLUDE support for exlist files for packimage git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5703 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/packimage.pm | 46 ++++++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index fa5793b58..726a124ff 100644 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -10,6 +10,8 @@ use File::Path; use File::Copy; use Cwd; use File::Temp; +use File::Basename; +use File::Path; use xCAT::Utils qw(genpassword); use xCAT::SvrUtils; Getopt::Long::Configure("bundling"); @@ -149,10 +151,28 @@ sub process_request { my $includestr; if ($exlistloc) { my $exlist; + my $excludetext; open($exlist,"<",$exlistloc); system("echo -n > /tmp/xcat_packimg.txt"); while (<$exlist>) { - chomp $_; + $excludetext .= $_; + } + close($exlist); + + #handle the #INLCUDE# tag recursively + my $idir = dirname($exlistloc); + my $doneincludes=0; + while (not $doneincludes) { + $doneincludes=1; + if ($excludetext =~ /#INCLUDE:[^#]+#/) { + $doneincludes=0; + $excludetext =~ s/#INCLUDE:([^#]+)#/include_file($1,$idir)/eg; + } + } + + my @tmp=split("\n", $excludetext); + foreach (@tmp) { + chomp $_; s/\s*#.*//; #-- remove comments next if /^\s*$/; #-- skip empty lines if (/^\+/) { @@ -163,7 +183,6 @@ sub process_request { $excludestr .= "'!' -path '".$_."' -a "; } } - close($exlist); } $excludestr =~ s/-a $//; if ($includestr) { @@ -367,3 +386,26 @@ sub copybootscript { return 0; } +sub include_file +{ + my $file = shift; + my $idir = shift; + my @text = (); + unless ($file =~ /^\//) { + $file = $idir."/".$file; + } + + open(INCLUDE,$file) || \ + return "#INCLUDEBAD:cannot open $file#"; + + while() { + chomp($_); + s/\s+$//; #remove trailing spaces + next if /^\s*$/; #-- skip empty lines + push(@text, $_); + } + + close(INCLUDE); + + return join("\n", @text); +}