From 6e0cd8d48049ffeac1b9a9b4e0be735651865dc5 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Wed, 29 May 2019 19:48:28 +0200 Subject: user.eclass: Support disabling home directory creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- eclass/user.eclass | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'eclass') diff --git a/eclass/user.eclass b/eclass/user.eclass index a24920af13f1..0577df81ae78 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -71,12 +71,15 @@ egetent() { } # @FUNCTION: enewuser -# @USAGE: [uid] [shell] [homedir] [groups] +# @USAGE: [-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}" -- cgit v1.2.3-65-gdbad