summaryrefslogtreecommitdiff
path: root/bin/pkglist2preseed
blob: 8ebf711643a4d9879b729bd4d42cb4e98a9d3acb (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 = map { split } 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( ' ', sort grep { /[^-]$/ } @pkg );
  33. $pkglist .= " \\\n ";
  34. $pkglist .= join( ' ', sort grep { /-$/ } @pkg );
  35. $outdir->mkpath;
  36. $_ = $altinfile->slurp;
  37. s,__PKGDESC__,$pkgdesc,;
  38. s,__PKGLIST__,$pkglist,;
  39. s,__TWEAKDESC__,$tweakdesc,;
  40. s,__TWEAKLIST__,$tweaklist,;
  41. s,chroot\s+/target\s+,,g;
  42. s,/target/,/,g;
  43. $altoutfile->spew($_);
  44. $_ = $infile->slurp;
  45. s,__PKGDESC__,$pkgdesc,;
  46. s,__PKGLIST__,$pkglist,;
  47. s,__TWEAKDESC__,$tweakdesc,;
  48. s,__TWEAKLIST__,$tweaklist,;
  49. $outfile->spew($_);
  50. 1;