- #!/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"},;'\
- < $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
|