#!/bin/sh prog=makepkgbuild appendpb() { txt=$(awk -v f=$1 'BEGIN { FS = "\n"; RS = "" } $1 ~ "^" f "[(][)]/dev/null 2>&1 return $? ;; esac } prependpb() { txt=$(awk -v f=$1 'BEGIN { FS = "\n"; RS = "" } $1 == ">" f "()" { for (i = 2; i <= NF; i++) print $i }' \ PKGMETA | sed 's/^/ /') case "$txt" in '') return 0 ;; *) echo "/^ *${func}()[ \\n]*{ /^[ \t]*cd/ a $txt . wq " | ed PKGBUILD >/dev/null 2>&1 return $? ;; esac } if ! [ -r PKGMETA ] then echo "$prog: PKGMETA could not be read." 1>&2 exit 1 fi case "$TDIR" in '') echo "$prog: TDIR env variable is not set." 1>&2 exit 1 esac tcmd=$(awk ' BEGIN { FS = "\n"; RS = "" } $1 == "template" { for (i = 2; i <= NF; i++) print $i }' PKGMETA \ | while read line do set -- $line cmd="$TDIR/$1" if ! [ -x $cmd ] then echo "$prog: Unknown template command: $cmd" 1>&2 exit 2 fi echo "$TDIR/$*" done \ | tr '\n' '|' | sed 's/[|]$//') "$TDIR/pbfields" PKGBUILD $tcmd >PKGBUILD for func in package check build do if ! appendpb $func then echo "$prog: error when trying to append to ${func}()" 1>&2 exit 2 fi if ! prependpb $func then echo "$prog: error when trying to prepend to ${func}()" 1>&2 exit 2 fi done