summaryrefslogtreecommitdiff
path: root/mk/install/info-files
blob: 036438af4ab9190f729a3fb05e8f34edc043c1a8 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# $NetBSD: info-files,v 1.3 2006/03/19 23:58:14 jlam Exp $
#
# Generate an +INFO_FILES script that handles info file registration for
# the package.
#
case "${STAGE},$1" in
UNPACK,|UNPACK,+INFO_FILES)
	${CAT} > ./+INFO_FILES << 'EOF'
#!@SH@
#
# +INFO_FILES - info file registration management script
#
# Usage: ./+INFO_FILES ADD|REMOVE [metadatadir]
#
# This script supports two actions, ADD and REMOVE, that will add or
# remove entries for info files from the package associated with
# <metadatadir> from the info index files (the "dir" file in the
# same directory as the info files).
#
# Lines starting with "# INFO: " are data read by this script that
# name the info files that will be added or removed from the "dir"
# index files.
#
#	# INFO: /usr/pkg/info/bar.info
#	# INFO: /usr/pkg/info/baz.info
#
# For each INFO entry, if the path is relative, that it is taken to be
# relative to ${PKG_PREFIX}.
#

ECHO="@ECHO@"
GREP="@GREP@"
INSTALL_INFO="@INSTALL_INFO@"
PWD_CMD="@PWD_CMD@"
RM="@RM@"
SED="@SED@"
SORT="@SORT@"
TEST="@TEST@"

SELF=$0
ACTION=$1

PKG_METADATA_DIR="${2-`${PWD_CMD}`}"
: ${PKGNAME=${PKG_METADATA_DIR##*/}}
: ${PKG_PREFIX=@PREFIX@}

exitcode=0
case $ACTION in
ADD)
	${SED} -n "/^\# INFO: /{s/^\# INFO: //;p;}" ${SELF} | ${SORT} -u |
	{ while read file; do
		case $file in
		"")	continue ;;
		[!/]*)	file="${PKG_PREFIX}/$file" ;;
		esac

		case "$printed_header" in
		yes)	;;
		*)	printed_header=yes
			${ECHO} "==========================================================================="
			${ECHO} "Registering info files for ${PKGNAME}:"
			${ECHO} ""
			;;
		esac

		infodir="${file%/*}"
		infoindex="$infodir/dir"
		nentries="`${GREP} -c '^\*' $infoindex 2>/dev/null`"
		case "$nentries" in
		[0-9]*)	${TEST} $nentries -gt 0 || ${RM} $infoindex ;;
		esac
		${ECHO} "	$file"
		${INSTALL_INFO} --info-dir="$infodir" --delete $file >/dev/null 2>&1
		${INSTALL_INFO} --info-dir="$infodir" $file >/dev/null 2>&1
	done
	case "$printed_header" in
	yes)	${ECHO} ""
		${ECHO} "==========================================================================="
		;;
	esac; }
	;;

REMOVE)
	${SED} -n "/^\# INFO: /{s/^\# INFO: //;p;}" ${SELF} | ${SORT} -u |
	{ while read file; do
		case $file in
		"")	continue ;;
		[!/]*)	file="${PKG_PREFIX}/$file" ;;
		esac

		case "$printed_header" in
		yes)	;;
		*)	printed_header=yes
			${ECHO} "==========================================================================="
			${ECHO} "Unregistering info files for ${PKGNAME}:"
			${ECHO} ""
			;;
		esac

		infodir="${file%/*}"
		infoindex="$infodir/dir"
		${ECHO} "	$file"
		${INSTALL_INFO} --info-dir="$infodir" --delete $file >/dev/null 2>&1
		nentries="`${GREP} -c '^\*' $infoindex 2>/dev/null`"
		case "$nentries" in
		[0-9]*)	${TEST} $nentries -gt 1 || ${RM} $infoindex ;;
		esac
	done
	case "$printed_header" in
	yes)	${ECHO} ""
		${ECHO} "==========================================================================="
		;;
	esac; }
	;;
esac
exit $exitcode

EOF
	${SED} -n "/^\# INFO: /p" ${SELF} >> ./+INFO_FILES
	${CHMOD} +x ./+INFO_FILES
	;;
esac