commit:     6e0cd8d48049ffeac1b9a9b4e0be735651865dc5
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed May 29 17:48:28 2019 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jun 20 08:16:40 2019 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6e0cd8d4

user.eclass: Support disabling home directory creation

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 eclass/user.eclass | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/eclass/user.eclass b/eclass/user.eclass
index a24920af13f..0577df81ae7 100644
--- a/eclass/user.eclass
+++ b/eclass/user.eclass
@@ -71,12 +71,15 @@ egetent() {
 }
 
 # @FUNCTION: enewuser
-# @USAGE: <user> [uid] [shell] [homedir] [groups]
+# @USAGE: <user> [-M] [uid] [shell] [homedir] [groups]
 # @DESCRIPTION:
 # Same as enewgroup, you are not required to understand how to properly add
 # a user to the system.  The only required parameter is the username.
 # Default uid is (pass -1 for this) next available, default shell is
 # /bin/false, default homedir is /dev/null, and there are no default groups.
+#
+# If -M is passed, enewuser does not create the home directory if it does not
+# exist.
 enewuser() {
        if [[ ${EUID} != 0 ]] ; then
                einfo "Insufficient privileges to execute ${FUNCNAME[0]}"
@@ -84,6 +87,15 @@ enewuser() {
        fi
        _assert_pkg_ebuild_phase ${FUNCNAME}
 
+       local create_home=1
+       while [[ $1 == -* ]]; do
+               case $1 in
+                       -M) create_home=;;
+                       *) die "${FUNCNAME}: invalid option ${1}";;
+               esac
+               shift
+       done
+
        # get the username
        local euser=$1; shift
        if [[ -z ${euser} ]] ; then
@@ -213,7 +225,7 @@ enewuser() {
                ;;
        esac
 
-       if [[ ! -e ${ROOT}/${ehome} ]] ; then
+       if [[ -n ${create_home} && ! -e ${ROOT}/${ehome} ]] ; then
                einfo " - Creating ${ehome} in ${ROOT}"
                mkdir -p "${ROOT}/${ehome}"
                chown "${euser}" "${ROOT}/${ehome}"

Reply via email to