summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2014-07-28 02:34:45 +0200
committerJonas Smedegaard <dr@jones.dk>2014-07-30 09:17:17 +0200
commit0e7d57692e4a33e8f64bbef1cc9e151c351aa837 (patch)
tree6c71a76367da8fc41190d616bb3ae234a77b7d7d
parentc4f0185ba2096538c4e08a7cb319691defb72d06 (diff)
Rewrite pkglist2preseed in perl.
-rwxr-xr-xbin/pkglist2preseed96
1 files changed, 56 insertions, 40 deletions
diff --git a/bin/pkglist2preseed b/bin/pkglist2preseed
index 696398c..c93debe 100755
--- a/bin/pkglist2preseed
+++ b/bin/pkglist2preseed
@@ -1,40 +1,56 @@
-#!/bin/sh
-
-set -eu
-
-infile="$1"
-outfile="$2"
-pkgfiles="$3"
-tweakfiles="$4"
-
-outdir=$(dirname $outfile)
-altinfile=$(dirname $infile)/script.sh.in
-altoutfile=$outdir/script.sh
-
-pkgdesc=$(perl -nE '/^[#]{2} (.*)/ and say "# $1"; /^[#]{1} (.*)/ and say "# * $1"' $pkgfiles) #'
-pkglist=$(perl -ne 'chomp; /^[^#]+/ and print "$_ "' $pkgfiles)
-
-tweakdesc=$(perl -nE '/^[#]{2} (.*)/ and say "# $1"; /^[#]{1} (.*)/ and say "# * $1"' $tweakfiles) #'
-tweaklist=$(perl -ne 'chomp; /^(?!#)\s*(.+)/ and print "$1;"' $tweakfiles)
-
-export pkgdesc pkglist tweakdesc tweaklist
-
-mkdir -p $outdir
-perl -p \
- -e 's,__PKGDESC__,$ENV{"pkgdesc"},;'\
- -e 's,__PKGLIST__,$ENV{"pkglist"},;'\
- -e 's,__TWEAKDESC__,$ENV{"tweakdesc"},;'\
- -e 's,__TWEAKLIST__,$ENV{"tweaklist"},;'\
- -e 's,chroot\s+/target\s+,,g;'\
- -e 's,/target/,/,g;'\
- < $altinfile \
- > $altoutfile~
-mv -f $altoutfile~ $altoutfile
-perl -p \
- -e 's,__PKGDESC__,$ENV{"pkgdesc"},;'\
- -e 's,__PKGLIST__,$ENV{"pkglist"},;'\
- -e 's,__TWEAKDESC__,$ENV{"tweakdesc"},;'\
- -e 's,__TWEAKLIST__,$ENV{"tweaklist"},;'\
- < $infile \
- > $outfile~
-mv -f $outfile~ $outfile
+#!/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, $pkglist);
+foreach (@pkgfiles) {
+ foreach (path($_)->lines) {
+ chomp;
+ /^[#]{2} (.*)/ and $pkgdesc .= "# $1\n";
+ /^[#]{1} (.*)/ and $pkgdesc .= "# * $1\n";
+ /^[^#]+/ and $pkglist .= "$_ ";
+ };
+};
+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;
+
+$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;