summaryrefslogtreecommitdiff
path: root/mk/pkgformat/pkg/register-dependencies
blob: 148ef8ac3407a00eed4c67f7437c1b996a373203 (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
#!/bin/sh
#
# $NetBSD: register-dependencies,v 1.1 2011/10/15 00:23:09 reed Exp $
#
######################################################################
#
# NAME
#	register-dependencies -- register package dependencies
#
# SYNOPSIS
#	register-dependencies pkgname
#
# DESCRIPTION
#	register-dependencies registers a dependency relationship from
#	the named package pkgname and the packages passed in via
#	standard input.
#
# ENVIRONMENT
#	PKG_DBDIR
#		This is the package meta-data directory in which the
#		packages are registered.  By default, this is /var/db/pkg.
#
######################################################################

: ${AWK:=awk}
: ${CP:=cp}
: ${ECHO:=echo}
: ${PKG_DBDIR:=/var/db/pkg}
: ${RM:=rm}
: ${TEST:=test}
: ${TOUCH:=touch}
: ${TRUE:=true}

PKGNAME="$1"

while read pkg; do
	pkgdir="${PKG_DBDIR}/$pkg"
	if ${TEST} ! -d "$pkgdir"; then
		${ECHO} 1>&2 "$pkg not found - dependency NOT registered"
		continue
	fi
	req="$pkgdir/+REQUIRED_BY"
	tmpreq="$pkgdir/+REQUIRED_BY.$$"
	${TOUCH} $req
	${AWK} -v PKGNAME="${PKGNAME}" \
		'BEGIN { found = 0 }
		$0 == PKGNAME { found = 1 } { print }
		END { if (!found) print PKGNAME }' $req > $tmpreq
	${CP} -f $tmpreq $req; ${RM} -f $tmpreq
	${ECHO} "${PKGNAME} requires installed package $pkg"
done