blob: 490a27a934a10131acf62e43a670c98728ec4e01 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/bin/sh
prog=mkpkgbuild
die()
{
rc=$1; shift
echo "$prog: $*" 1>&2
exit $rc
}
editpb()
{
op=$1 func=$2
case "$op" in
append)
regexp="^${func}[(][)]<?$"
edin="/^ *$func() *{
/^}
i" ;;
prepend)
regexp=">${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 }' PKGDATA |\
sed 's/^/ /')
[ "$txt" ] || return 0
cat << END | ed -s PKGBUILD >/dev/null
$edin
$txt
.
wq
END
return $?
}
[ -r PKGDATA ] || die 1 "PKGDATA 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 }' PKGDATA)
[ "$tcmd" ] || die 1 "PKGDATA 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" < PKGDATA > PKGBUILD || die 1 "pbfields returned error ${?}."
"$TDIR"/$tcmd < PKGDATA >> 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
|