Fixup fromcvs/togit conversion
[pkgsrcv2.git] / mk / unprivileged.mk
1 # $NetBSD: unprivileged.mk,v 1.19 2010/02/28 19:33:00 tnn Exp $
2 #
3 # This file collects definitions that are useful when using pkgsrc as an
4 # unprivileged (non-root) user. It is included automatically by the
5 # pkgsrc infrastructure.
6 #
7 # === User-settable variables ===
8 #
9 # UNPRIVILEGED
10 #       Whether to build packages as unprivileged user.
11 #
12 #       Default: (undefined)
13 #       Possible: yes no
14 #
15 # UNPRIVILEGED_USER
16 #       The user name (or numeric uid) that will be used to install
17 #       files.
18 #
19 #       Default: The user building the package
20 #
21 # UNPRIVILEGED_GROUP
22 #       The group name (or numeric gid) that will be used to install
23 #       files.
24 #
25 #       Default: The primary group of the user building the package
26 #
27 # UNPRIVILEGED_GROUPS
28 #       The group names that can be used to install files.  Where a
29 #       per-package custom group is declared that matches a group name
30 #       in this variable, it will be left unmodified.  Any per-package
31 #       custom group not in this list will be forced to the value of
32 #       UNPRIVILEGED_GROUP.
33 #
34 #       Default: The complete group membership of the user building
35 #       the package
36 #
37 # === Package-settable variables ===
38 #
39 # PKG_USERS_VARS
40 #       A list of variables that hold bare user names, e.g APACHE_USER, etc.
41 #
42 # PKG_GROUPS_VARS
43 #       A list of variables that hold bare group names, e.g UUCP_GROUP, etc.
44 #
45 # XXX: How can the user say that some of the packages shouldn't override
46 # the user and group names?
47 #
48 # PRIVILEGED_STAGES
49 #       A list of phases (not stages) that are run as the privileged
50 #       user. Some packages, when installed with just-in-time-su, leave
51 #       temporary files in the working directory, so the "clean" phase
52 #       must have enough priviledges to clean them up.
53 #
54 #       Possible: clean
55 #       Default: (undefined)
56 #
57 # === System-defined variables ===
58 #
59 # REAL_ROOT_USER
60 #       The name of an omnipotent user account on the system.
61 #
62 #       XXX: Why do we have this variable when it is set to ${ROOT_USER}
63 #       anyway for unprivileged builds? Shouldn't packages that require
64 #       such a user just fail in unprivileged mode?
65 #       (See NOT_FOR_UNPRIVILEGED.)
66 #
67 # REAL_ROOT_GROUP
68 #       The primary group of the REAL_ROOT_USER.
69 #
70 # ROOT_USER
71 #       XXX: ???
72 #
73 # ROOT_GROUP
74 #       The primary group of the ROOT_USER.
75 #
76 # BINOWN, BINGRP, GAMEOWN, GAMEGRP, MANOWN, MANGRP, SHAREOWN, SHAREGRP,
77 # DOCOWN, DOCGRP, BINMODE, NONBINMODE
78 #       Ownership and permissions of the various types of files that are
79 #       installed by the packages.
80 #
81 #       XXX: What do we need all these different variables for? Wouldn't
82 #       it be ok to install all files as ROOT_USER:ROOT_GROUP?
83 #
84 # PKG_CREATE_USERGROUP
85 #       Since an unprivileged user normally cannot create other users
86 #       and groups, this pkgsrc feature is disabled.
87 #
88 #       XXX: This setting should be moved into pkg_add.
89 #
90 # PKG_REGISTER_SHELLS
91 #       Since an unprivileged user normally cannot add entries to
92 #       /etc/shells, this pkgsrc feature is disabled.
93 #
94 #       XXX: See PKG_CREATE_USERGROUP
95 #
96 # TOOLS_PLATFORM.chown, TOOLS_PLATFORM.chgrp
97 #       These tools cannot be used in their full extent by unprivileged
98 #       users.
99 #
100 #       XXX: chgrp may work for some groups.
101 #
102 # Keywords: unprivileged root override
103 #
104
105 _VARGROUPS+=                    unprivileged
106 _USER_VARS.unprivileged= \
107         UNPRIVILEGED UNPRIVILEGED_GROUP UNPRIVILEGED_GROUPS UNPRIVILEGED_USER
108 _PKG_VARS.unprivileged= \
109         PKG_USERS_VARS PKG_GROUPS_VARS
110 _SYS_VARS.unprivileged= \
111         REAL_ROOT_USER REAL_ROOT_GROUP ROOT_USER ROOT_GROUP \
112         BINOWN BINGRP GAMEOWN GAMEGRP MANOWN MANGRP SHAREOWN SHAREGRP DOCOWN DOCGRP \
113         BINMODE NONBINMODE \
114         PKG_CREATE_USERGROUP PKG_REGISTER_SHELLS \
115         TOOLS_PLATFORM.chgrp TOOLS_PLATFORM.chown SU_CMD
116
117 _UNPRIVILEGED=          # empty
118 .if defined(UNPRIVILEGED) && !empty(UNPRIVILEGED:M[Yy][Ee][Ss])
119 _UNPRIVILEGED+=         unprivileged
120 .endif
121 .if (${_USE_DESTDIR} == "user-destdir")
122 _UNPRIVILEGED+=         user-destdir
123 .endif
124
125 .if !empty(_UNPRIVILEGED)
126
127 # Guess which user/group has to be used.
128 .  if !defined(UNPRIVILEGED_USER) || empty(UNPRIVILEGED_USER)
129 UNPRIVILEGED_USER!=     ${ID} -n -u
130 .  endif
131 .  if !defined(UNPRIVILEGED_GROUP) || empty(UNPRIVILEGED_GROUP)
132 .    if "$(OPSYS)" == "Interix" # For at least Interix 3.5 SP-8.0.1969.1
133 UNPRIVILEGED_GROUP!=    ${ID} -g
134 .    else
135 UNPRIVILEGED_GROUP!=    ${ID} -n -g
136 .    endif 
137 .  endif
138 .  if !defined(UNPRIVILEGED_GROUPS) || empty(UNPRIVILEGED_GROUPS)
139 UNPRIVILEGED_GROUPS!=   ${ID} -n -G
140 .  endif
141
142 .  if empty(_UNPRIVILEGED:Munprivileged) && !empty(_UNPRIVILEGED:Muser-destdir)
143 # Only do following for privileged, user-destdir builds.
144 _SU_ROOT_USER:=         ${ROOT_USER}
145 REAL_ROOT_USER:=        ${ROOT_USER}
146 REAL_ROOT_GROUP:=       ${ROOT_GROUP}
147 .  endif
148
149 # Override super-user account.
150 ROOT_GROUP=             ${UNPRIVILEGED_GROUP}
151 ROOT_USER=              ${UNPRIVILEGED_USER}
152
153 .  if !empty(_UNPRIVILEGED:Munprivileged)
154 # Override "games" account.
155 GAMES_GROUP=            ${UNPRIVILEGED_GROUP}
156 GAMES_USER=             ${UNPRIVILEGED_USER}
157 GAMEDIRMODE=            0755
158 GAMEMODE=               0755
159 .  endif
160
161 # Override user/group pairs used to install files.
162 BINGRP=                 ${UNPRIVILEGED_GROUP}
163 BINOWN=                 ${UNPRIVILEGED_USER}
164 GAMEGRP=                ${UNPRIVILEGED_GROUP}
165 GAMEOWN=                ${UNPRIVILEGED_USER}
166 MANGRP=                 ${UNPRIVILEGED_GROUP}
167 MANOWN=                 ${UNPRIVILEGED_USER}
168 SHAREGRP=               ${UNPRIVILEGED_GROUP}
169 SHAREOWN=               ${UNPRIVILEGED_USER}
170 DOCGRP=                 ${UNPRIVILEGED_GROUP}
171 DOCOWN=                 ${UNPRIVILEGED_USER}
172
173 # Override installation modes.  As a regular user, we may have problems
174 # when overwriting files if they are not writable.
175 BINMODE=                755
176 NONBINMODE=             644
177
178 .  if !empty(_UNPRIVILEGED:Munprivileged) && empty(_UNPRIVILEGED:Muser-destdir)
179 # Only do the following for unprivileged, normal builds.
180
181 PKG_USERS_VARS?=        # empty
182 PKG_GROUPS_VARS?=       # empty
183 BUILD_DEFS+=            ${PKG_USERS_VARS} ${PKG_GROUPS_VARS}
184
185 # Override per-package custom users and groups, except for groups listed
186 # in UNPRIVILEGED_GROUPS.
187 .    for _var_ in ${PKG_USERS_VARS}
188 ${_var_}=               ${UNPRIVILEGED_USER}
189 .    endfor
190 .    for _var_ in ${PKG_GROUPS_VARS}
191 .      if empty(UNPRIVILEGED_GROUPS:M${${_var_}})
192 ${_var_}=               ${UNPRIVILEGED_GROUP}
193 .      endif
194 .    endfor
195 .  endif
196
197 .endif
198
199 .if !empty(_UNPRIVILEGED:Munprivileged)
200 # As a regular user, creation of other users and groups won't work, so
201 # disable this step by default.
202 PKG_CREATE_USERGROUP=   NO
203
204 # Override commands that won't work as a regular user.
205 TOOLS_PLATFORM.chgrp=   ${TRUE} chgrp
206 TOOLS_PLATFORM.chown=   ${TRUE} chown
207 SU_CMD=                 ${SH} -c
208
209 # Do not attempt to modify /etc/shells as a regular user.
210 PKG_REGISTER_SHELLS=    NO
211 .endif