pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/mk/install Add two new capabilities to the pkginstall ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/8606102002f6
branches: trunk
changeset: 511819:8606102002f6
user: jlam <jlam%pkgsrc.org@localhost>
date: Sun Apr 23 00:00:43 2006 +0000
description:
Add two new capabilities to the pkginstall framework:
(1) Allow specifying the numeric UID and GID for users and groups in
/etc/mk.conf by setting PKG_UID.<user> and PKG_GID.<group> to
those values. If these values are specified, then the +USERGROUP
script will verify that existing users and groups match the
requested UIDs and GIDs for the package, and otherwise create them
with these UIDs and GIDs. For example:
PKG_UID.courier= 10001
PKG_GID.mail= 6
In this example, the courier-authlib binary package will be created
to use uid 10001 for the "courier" user and gid 6 for the "mail"
group.
(2) Allow a package to request that users and groups be created prior
to configuring or building a package by setting USERGROUP_PHASE
to "configure" or "build". Because the reason for this is typically
to hardcode the UIDs and GIDs of requested users and groups directly
into the package's executables, these hardcoded values will be
automatically determined and put into the +USERGROUP script. For
example:
USERGROUP_PHASE= configure
PKG_GROUPS= qmail nofiles
PKG_USERS+= qmaill:nofiles
PKG_USERS+= qmailq:qmail
In this example, the users and groups are created before the
configure phase when building qmail, and the qmail binary package's
+INSTALL script will try to create (or verify) users and groups
with the same UIDs and GIDs that were used during the build.
As part of these changes, the format for PKG_USERS and PKG_GROUPS has
changed -- the optional parts of the corresponding entries are no
longer used and cannot be specified. Instead, the following variables
should be set:
PKG_GID.<group> is the group's numeric GID.
PKG_UID.<user> is the user's numeric UID.
PKG_GECOS.<user> is the user's description.
PKG_HOME.<user> is the user's home directory.
PKG_SHELL.<user> is the user's login shell.
A separate commit will follow which will fix all packages that set
PKG_USERS and PKG_GROUPS to use the new syntax and variables.
diffstat:
doc/guide/files/pkginstall.xml | 44 +++++++-----
mk/install/bsd.pkginstall.mk | 117 ++++++++++++++++++++++++++++++---
mk/install/usergroup | 78 +++++++--------------
mk/install/usergroup-check | 126 ++++++++++++++++++++++++++++++++++++
mk/install/usergroupfuncs | 79 +++++++++++++++++++++-
mk/install/usergroupfuncs.DragonFly | 70 +++++++++++++++++++-
mk/install/usergroupfuncs.FreeBSD | 70 +++++++++++++++++++-
7 files changed, 496 insertions(+), 88 deletions(-)
diffs (truncated from 792 to 300 lines):
diff -r 73d470fc2d74 -r 8606102002f6 doc/guide/files/pkginstall.xml
--- a/doc/guide/files/pkginstall.xml Sat Apr 22 18:44:58 2006 +0000
+++ b/doc/guide/files/pkginstall.xml Sun Apr 23 00:00:43 2006 +0000
@@ -1,4 +1,4 @@
-<!-- $NetBSD: pkginstall.xml,v 1.10 2006/02/12 14:44:59 rillig Exp $ -->
+<!-- $NetBSD: pkginstall.xml,v 1.11 2006/04/23 00:00:43 jlam Exp $ -->
<chapter id="pkginstall"> <?dbhtml filename="pkginstall.html"?>
<title>The pkginstall framework</title>
@@ -426,33 +426,41 @@
<para>Users can be created by adding entries to the
<varname>PKG_USERS</varname> variable. Each entry has the following
-syntax, which mimics <filename>/etc/passwd</filename>:</para>
+syntax:</para>
<programlisting>
- user:group[:[userid][:[descr][:[home][:shell]]]]
+ user:group
</programlisting>
-<para>Only the user and group are required; everything else is optional,
-but the colons must be in the right places when specifying optional bits.
-By default, a new user will have home directory
-<filename>/nonexistent</filename>, and login shell
-<filename>/sbin/nologin</filename> unless they are specified as part of the
-user element. Note that if the description contains spaces, then spaces
-should be backslash-escaped, as in:</para>
+<para>Further specification of user details may be done by setting per-user
+variables.
+<varname>PKG_UID.<replaceable>user</replaceable></varname> is the numeric
+UID for the user.
+<varname>PKG_GECOS.<replaceable>user</replaceable></varname> is the user's
+description or comment.
+<varname>PKG_HOME.<replaceable>user</replaceable></varname> is the user's
+home directory, and defaults to <filename>/nonexistent</filename> if not
+specified.
+<varname>PKG_SHELL.<replaceable>user</replaceable></varname> is the user's
+shell, and defaults to <filename>/sbinno/login</filename> if not specified.
+</para>
-<programlisting>
- foo:foogrp::The\ Foomister
-</programlisting>
-
-<para>Similarly, groups can be created using the
+<para>Similarly, groups can be created by adding entries to the
<varname>PKG_GROUPS</varname> variable, whose syntax is:</para>
<programlisting>
- group[:groupid]
+ group
</programlisting>
-<para>As before, only the group name is required; the numeric identifier is
-optional.</para>
+<para>The numeric GID of the group may be set by defining
+<varname>PKG_GID.<replaceable>group</replaceable></varname>.</para>
+
+<para>If a package needs to create the users and groups at an earlier
+stage, then it can set <varname>USERGROUP_PHASE</varname> to
+either <literal>configure</literal> or <literal>build</literal> to
+indicate the phase before which the users and groups are created. In
+this case, the numeric UIDs and GIDs of the created users and groups
+are automatically hardcoded into the final installation scripts.</para>
</sect1>
diff -r 73d470fc2d74 -r 8606102002f6 mk/install/bsd.pkginstall.mk
--- a/mk/install/bsd.pkginstall.mk Sat Apr 22 18:44:58 2006 +0000
+++ b/mk/install/bsd.pkginstall.mk Sun Apr 23 00:00:43 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkginstall.mk,v 1.46 2006/04/16 04:27:17 jlam Exp $
+# $NetBSD: bsd.pkginstall.mk,v 1.47 2006/04/23 00:00:43 jlam Exp $
#
# This Makefile fragment is included by bsd.pkg.mk and implements the
# common INSTALL/DEINSTALL scripts framework. To use the pkginstall
@@ -111,21 +111,41 @@
# PKG_USERS represents the users to create for the package. It is a
# space-separated list of elements of the form
#
-# user:group[:[userid][:[descr][:[home][:shell]]]]
+# user:group
+#
+# The following variables are optional and specify further details of
+# the user accounts listed in PKG_USERS:
#
-# Only the user and group are required; everything else is optional,
-# but the colons must be in the right places when specifying optional
-# bits. Note that if the description contains spaces, they must
-# be escaped as usual, e.g.
+# PKG_UID.<user> is the hardcoded numeric UID for <user>.
+# PKG_GECOS.<user> is <user>'s description, as well as contact info.
+# PKG_HOME.<user> is the home directory for <user>.
+# PKG_SHELL.<user> is the login shell for <user>.
#
-# foo:foogrp::The\ Foomister
#
# PKG_GROUPS represents the groups to create for the package. It is a
# space-separated list of elements of the form
#
-# group[:groupid]
+# group
+#
+# The following variables are optional and specify further details of
+# the user accounts listed in PKG_GROUPS:
+#
+# PKG_GID.<group> is the hardcoded numeric GID for <group>.
+#
+# For example:
#
-# Only the group is required; the groupid is optional.
+# PKG_GROUPS+= mail
+# PKG_USERS+= courier:mail
+#
+# PKG_GECOS.courier= Courier authlib and mail user
+#
+# USERGROUP_PHASE is set to the phase just before which users and
+# groups need to be created. Valid values are "configure" and
+# "build". If not defined, then by default users and groups
+# are created prior to installation by the pre-install-script
+# target. If this is defined, then the numeric UIDs and GIDs
+# of users and groups required by this package are hardcoded
+# into the +INSTALL script.
#
PKG_GROUPS?= # empty
PKG_USERS?= # empty
@@ -162,19 +182,43 @@
_INSTALL_UNPACK_TMPL+= ${_INSTALL_USERGROUP_FILE}
_INSTALL_DATA_TMPL+= ${_INSTALL_USERGROUP_DATAFILE}
+.for _group_ in ${PKG_GROUPS}
+. if defined(USERGROUP_PHASE)
+# Determine the numeric GID of each group.
+USE_TOOLS+= perl
+PKG_GID.${_group_}_cmd= \
+ if ${TEST} ! -x ${PERL5}; then ${ECHO} ""; exit 0; fi; \
+ ${PERL5} -le 'print scalar getgrnam shift' ${_group_}
+PKG_GID.${_group_}?= ${PKG_GID.${_group_}_cmd:sh:M*}
+. endif
+_PKG_GROUPS+= ${_group_}:${PKG_GID.${_group_}}
+.endfor
+
+.for _entry_ in ${PKG_USERS}
+. if defined(USERGROUP_PHASE)
+# Determine the numeric UID of each user.
+USE_TOOLS+= perl
+PKG_UID.${_entry_:C/\:.*//}_cmd= \
+ if ${TEST} ! -x ${PERL5}; then ${ECHO} ""; exit 0; fi; \
+ ${PERL5} -le 'print scalar getpwnam shift' ${_entry_:C/\:.*//}
+PKG_UID.${_entry_:C/\:.*//}?= ${PKG_UID.${_entry_:C/\:.*//}_cmd:sh:M*}
+. endif
+_PKG_USERS+= ${_user_::=${_entry_:C/\:.*//}}${_entry_}:${PKG_UID.${_user_}}:${PKG_GECOS.${_user_}:Q}:${PKG_HOME.${_user_}:Q}:${PKG_SHELL.${_user_}:Q}
+.endfor
+
${_INSTALL_USERGROUP_DATAFILE}:
${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H}
${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp
${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp
${_PKG_SILENT}${_PKG_DEBUG} \
- set -- dummy ${PKG_GROUPS}; shift; \
+ set -- dummy ${_PKG_GROUPS:C/\:*$//}; shift; \
exec 1>>${.TARGET}.tmp; \
while ${TEST} $$# -gt 0; do \
i="$$1"; shift; \
${ECHO} "# GROUP: $$i"; \
done
${_PKG_SILENT}${_PKG_DEBUG} \
- set -- dummy ${PKG_USERS}; shift; \
+ set -- dummy ${_PKG_USERS:C/\:*$//}; shift; \
exec 1>>${.TARGET}.tmp; \
while ${TEST} $$# -gt 0; do \
i="$$1"; shift; \
@@ -196,6 +240,57 @@
${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \
fi
+_INSTALL_USERGROUP_UNPACKER= ${_PKGINSTALL_DIR}/usergroup-unpack
+
+${_INSTALL_USERGROUP_UNPACKER}: \
+ ${_INSTALL_USERGROUP_FILE} \
+ ${_INSTALL_USERGROUP_DATAFILE}
+ ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H}
+ ${_PKG_SILENT}${_PKG_DEBUG} \
+ exec 1>${.TARGET}.tmp; \
+ ${ECHO} "#!${SH}"; \
+ ${ECHO} ""; \
+ ${ECHO} "CAT="${CAT:Q}; \
+ ${ECHO} "CHMOD="${CHMOD:Q}; \
+ ${ECHO} "SED="${SED:Q}; \
+ ${ECHO} ""; \
+ ${ECHO} "SELF=\$$0"; \
+ ${ECHO} "STAGE=UNPACK"; \
+ ${ECHO} ""; \
+ ${CAT} ${_INSTALL_USERGROUP_FILE} \
+ ${_INSTALL_USERGROUP_DATAFILE}
+ ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET}
+ ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET}
+
+.if defined(USERGROUP_PHASE)
+. if !empty(USERGROUP_PHASE:M*configure)
+pre-configure: create-usergroup
+. elif !empty(USERGROUP_PHASE:M*build)
+pre-build: create-usergroup
+. endif
+.endif
+
+_INSTALL_USERGROUP_CHECK= \
+ ${SETENV} PERL5=${PERL5:Q} \
+ ${SH} ${PKGSRCDIR}/mk/install/usergroup-check
+
+.PHONY: create-usergroup
+create-usergroup: ${_INSTALL_USERGROUP_UNPACKER}
+ ${_PKG_SILENT}${_PKG_DEBUG} \
+ if ${_INSTALL_USERGROUP_CHECK} -g ${_PKG_GROUPS:C/\:*$//} && \
+ ${_INSTALL_USERGROUP_CHECK} -u ${_PKG_USERS:C/\:*$//}; then \
+ exit 0; \
+ fi; \
+ cd ${_PKGINSTALL_DIR} && \
+ ${SH} ${_INSTALL_USERGROUP_UNPACKER} && \
+ ${TEST} -f ./+USERGROUP && \
+ ./+USERGROUP ADD ${_PKG_DBDIR}/${PKGNAME} && \
+ ./+USERGROUP CHECK-ADD ${_PKG_DBDIR}/${PKGNAME} && \
+ ${RM} -f ${_INSTALL_USERGROUP_FILE:Q} \
+ ${_INSTALL_USERGROUP_DATAFILE:Q} \
+ ${_INSTALL_USERGROUP_UNPACKER:Q} \
+ ./+USERGROUP
+
# SPECIAL_PERMS are lists that look like:
# file user group mode
# At post-install time, file (it may be a directory) is changed to be
diff -r 73d470fc2d74 -r 8606102002f6 mk/install/usergroup
--- a/mk/install/usergroup Sat Apr 22 18:44:58 2006 +0000
+++ b/mk/install/usergroup Sun Apr 23 00:00:43 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: usergroup,v 1.14 2006/03/19 23:58:14 jlam Exp $
+# $NetBSD: usergroup,v 1.15 2006/04/23 00:00:44 jlam Exp $
#
# Generate a +USERGROUP script that reference-counts users and groups
# that are required for the proper functioning of the package.
@@ -44,11 +44,13 @@
#
# Only the group is required; the groupid is optional.
#
+AWK="@AWK@"
CAT="@CAT@"
CHGRP="@CHGRP@"
+CHOWN="@CHOWN@"
ECHO="@ECHO@"
GREP="@GREP@"
-ID="@ID@"
+LS="@LS@"
MKDIR="@MKDIR@"
PWD_CMD="@PWD_CMD@"
RM="@RM@"
@@ -77,36 +79,6 @@
;;
esac
-group_exists()
-{
- _group="$1"
- case $_group in
- "") return 2 ;;
- esac
- # Check using chgrp to work properly in an NIS environment.
- testfile="./grouptest.tmp.$$"
- ${ECHO} > $testfile
- if ${CHGRP} $_group $testfile >/dev/null 2>&1; then
- ${RM} -f $testfile
- return 0
- fi
- ${RM} -f $testfile
- return 1
-}
-
-user_exists()
-{
- _user="$1"
- case $_user in
- "") return 2 ;;
- esac
- # Check using id to work properly in an NIS environment.
- if ${ID} $_user >/dev/null 2>&1; then
- return 0
- fi
- return 1
-}
-
listwrap()
{
_length=$1
@@ -150,7 +122,7 @@
token="$shadow_dir/${PKGNAME}"
if ${TEST} ! -d "$shadow_dir"; then
${MKDIR} $shadow_dir
- group_exists $group &&
+ group_exists $group $groupid &&
${ECHO} "${PKGNAME}" > $preexist
fi
Home |
Main Index |
Thread Index |
Old Index