Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / check / check-perms.mk
blob8efe93032b8cc8a9ae7a23e793d248cffb104e91
1 # $NetBSD: check-perms.mk,v 1.12 2008/06/22 22:05:19 joerg Exp $
3 # This file checks that after installation of a package, all files and
4 # directories of that package have sensible permissions set.
6 # To use this check in bulk builds, add
7 # BULK_PREREQ+= sysutils/checkperms
8 # to your mk.conf file.
10 # User-settable variables:
12 # CHECK_PERMS
13 # Specifies whether the permissions check should be run at all.
15 # Possible values: yes, no.
17 # Default value: yes for PKG_DEVELOPER, no otherwise.
19 # Package-settable variables:
21 # CHECK_PERMS_SKIP
22 # A list of shell patterns (like man/*) that should be excluded
23 # from the check. Note that a * in a pattern also matches a slash
24 # in a pathname.
26 # Default value: empty.
28 # CHECK_PERMS_AUTOFIX
29 # If set to yes, any unusual permissions are fixed automatically.
31 # Possible values: yes, no.
34 _VARGROUPS+= check-perms
35 _USER_VARS.check-perms= CHECK_PERMS
36 _PKG_VARS.check-perms= CHECK_PERMS_SKIP CHECK_PERMS_AUTOSKIP
38 .if defined(PKG_DEVELOPER) && ${PKG_DEVELOPER} != "no"
39 CHECK_PERMS?= yes
40 .else
41 CHECK_PERMS?= no
42 .endif
44 CHECK_PERMS_SKIP?= # none
45 CHECK_PERMS_AUTOFIX?= no
47 # The checkperms command does not yet support Interix with the -c flag.
48 # See PR 34968.
49 .if !empty(MACHINE_PLATFORM:MInterix-*-*)
50 _CHECK_PERMS_FLAGS=
51 .elif !empty(CHECK_PERMS_AUTOFIX:M[Yy][Ee][Ss])
52 _CHECK_PERMS_FLAGS= -cff
53 .else
54 _CHECK_PERMS_FLAGS= -c
55 .endif
57 .if !empty(CHECK_PERMS:M[Yy][Ee][Ss])
58 BUILD_DEPENDS+= checkperms>=1.1:../../sysutils/checkperms
60 privileged-install-hook: _check-perms
61 .endif
63 _CHECK_PERMS_CMD= ${LOCALBASE}/bin/checkperms
64 _CHECK_PERMS_GETDIRS_AWK= \
65 /.*/ { \
66 print $$0; \
67 dir = $$0; \
68 while (sub("/[^/]*$$", "", dir) && dir != "") { \
69 if (!(dir in dirs)) { \
70 dirs[dir] = "done"; \
71 print dir; \
72 } \
73 } \
76 _check-perms: .PHONY
77 @${STEP_MSG} "Checking file permissions in ${PKGNAME}"
78 ${RUN} ${PKG_INFO} -qe "checkperms>=1.1" \
79 || { \
80 ${WARNING_MSG} "[check-perms.mk] Skipping file permissions check."; \
81 ${WARNING_MSG} "[check-perms.mk] Install sysutils/checkperms to enable this check."; \
82 exit 0; \
83 }; \
84 ${PKG_FILELIST_CMD} \
85 | sort \
86 | sed -e 's,\\,\\\\,g' \
87 | while read file; do \
88 case "$$file" in \
89 ${CHECK_PERMS_SKIP:@p@${PREFIX}/${p}|${p}) continue ;;@}\
90 *) ;; \
91 esac; \
92 printf "%s\\n" "${DESTDIR}$$file"; \
93 done \
94 | awk ${_CHECK_PERMS_GETDIRS_AWK:Q} \
95 | ${_CHECK_PERMS_CMD} ${_CHECK_PERMS_FLAGS}