#!/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 (@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 = grep { /^[^#]/ } @pkglines; my (@tweaklines, $tweakdesc, $tweaklist); foreach (@tweakfiles) { push @tweaklines, path($_)->lines; }; grep { chomp } @tweaklines; grep { s/^[#]{1} (.*)/# * $1/ } @tweaklines; grep { s/^[#]{2} (.*)/# $1/ } @tweaklines; grep { /^[^#]/ and s/(?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;