summaryrefslogtreecommitdiff
path: root/mk/install/perms
blob: 303d304f349d2b7e86a2c81c6aaf0045d11a3b3b (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
# $NetBSD: perms,v 1.5 2006/03/19 23:58:14 jlam Exp $
#
# Generate a +PERMS script that sets the special permissions on files
# and directories used by the package.
#
case "${STAGE},$1" in
UNPACK,|UNPACK,+PERMS)
	${CAT} > ./+PERMS << 'EOF'
#!@SH@
#
# +PERMS - special file and directory permissions management script
#
# Usage: ./+PERMS [metadatadir]
#
# This script sets special permissions on files and directories needed
# by the package associated with <metadatadir>.
#
# Lines starting with "# PERMS: " are data read by this script that
# name the files and directories required to have special permissions
# in order for this package to function correctly.
#
#	# PERMS: /usr/pkg/bin/lppasswd 4711 lp sys
#	# PERMS: /usr/pkg/etc/pwd.db 0600
#
# For each PERMS entry, if the file path is relative, then it is taken to
# be relative to ${PKG_PREFIX}.
#
CHGRP="@CHGRP@"
CHMOD="@CHMOD@"
CHOWN="@CHOWN@"
ECHO="@ECHO@"
PWD_CMD="@PWD_CMD@"
SED="@SED@"
SORT="@SORT@"
TEST="@TEST@"

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

${SED} -n "/^\# PERMS: /{s/^\# PERMS: //;p;}" ${SELF} | ${SORT} -u |
{ while read file f_mode f_user f_group; do
	case $file in
	"")	continue ;;
	[!/]*)	file="${PKG_PREFIX}/$file" ;;
	esac
	${TEST} -f "$file" || continue
	case "$printed_header" in
	yes)	;;
	*)	printed_header=yes
		${ECHO} "==========================================================================="
		${ECHO} "The following files and directories needed by ${PKGNAME}"
		${ECHO} "have special permissions:"
		${ECHO} ""
		;;
	esac
	case $f_mode/$f_user/$f_group in
	//)
		${ECHO} "	$file"
		;;
	[!/]*//)
		${ECHO} "	$file (m=$f_mode)"
		;;
	[!/]*/[!/]*/)
		${ECHO} "	$file (o=$f_user, m=$f_mode)"
		;;
	[!/]*/[!/]*/[!/]*)
		${ECHO} "	$file (o=$f_user, g=$f_group, m=$f_mode)"
		;;
	esac
	case $f_user in
	"")	;;
	*)	${CHOWN} $f_user $file ;;
	esac
	case $f_group in
	"")	;;
	*)	${CHGRP} $f_group $file ;;
	esac
	case $f_mode in
	"")	;;
	*)	${CHMOD} $f_mode $file ;;
	esac
done
case "$printed_header" in
yes)	${ECHO} ""
	${ECHO} "==========================================================================="
	;;
esac; }

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