Subject: Support adding admin users/groups via defs.${OPSYS}.mk
To: None <tech-pkg@NetBSD.org>
From: Juan RP <juan@xtraeme.unixbsd.org>
List: tech-pkg
Date: 01/11/2004 05:08:27
Hi,

Actually, we have a problem with pkgsrc, when we want to install a package which
needs to create new users/groups in some platforms (FreeBSD, BSD/OS,
Darwin, etc)...

I would like to commit this patch, and modify all defs.${OPSYS}.mk files, with
that change all platforms should be able to create users/groups when
using PKG_{USERS,GROUPS}.

This patch changes defs.FreeBSD.mk, which was my test system.

Comments?

----

Index: defs.FreeBSD.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/defs.FreeBSD.mk,v
retrieving revision 1.28
diff -b -u -r1.28 defs.FreeBSD.mk
--- defs.FreeBSD.mk	2003/12/16 23:07:42	1.28
+++ defs.FreeBSD.mk	2004/01/11 03:41:25
@@ -84,16 +84,14 @@
 WC?=		/usr/bin/wc
 XARGS?=		/usr/bin/xargs
 
-.if exists(/usr/sbin/user)
-USERADD?=	/usr/sbin/useradd
-GROUPADD?=	/usr/sbin/groupadd
-.else
-USERADD?=	${LOCALBASE}/sbin/useradd
-GROUPADD?=	${LOCALBASE}/sbin/groupadd
-.if defined(USE_USERADD) || defined(USE_GROUPADD)
-DEPENDS+=	user>=20000313:../../sysutils/user
-.endif
-.endif
+USERADD?=	/usr/sbin/pw useradd 
+GROUPADD?=	/usr/sbin/pw groupadd
+USERADD_USERID_ARG?=	-u
+USERADD_GROUPID_ARG?=	-g
+USERADD_HOME_ARG?=	-d
+USERADD_SHELL_ARG?=	-s
+USERADD_NAME_ARG?=	-n
+USERADD_DESCR_ARG?=	-c
 
 CPP_PRECOMP_FLAGS?=	# unset
 DEF_UMASK?=		0022
Index: install/install
===================================================================
RCS file: /cvsroot/pkgsrc/mk/install/install,v
retrieving revision 1.30
diff -b -u -r1.30 install
--- install/install	2004/01/08 14:19:29	1.30
+++ install/install	2004/01/11 03:41:28
@@ -53,10 +53,10 @@
 			else
 				groupid_option=
 				if [ -n "${groupid}" ]; then
-					groupid_option="-g"
+					groupid_option="${USERADD_GROUPID_ARG}"
 				fi
 				${ECHO} "Creating group: ${group}"
-				${GROUPADD} ${groupid_option} ${groupid} "${group}"
+				${GROUPADD} ${groupid_option} ${groupid} ${USERADD_NAME_ARG}
"${group}" 			fi
 			${RM} -f /tmp/grouptest.$$
 		done
@@ -93,15 +93,16 @@
 			else
 				userid_option=
 				if [ -n "${userid}" ]; then
-					userid_option="-u"
+					userid_option="${USERADD_USERID_ARG}"
 				fi
 				${ECHO} "Creating user: ${user}"
-				${USERADD} -c "${descr}"		\
+				${USERADD} \
+					${USERADD_DESCR_ARG} "${descr}"		\
 					${userid_option} ${userid}	\
-					-g "${group}"			\
-					-d "${home}"			\
-					-s "${shell}"			\
-					"${user}"
+					${USERADD_GROUPID_ARG} "${group}"	\
+					${USERADD_HOME_ARG} "${home}"		\
+					${USERADD_SHELL_ARG} "${shell}"		\
+					${USERADD_NAME_ARG} "${user}"
 			fi
 		done
 	fi
----

Also the patch is available here:
http://xtraeme.unixbsd.org:81/patches/users_and_groups.diff

-- 
Juan RP <juan AT xtraeme DOT unixbsd DOT org>