summaryrefslogtreecommitdiff
path: root/bin/pkglist2preseed
blob: 01627268ef01c6b9b3907c3800ef5da37b7238ed (plain)
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use autodie qw(:all);;
  5. use Path::Tiny;
  6. my $infile = path($ARGV[0]);
  7. my $outfile = path($ARGV[1]);
  8. my @pkgfiles = split( ' ', $ARGV[2] );
  9. my @tweakfiles = split( ' ', $ARGV[3] );
  10. my $outdir = $outfile->parent;
  11. my $altinfile = path( $infile->parent, 'script.sh.in' );
  12. my $altoutfile = path( $outdir, 'script.sh' );
  13. my ($pkgdesc, @pkg);
  14. foreach (@pkgfiles) {
  15. foreach (path($_)->lines) {
  16. chomp;
  17. /^[#]{2} (.*)/ and $pkgdesc .= "# $1\n";
  18. /^[#]{1} (.*)/ and $pkgdesc .= "# * $1\n";
  19. /^[^#]+/ and push @pkg, $_;
  20. };
  21. };
  22. chomp $pkgdesc;
  23. my ($tweakdesc, $tweaklist);
  24. foreach (@tweakfiles) {
  25. foreach (path($_)->lines) {
  26. chomp;
  27. /^[#]{2} (.*)/ and $tweakdesc .= "# $1\n";
  28. /^[#]{1} (.*)/ and $tweakdesc .= "# * $1\n";
  29. /^(?!#)\s*(.+)/ and $tweaklist .= "$1;"
  30. };
  31. };
  32. chomp $tweakdesc;
  33. my $pkglist = join( ' ', @pkg );
  34. $outdir->mkpath;
  35. $_ = $altinfile->slurp;
  36. s,__PKGDESC__,$pkgdesc,;
  37. s,__PKGLIST__,$pkglist,;
  38. s,__TWEAKDESC__,$tweakdesc,;
  39. s,__TWEAKLIST__,$tweaklist,;
  40. s,chroot\s+/target\s+,,g;
  41. s,/target/,/,g;
  42. $altoutfile->spew($_);
  43. $_ = $infile->slurp;
  44. s,__PKGDESC__,$pkgdesc,;
  45. s,__PKGLIST__,$pkglist,;
  46. s,__TWEAKDESC__,$tweakdesc,;
  47. s,__TWEAKLIST__,$tweaklist,;
  48. $outfile->spew($_);
  49. 1;