summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2005-09-26 22:12:35 +0000
committerjlam <jlam@pkgsrc.org>2005-09-26 22:12:35 +0000
commita1660a8258d21143f1b6f917ca1e0ebe8ffda23e (patch)
tree93b4a733ee44d410331bd303299685a8021f54d1 /mk
parent372bc65d83f754a14b38a3d69bf69ce48f3c675e (diff)
downloadpkgsrc-a1660a8258d21143f1b6f917ca1e0ebe8ffda23e.tar.gz
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 (limited to 'mk')
-rw-r--r--mk/install/bsd.pkginstall.mk14
-rw-r--r--mk/install/usergroup38
-rw-r--r--mk/install/usergroupfuncs63
3 files changed, 86 insertions, 29 deletions
diff --git a/mk/install/bsd.pkginstall.mk b/mk/install/bsd.pkginstall.mk
index f4c367716a8..219381e4573 100644
--- a/mk/install/bsd.pkginstall.mk
+++ b/mk/install/bsd.pkginstall.mk
@@ -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 @@ DEPENDS+= ${_USER_DEPENDS}
.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_UNPACK_TMPL+= ${INSTALL_USERGROUP_FILE}
${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 @@ ${INSTALL_USERGROUP_FILE}: ../../mk/install/usergroup
${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 --git a/mk/install/usergroup b/mk/install/usergroup
index 1e38545031c..90b0b9e08df 100644
--- a/mk/install/usergroup
+++ b/mk/install/usergroup
@@ -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 @@ CAT="@CAT@"
CHGRP="@CHGRP@"
ECHO="@ECHO@"
GREP="@GREP@"
-GROUPADD="@GROUPADD@"
ID="@ID@"
MKDIR="@MKDIR@"
PWD_CMD="@PWD_CMD@"
@@ -52,7 +51,6 @@ SED="@SED@"
SORT="@SORT@"
TEST="@TEST@"
TRUE="@TRUE@"
-USERADD="@USERADD@"
SELF=$0
ACTION=$1
@@ -64,9 +62,6 @@ PKG_METADATA_DIR="${2-`${PWD_CMD}`}"
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 @@ listwrap()
esac
}
+# DO NOT CHANGE THE FOLLOWING LINE!
+# platform-specific adduser/addgroup functions
+
exitcode=0
case $ACTION in
ADD)
@@ -159,12 +157,8 @@ ADD)
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 @@ ADD)
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 @@ ADD)
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 --git a/mk/install/usergroupfuncs b/mk/install/usergroupfuncs
new file mode 100644
index 00000000000..1996e50f8e2
--- /dev/null
+++ b/mk/install/usergroupfuncs
@@ -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
+}