summaryrefslogtreecommitdiffstats
path: root/bin/mkpkgdata
blob: f33089473d9f23d163f9352ce91c9b9e7742e97b (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
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh

prog=mkpkgdata

lazysource()
{
	awk -v prog="$prog" '
BEGIN { FS = "\n"; RS = ""; OFS = ORS = "\n\n" }
$1 == "pkgver" { ver = $2 }
$1 == "source" {
	len = NF - 1
	for(i = 2; i <= NF; i++) sources[i - 1] = $i
	next
}
1 # print everything but sources

END {
	# remember that metas emit no output when they cant match
	# a package.
	if(NR == 0 || !ver) exit 2

	ORS="\n"
	
	# Replace any version strings in the source file with ${pkgver}.
	gsub(/[.]/, "\\\\&", ver)

	print "source"
	for(i = 1; i <= len; i++){
		gsub(ver, "${pkgver}", sources[i])
		print sources[i]
	}
	print ""
}'
	return $?
} # end of lazysource()

basicmeta()
{
	printf "pkgname\n%s\n\n" "$1"
	printf "pkgrel\n%d\n\n" "${PKGREL:-1}"
	printf "packager\n%s\n\n" "${PACKAGER:-Anonymous}"
	
	if [ "$MAINTAINER" ]
	then
		printf "maintainer\n%s\n\n" "$MAINTAINER"
	fi
}

case $# in
0)	echo "usage: $prog [package name]" 1>&2
	exit 1
esac

case "$METABIN" in
'')	echo "$prog: set METABIN before calling $prog" 1>&2
	exit 1
esac

tmp="/tmp/$prog.$$"
for flav in "$METABIN"/*
do
	[ -f "$flav" -a -x "$flav" ] || continue
	trap 'rm "$tmp"' 1 2 15
	PATH="$PATH:$flav.d" "$flav" "$1" > "$tmp"
	metaret=$?
	case "$metaret" in
	0)	basicmeta "$1"
		lazysource < "$tmp"
	esac
	
	rm "$tmp"
	trap '' 1 2 5
	case "$metaret" in
	0)	exit 0 ;;
	1)	echo "$prog: $flav encountered an error" 1>&2
		exit 1 ;;
	2)	;; # loop
	*)	echo "$prog: $flav returned error code $metaret" 1>&2
		exit 1 ;;
	esac
done

echo "$prog: no matching meta generator found for '$1'" 1>&2
exit 1