pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/install Allow platform-specific overrides for creat...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/ae3910ec24f8
branches:  trunk
changeset: 499767:ae3910ec24f8
user:      jlam <jlam%pkgsrc.org@localhost>
date:      Mon Sep 26 22:12:35 2005 +0000

description:
Allow platform-specific overrides for creating new users and groups.
There is a default implementation of the shell functions adduser()
and addgroup() used by the +USERGROUP script that uses NetBSD/Solaris-style
useradd(8) and groupadd(8) commands.  A platform may override those
functions by creating pkgsrc/mk/install/usergroupfuncs.${OPSYS}.  This
fixes PR pkg/23061.

diffstat:

 mk/install/bsd.pkginstall.mk |  14 +++++++--
 mk/install/usergroup         |  38 ++++++++------------------
 mk/install/usergroupfuncs    |  63 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 29 deletions(-)

diffs (205 lines):

diff -r e8af19b1ab92 -r ae3910ec24f8 mk/install/bsd.pkginstall.mk
--- a/mk/install/bsd.pkginstall.mk      Mon Sep 26 22:08:20 2005 +0000
+++ b/mk/install/bsd.pkginstall.mk      Mon Sep 26 22:12:35 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkginstall.mk,v 1.26 2005/08/24 22:43:02 rillig Exp $
+# $NetBSD: bsd.pkginstall.mk,v 1.27 2005/09/26 22:12:35 jlam Exp $
 #
 # This Makefile fragment is included by bsd.pkg.mk to use the common
 # INSTALL/DEINSTALL scripts.  To use this Makefile fragment, simply:
@@ -143,6 +143,11 @@
 .endif
 
 INSTALL_USERGROUP_FILE=                ${WRKDIR}/.install-usergroup
+.if exists(../../mk/install/usergroupfuncs.${OPSYS})
+INSTALL_USERGROUPFUNCS_FILE?=  ../../mk/install/usergroupfuncs.${OPSYS}
+.else
+INSTALL_USERGROUPFUNCS_FILE?=  ../../mk/install/usergroupfuncs
+.endif
 INSTALL_USERGROUP_MEMBERS=     ${PKG_USERS} ${PKG_GROUPS}
 INSTALL_UNPACK_TMPL+=          ${INSTALL_USERGROUP_FILE}
 
@@ -150,7 +155,9 @@
 ${INSTALL_USERGROUP_FILE}:
        ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
 .else
-${INSTALL_USERGROUP_FILE}: ../../mk/install/usergroup
+${INSTALL_USERGROUP_FILE}:                                             \
+               ../../mk/install/usergroup                              \
+               ${INSTALL_USERGROUPFUNCS_FILE}
        ${_PKG_SILENT}${_PKG_DEBUG}                                     \
        ${RM} -f ${.TARGET} ${.TARGET}.tmp;                             \
        exec 1>>${.TARGET}.tmp;                                         \
@@ -163,7 +170,8 @@
        ${ECHO} "case \$${STAGE} in";                                   \
        ${ECHO} "PRE-INSTALL|UNPACK)";                                  \
        ${ECHO} "       \$${CAT} > ./+USERGROUP << 'EOF_USERGROUP'";    \
-       ${SED} ${FILES_SUBST_SED} ../../mk/install/usergroup;           \
+       ${SED}  -e "/^# platform-specific adduser\/addgroup functions/r${INSTALL_USERGROUPFUNCS_FILE}" ../../mk/install/usergroup | \
+       ${SED} ${FILES_SUBST_SED};                                      \
        ${ECHO} "";                                                     \
        set -- dummy ${PKG_GROUPS}; shift;                              \
        while ${TEST} $$# -gt 0; do                                     \
diff -r e8af19b1ab92 -r ae3910ec24f8 mk/install/usergroup
--- a/mk/install/usergroup      Mon Sep 26 22:08:20 2005 +0000
+++ b/mk/install/usergroup      Mon Sep 26 22:12:35 2005 +0000
@@ -1,6 +1,6 @@
 #!@SH@
 #
-# $NetBSD: usergroup,v 1.10 2005/08/19 22:24:10 jlam Exp $
+# $NetBSD: usergroup,v 1.11 2005/09/26 22:12:35 jlam Exp $
 #
 # +USERGROUP - users and groups management script
 #
@@ -42,7 +42,6 @@
 CHGRP="@CHGRP@"
 ECHO="@ECHO@"
 GREP="@GREP@"
-GROUPADD="@GROUPADD@"
 ID="@ID@"
 MKDIR="@MKDIR@"
 PWD_CMD="@PWD_CMD@"
@@ -52,7 +51,6 @@
 SORT="@SORT@"
 TEST="@TEST@"
 TRUE="@TRUE@"
-USERADD="@USERADD@"
 
 SELF=$0
 ACTION=$1
@@ -64,9 +62,6 @@
 PKG_REFCOUNT_USERS_DBDIR="${PKG_REFCOUNT_DBDIR}/users"
 PKG_REFCOUNT_GROUPS_DBDIR="${PKG_REFCOUNT_DBDIR}/groups"
 
-PKG_USER_HOME="@PKG_USER_HOME@"
-PKG_USER_SHELL="@PKG_USER_SHELL@"
-
 case "${PKG_CREATE_USERGROUP:-@PKG_CREATE_USERGROUP@}" in
 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
        _PKG_CREATE_USERGROUP=yes
@@ -129,6 +124,9 @@
        esac
 }
 
+# DO NOT CHANGE THE FOLLOWING LINE!
+# platform-specific adduser/addgroup functions
+
 exitcode=0
 case $ACTION in
 ADD)
@@ -159,12 +157,8 @@
                yes)
                        if group_exists $group; then
                                :
-                       elif ${TEST} -n "${GROUPADD}" -a -x "${GROUPADD}"; then
-                               ${ECHO} "Creating group: $group";
-                               case $groupid in
-                               "")     ${GROUPADD} $group ;;
-                               *)      ${GROUPADD} -g $groupid $group ;;
-                               esac
+                       else
+                               addgroup "$group" "$groupid"
                        fi
                        ;;
                esac
@@ -179,9 +173,9 @@
                case $user in
                "")     continue ;;
                esac
-               : ${descr:="${PKGNAME%-[0-9]*} $user user"}
-               : ${home:="${PKG_USER_HOME}"}
-               : ${shell:="${PKG_USER_SHELL}"}
+               case $group in
+               "")     continue ;;
+               esac
                shadow_dir="${PKG_REFCOUNT_USERS_DBDIR}/$user"
                preexist="$shadow_dir/+PREEXISTING"
                token="$shadow_dir/${PKGNAME}"
@@ -200,17 +194,9 @@
                yes)
                        if user_exists $user && group_exists $group; then
                                :
-                       elif ${TEST} -n "${USERADD}" -a -x "${USERADD}"; then
-                               ${ECHO} "Creating user: $user";
-                               case $userid in
-                               "")     ${USERADD} -c "$descr" -d "$home" \
-                                               -s "$shell" -g $group $user
-                                       ;;
-                               *)      ${USERADD} -c "$descr" -d "$home" \
-                                               -s "$shell" -g $group \
-                                               -u $userid $user
-                                       ;;
-                               esac
+                       else
+                               adduser "$user" "$group" "$userid"      \
+                                       "$descr" "$home" "$shell"
                        fi
                        ;;
                esac
diff -r e8af19b1ab92 -r ae3910ec24f8 mk/install/usergroupfuncs
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/install/usergroupfuncs Mon Sep 26 22:12:35 2005 +0000
@@ -0,0 +1,63 @@
+# $NetBSD: usergroupfuncs,v 1.1 2005/09/26 22:12:35 jlam Exp $
+#
+# Default implementation of adduser() and addgroup() shell functions
+# for addiing users and groups.  This implementation assumes there are
+# NetBSD/Solaris-compatible versions of useradd(8) and groupadd(8)
+# available through ${USERADD} and ${GROUPADD}, respectively.
+#
+# Platform-specific customizations of this file should be located at:
+#
+#      pkgsrc/mk/install/usergroupfuncs.${OPSYS}
+#
+
+# adduser user group [userid] [descr] [home] [shell]
+adduser()
+{
+       user="$1"; group="$2"; userid="$3"
+       descr="$4"; home="$5" shell="$6"
+       ${TEST} $# -eq 6 || return 1
+       ${TEST} -n "$user" || return 2
+       ${TEST} -n "$group" || return 2
+
+       USERADD="@USERADD@"
+
+       : ${descr:="${PKGNAME%-[0-9]*} $user user"}
+       : ${home:="@PKG_USER_HOME@"}
+       : ${shell:="@PKG_USER_SHELL@"}
+
+       if ${TEST} -n "${USERADD}" -a -x "${USERADD}"; then
+               ${ECHO} "Creating user: $user"
+               case $userid in
+               "")
+                       ${USERADD}                                      \
+                               -c "$descr" -d "$home" -s "$shell"      \
+                               -g $group $user
+                       ;;
+               *)
+                       ${USERADD}                                      \
+                               -c "$descr" -d "$home" -s "$shell"      \
+                               -g $group -u $userid $user
+                       ;;
+               esac
+       fi
+       return 0
+}
+
+# adduser group [groupid]
+addgroup()
+{
+       group="$1"; groupid="$2"
+       ${TEST} $# -eq 2 || return 1
+       ${TEST} -n "$group" || return 2
+
+       GROUPADD="@GROUPADD@"
+
+       if ${TEST} -n "${GROUPADD}" -a -x "${GROUPADD}"; then
+               ${ECHO} "Creating group: $group";
+               case $groupid in
+               "")     ${GROUPADD} $group ;;
+               *)      ${GROUPADD} -g $groupid $group ;;
+               esac
+       fi
+       return 0
+}



Home | Main Index | Thread Index | Old Index