From c1dc844a8f09b52bb4c22960115a1640f255a213 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 30 Jul 2014 23:46:14 +0200 Subject: Major rewrite: Use reclass. --- bin/pkglist2preseed | 83 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 28 deletions(-) (limited to 'bin') diff --git a/bin/pkglist2preseed b/bin/pkglist2preseed index 8ebf711..1082111 100755 --- a/bin/pkglist2preseed +++ b/bin/pkglist2preseed @@ -4,41 +4,66 @@ use strict; use warnings; use autodie qw(:all);; +use Capture::Tiny qw(capture_stdout); use Path::Tiny; +use YAML::XS; +use Try::Tiny; -my $infile = path($ARGV[0]); -my $outfile = path($ARGV[1]); -my @pkgfiles = split( ' ', $ARGV[2] ); -my @tweakfiles = split( ' ', $ARGV[3] ); +my $node = $ARGV[0]; +my $outdir = path($ARGV[1]); -my $outdir = $outfile->parent; -my $altinfile = path( $infile->parent, 'script.sh.in' ); +my $basedir = path('.'); + +my $skeldir = path( $basedir, 'skel' ); +my $infile = path( $skeldir, 'preseed.cfg.in' ); +my $altinfile = path( $skeldir, 'script.sh.in' ); + +my $data = Load( scalar( capture_stdout { + system(qw( reclass -b profiles/wheezy --inventory )); +})); + +my $outfile = path( $outdir, 'preseed.cfg' ); my $altoutfile = path( $outdir, 'script.sh' ); -my (@pkglines, $pkgdesc, @pkg); -foreach (@pkgfiles) { - push @pkglines, path($_)->lines; -}; -grep { chomp } @pkglines; -grep { s/^[#]{1} (.*)/# * $1/ } @pkglines; -grep { s/^[#]{2} (.*)/# $1/ } @pkglines; -$pkgdesc = join "\n", grep { /^[#] / } @pkglines; -@pkg = map { split } grep { /^[^#]/ } @pkglines; - -my (@tweaklines, $tweakdesc, $tweaklist); -foreach (@tweakfiles) { - push @tweaklines, path($_)->lines; +my %desc; +my %params = %{ $data->{'nodes'}{$node}{'parameters'} }; + +#FIXME: sort by explicit list +foreach my $key ( sort keys $params{doc} ) { + my $headline = $params{doc}{$key}{headline}[0] || $key; + if ( $params{pkg} and $params{doc}{$key}{pkg} ) { + push @{ $desc{pkg} }, "# $headline"; + foreach ( @{ $params{doc}{$key}{pkg} } ) { + push @{ $desc{pkg} }, "# * $_"; + }; + }; + if ( $params{tweak} and $params{doc}{$key}{tweak} ) { + push @{ $desc{tweak} }, "# $headline"; + foreach ( @{ $params{doc}{$key}{tweak} } ) { + push @{ $desc{tweak} }, "# * $_"; + }; + }; }; -grep { chomp } @tweaklines; -grep { s/^[#]{1} (.*)/# * $1/ } @tweaklines; -grep { s/^[#]{2} (.*)/# $1/ } @tweaklines; -grep { /^[^#]/ and s/(?mkpath; $_ = $altinfile->slurp; @@ -46,6 +71,7 @@ s,__PKGDESC__,$pkgdesc,; s,__PKGLIST__,$pkglist,; s,__TWEAKDESC__,$tweakdesc,; s,__TWEAKLIST__,$tweaklist,; +s,__PKGAUTOLIST__,$pkgautolist,; s,chroot\s+/target\s+,,g; s,/target/,/,g; $altoutfile->spew($_); @@ -54,6 +80,7 @@ s,__PKGDESC__,$pkgdesc,; s,__PKGLIST__,$pkglist,; s,__TWEAKDESC__,$tweakdesc,; s,__TWEAKLIST__,$tweaklist,; +s,__PKGAUTOLIST__,$pkgautolist,; $outfile->spew($_); 1; -- cgit v1.2.3