summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/pkglist2preseed83
1 files changed, 55 insertions, 28 deletions
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/(?<!;)$/ / } @tweaklines;
-$tweakdesc = join "\n", grep { /^[#] / } @tweaklines;
-$tweaklist = join "\\\n", grep { /^[^#]/ } @tweaklines;
-
-my $pkglist = join( ' ', sort grep { /[^-]$/ } @pkg );
+my $pkgdesc = defined( $desc{pkg} )
+ ? join( "\n", @{ $desc{pkg} } )
+ : '';
+my $tweakdesc = defined( $desc{tweak} )
+ ? join( "\n", @{ $desc{tweak} } )
+ : '';
+my @pkg = try { @{ $params{pkg} } }
+ catch { die "No packages resolved" };
+my @pkgauto = try { @{ $params{'pkg-auto'} } }
+ catch { die "No package auto-markings resolved" };
+my @pkgavoid = try { @{ $params{'pkg-avoid'} } }
+ catch { die "No package avoidance resolved" };
+my @tweak = try { @{ $params{tweak} } }
+ catch { die "No tweaks resolved" };
+my $pkglist = join( ' ', sort @pkg );
$pkglist .= " \\\n ";
-$pkglist .= join( ' ', sort grep { /-$/ } @pkg );
+$pkglist .= join( ' ', sort map { $_.'-' } @pkgavoid );
+my $pkgautolist = join( ' ', sort @pkgauto );
+grep {chomp} @tweak;
+my $tweaklist = join( ";\\\n ", 'set -e', @tweak );
$outdir->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;