diff options
author | Michał Górny <mgorny@gentoo.org> | 2019-05-29 19:48:28 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2019-06-20 10:16:40 +0200 |
commit | 6e0cd8d48049ffeac1b9a9b4e0be735651865dc5 (patch) | |
tree | bb16beeee52d02ef05ab7cb9632582b4ac240c5b /eclass | |
parent | user.eclass: Prevent automated home creation in useradd (diff) | |
download | gentoo-6e0cd8d48049ffeac1b9a9b4e0be735651865dc5.tar.gz gentoo-6e0cd8d48049ffeac1b9a9b4e0be735651865dc5.tar.bz2 gentoo-6e0cd8d48049ffeac1b9a9b4e0be735651865dc5.zip |
user.eclass: Support disabling home directory creation
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/user.eclass | 16 |
1 files changed, 14 insertions, 2 deletions
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: <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}" |