summaryrefslogtreecommitdiff
path: root/bin/pkglist2preseed
blob: 0ff94c5440510330e2aeb3e936ae6c87af9fd136 (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 (@pkglines, $pkgdesc, @pkg);
  14. foreach (@pkgfiles) {
  15. push @pkglines, path($_)->lines;
  16. };
  17. grep { chomp } @pkglines;
  18. grep { s/^[#]{1} (.*)/# * $1/ } @pkglines;
  19. grep { s/^[#]{2} (.*)/# $1/ } @pkglines;
  20. $pkgdesc = join "\n", grep { /^[#] / } @pkglines;
  21. @pkg = grep { /^[^#]/ } @pkglines;
  22. my (@tweaklines, $tweakdesc, $tweaklist);
  23. foreach (@tweakfiles) {
  24. push @tweaklines, path($_)->lines;
  25. };
  26. grep { chomp } @tweaklines;
  27. grep { s/^[#]{1} (.*)/# * $1/ } @tweaklines;
  28. grep { s/^[#]{2} (.*)/# $1/ } @tweaklines;
  29. grep { /^[^#]/ and s/(?<!;)$/ / } @tweaklines;
  30. $tweakdesc = join "\n", grep { /^[#] / } @tweaklines;
  31. $tweaklist = join "\\\n", grep { /^[^#]/ } @tweaklines;
  32. my $pkglist = join( ' ', @pkg );
  33. $outdir->mkpath;
  34. $_ = $altinfile->slurp;
  35. s,__PKGDESC__,$pkgdesc,;
  36. s,__PKGLIST__,$pkglist,;
  37. s,__TWEAKDESC__,$tweakdesc,;
  38. s,__TWEAKLIST__,$tweaklist,;
  39. s,chroot\s+/target\s+,,g;
  40. s,/target/,/,g;
  41. $altoutfile->spew($_);
  42. $_ = $infile->slurp;
  43. s,__PKGDESC__,$pkgdesc,;
  44. s,__PKGLIST__,$pkglist,;
  45. s,__TWEAKDESC__,$tweakdesc,;
  46. s,__TWEAKLIST__,$tweaklist,;
  47. $outfile->spew($_);
  48. 1;