Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Dec 2011 18:57:39 GMT
From:      Chris Rees <crees@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/163511: [PATCH] bsd.port.mk: Allow existing users on system to be used by ports
Message-ID:  <201112211857.pBLIvdXZ000716@freefall.freebsd.org>
Resent-Message-ID: <201112211900.pBLJ0PJO000837@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         163511
>Category:       ports
>Synopsis:       [PATCH] bsd.port.mk: Allow existing users on system to be used by ports
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 21 19:00:25 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Chris Rees
>Release:        FreeBSD 8.2-STABLE i386
>Organization:
>Environment:
System: FreeBSD freefall.freebsd.org 8.2-STABLE FreeBSD 8.2-STABLE #5 r227907: Wed Nov 23 21:55:50 UTC 2011 simon@freefall.freebsd.org:/usr/obj/usr/src/sys/FREEFALL i386


	
>Description:
	Currently one must ensure that a user in USERS= in a port Makefile is included in ${UID_FILES}.  This of course is important when a port defines a standard username, but when it allows the username to be customised it results in inflexibility (ports/162934).

	Instead of guessing anything, it's still an error if no such user exists, but if the user does exist it uses those details to program the package to create the user.
>How-To-Repeat:
	
>Fix:

	- Detect and use groups and users present on system
	- Correct uses of ECHO_MSG
	- Correct sample master.passwd line

--- bsd-port-mk-users-existing.diff begins here ---
Index: bsd.port.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.699
diff -u -r1.699 bsd.port.mk
--- bsd.port.mk	9 Nov 2011 08:53:12 -0000	1.699
+++ bsd.port.mk	18 Dec 2011 15:55:27 -0000
@@ -4102,23 +4102,28 @@
 .endif
 
 .if !target(create-users-groups)
+GETUSER=	${SH} -c '${GREP} -h ^$${0}: ${UID_FILES} \
+			  || (/usr/bin/getent passwd $${0} \
+			    | ${SED} "s/^\([^:]*:\)\{4\}/&:0:0:/")'
+GETGROUP=	${SH} -c '${GREP} -h ^$${0}: ${GID_FILES} \
+			  || /usr/bin/getent group $${0}'
 create-users-groups:
 .if defined(GROUPS) || defined(USERS)
 .if defined(GROUPS)
 .for _file in ${GID_FILES}
 .if !exists(${_file})
-	@${ECHO_CMD} "** ${_file} doesn't exist. Exiting."; exit 1
+	@${ECHO_MSG} "** ${_file} doesn't exist. Exiting."; exit 1
 .endif
 .endfor
 	@${ECHO_MSG} "===> Creating users and/or groups."
 	@${ECHO_CMD} "@exec echo \"===> Creating users and/or groups.\"" >> ${TMPPLIST}
 .for _group in ${GROUPS}
 # _bgpd:*:130:
-	@if ! ${GREP} -h ^${_group}: ${GID_FILES} >/dev/null 2>&1; then \
-		${ECHO_CMD} "** Cannot find any information about group \`${_group}' in ${GID_FILES}."; \
+	@if ! ${GETGROUP} ${_group} >/dev/null 2>&1; then \
+		${ECHO_MSG} "** Cannot find any information about group \`${_group}' in ${GID_FILES}."; \
 		exit 1; \
 	fi
-	@IFS=":"; ${GREP} -h ^${_group}: ${GID_FILES} | head -n 1 | while read group foo gid members; do \
+	@IFS=":"; ${GETGROUP} ${_group} | head -n 1 | while read group foo gid members; do \
 		gid=$$(($$gid+${GID_OFFSET})); \
 		if ! ${PW} groupshow $$group >/dev/null 2>&1; then \
 			${ECHO_MSG} "Creating group \`$$group' with gid \`$$gid'."; \
@@ -4135,16 +4140,16 @@
 .if defined(USERS)
 .for _file in ${UID_FILES}
 .if !exists(${_file})
-	@${ECHO_CMD} "** ${_file} doesn't exist. Exiting."; exit 1
+	@${ECHO_MSG} "** ${_file} doesn't exist. Exiting."; exit 1
 .endif
 .endfor
 .for _user in ${USERS}
-# _bgpd:*:130:130:BGP Daemon:/var/empty:/sbin/nologin
-	@if ! ${GREP} -h ^${_user}: ${UID_FILES} >/dev/null 2>&1; then \
-		${ECHO_CMD} "** Cannot find any information about user \`${_user}' in ${UID_FILES}."; \
+# _bgpd:*:130:130::0:0:BGP Daemon:/var/empty:/sbin/nologin
+	@if ! ${GETUSER} ${_user} >/dev/null 2>&1; then \
+		${ECHO_MSG} "** Cannot find any information about user \`${_user}' in ${UID_FILES}."; \
 		exit 1; \
 	fi
-	@IFS=":"; ${GREP} -h ^${_user}: ${UID_FILES} | head -n 1 | while read login passwd uid gid class change expire gecos homedir shell; do \
+	@IFS=":"; ${GETUSER} ${_user} | head -n 1 | while read login passwd uid gid class change expire gecos homedir shell; do \
 		uid=$$(($$uid+${UID_OFFSET})); \
 		gid=$$(($$gid+${GID_OFFSET})); \
 		class="$${class:+-L }$$class"; \
@@ -4166,7 +4171,7 @@
 .if defined(GROUPS)
 .for _group in ${GROUPS}
 # mail:*:6:postfix,clamav
-	@IFS=":"; ${GREP} -h ^${_group}: ${GID_FILES} | head -n 1 | while read group foo gid members; do \
+	@IFS=":"; ${GETGROUP} ${_group} | head -n 1 | while read group foo gid members; do \
 		gid=$$(($$gid+${GID_OFFSET})); \
 		IFS=","; for _login in $$members; do \
 			for _user in ${USERS}; do \
--- bsd-port-mk-users-existing.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112211857.pBLIvdXZ000716>