#!/bin/sh prog=makepkgbuild die() { rc=$1; shift echo "$prog: $*" 1>&2 exit $rc } editpb() { op=$1 func=$2 case "$op" in append) regexp="^${func}[(][)]${func}()" edin="/^ *$func() *{ /^[ \t]*cd/ a" ;; *) die 1 "unknown editpb operation: $op" esac txt=$(awk -v r="$regexp" 'BEGIN { FS = "\n"; RS = "" } $1 ~ r { for (i = 2; i <= NF; i++) print $i }' PKGMETA |\ sed 's/^/ /') [ "$txt" ] || return 0 cat << END | ed -s PKGBUILD >/dev/null $edin $txt . wq END return $? } [ -r PKGMETA ] || die 1 "PKGMETA could not be read." [ "$TDIR" ] || die 1 "TDIR env. var is unset." [ -d "$TDIR" ] || die 1 "template dir ($TDIR) not found." tcmd=$(awk 'BEGIN { FS="\n"; RS="" } $1 == "template" { print $2 }' PKGMETA) [ "$tcmd" ] || die 1 "PKGMETA is missing 'template' entry." set -- $tcmd cmd="$TDIR/$1" [ -f "$cmd" -a -x "$cmd" ] \ || die 2 "template command ($1) not in template dir ($TDIR)" # Generate the PKGBUILD using basic pbfields script plus custom template. "$TDIR/pbfields" < PKGMETA > PKGBUILD || die 1 "pbfields returned error ${?}." "$TDIR"/$tcmd < PKGMETA >> PKGBUILD || die 1 "template pipeline ($tcmd) failed" # Prepand/append text to the package, check, or build functions. for func in package check build do for op in append prepend do editpb $op $func \ || die 2 "error $? when trying to $op to ${func}()" done done exit 0