#!/usr/bin/perl use strict; use warnings; use autodie qw(:all);; use Path::Tiny; my $infile = path($ARGV[0]); my $outfile = path($ARGV[1]); my @pkgfiles = split( ' ', $ARGV[2] ); my @tweakfiles = split( ' ', $ARGV[3] ); my $outdir = $outfile->parent; my $altinfile = path( $infile->parent, 'script.sh.in' ); my $altoutfile = path( $outdir, 'script.sh' ); my ($pkgdesc, @pkg); foreach (@pkgfiles) { foreach (path($_)->lines) { chomp; /^[#]{2} (.*)/ and $pkgdesc .= "# $1\n"; /^[#]{1} (.*)/ and $pkgdesc .= "# * $1\n"; /^[^#]+/ and push @pkg, $_; }; }; chomp $pkgdesc; my ($tweakdesc, $tweaklist); foreach (@tweakfiles) { foreach (path($_)->lines) { chomp; /^[#]{2} (.*)/ and $tweakdesc .= "# $1\n"; /^[#]{1} (.*)/ and $tweakdesc .= "# * $1\n"; /^(?!#)\s*(.+)/ and $tweaklist .= "$1;" }; }; chomp $tweakdesc; my $pkglist = join( ' ', @pkg ); $outdir->mkpath; $_ = $altinfile->slurp; s,__PKGDESC__,$pkgdesc,; s,__PKGLIST__,$pkglist,; s,__TWEAKDESC__,$tweakdesc,; s,__TWEAKLIST__,$tweaklist,; s,chroot\s+/target\s+,,g; s,/target/,/,g; $altoutfile->spew($_); $_ = $infile->slurp; s,__PKGDESC__,$pkgdesc,; s,__PKGLIST__,$pkglist,; s,__TWEAKDESC__,$tweakdesc,; s,__TWEAKLIST__,$tweaklist,; $outfile->spew($_); 1;