summaryrefslogtreecommitdiffstats
path: root/bin/mkpkgmeta
blob: 2296a28e765e2bdc2a765c19b91d76869e72eaf9 (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
#!/bin/sh

prog=mkpkgmeta

err()
{
	echo "$prog: $*" 1>&2
	exit 1
}

basicmeta()
{
	printf "pkgname\n%s\n\n" "$pkgname"
	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

	return 0
}

prependmeta()
{
	if basicmeta | cat - "$1" > "$1.new"
	then
		mv "$1.new" "$1"
		return 0
	else
		rm "$1.new"
		return 1
	fi
}

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

case "$METABIN" in
'')	err "set METABIN before calling $prog"
esac

tmp="/tmp/$prog.$$"
for flav in "$METABIN"/*
do
	pkgname="$1"
	[ -f "$flav" -a -x "$flav" ] || continue
	PATH="$PATH:$flav.d" "$flav" "$pkgname"
	metaret=$?
	
	case "$metaret" in
	0)	if prependmeta PKGDATA
		then
			exit 0
		else
			err "failed to prepend to PKGDATA"
		fi ;;
	1)	err "$flav encountered an error" ;;
	2)	;; # loop
	*)	err "$flav returned error code $metaret" ;;
	esac
done

err "no matching meta generator found for '$1'"