git: 4280a82efe69 - main - Mk/Scripts/do-users-groups.sh: Make users and groups creation fail-fast

From: Michael Osipov <michaelo_at_FreeBSD.org>
Date: Fri, 03 May 2024 07:47:27 UTC
The branch main has been updated by michaelo:

URL: https://cgit.FreeBSD.org/ports/commit/?id=4280a82efe69f5dc77a67394f7bd36095c74cd6c

commit 4280a82efe69f5dc77a67394f7bd36095c74cd6c
Author:     Michael Osipov <michaelo@FreeBSD.org>
AuthorDate: 2023-11-22 11:30:32 +0000
Commit:     Michael Osipov <michaelo@FreeBSD.org>
CommitDate: 2024-05-03 07:44:53 +0000

    Mk/Scripts/do-users-groups.sh: Make users and groups creation fail-fast
    
    Fail fast when pw(8) fails to create a user or a group. Especially when it is
    not the last command in the pre-install script then the exit code will be 0 and
    the failure will go unnoticed.
    
    PR:             267384
    Approved by:    jrm (mentor)
    Differential Revision:  https://reviews.freebsd.org/D42719
---
 Mk/Scripts/do-users-groups.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Mk/Scripts/do-users-groups.sh b/Mk/Scripts/do-users-groups.sh
index b4ddf5a8a5d3..fdaad401de72 100644
--- a/Mk/Scripts/do-users-groups.sh
+++ b/Mk/Scripts/do-users-groups.sh
@@ -76,7 +76,7 @@ if [ -n "${GROUPS}" ]; then
 			cat >> "${dp_UG_INSTALL}" <<-eot2
 			if ! \${PW} groupshow $group >/dev/null 2>&1; then
 			  echo "Creating group '$group' with gid '$gid'"
-			  \${PW} groupadd $group -g $gid
+			  \${PW} groupadd $group -g $gid || exit \$?
 			else
 			  echo "Using existing group '$group'"
 			fi
@@ -129,7 +129,7 @@ if [ -n "${USERS}" ]; then
 			cat >> "${dp_UG_INSTALL}" <<-eot2
 			if ! \${PW} usershow $login >/dev/null 2>&1; then
 			  echo "Creating user '$login' with uid '$uid'"
-			  \${PW} useradd $login -u $uid -g $gid $class -c "$gecos" -d $homedir -s $shell
+			  \${PW} useradd $login -u $uid -g $gid $class -c "$gecos" -d $homedir -s $shell || exit \$?
 			else
 			  echo "Using existing user '$login'"
 			fi
@@ -185,7 +185,7 @@ if [ -n "${GROUPS}" ]; then
 						cat >> "${dp_UG_INSTALL}" <<-eot2
 						if ! \${PW} groupshow ${group} | grep -qw ${login}; then
 						  echo "Adding user '${login}' to group '${group}'"
-						  \${PW} groupmod ${group} -m ${login}
+						  \${PW} groupmod ${group} -m ${login} || exit \$?
 						fi
 						eot2
 					fi