diff options
author | Michał Górny <mgorny@gentoo.org> | 2019-06-06 16:26:46 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2019-06-20 10:16:45 +0200 |
commit | 2108f8e38104fe8a10825c568d7c18fe1ed6e3fd (patch) | |
tree | 483dd55d61ddca7e50bd2da1732f64fac7777f73 /eclass | |
parent | user.eclass: Factor out finding nologin into separate function (diff) | |
download | gentoo-2108f8e38104fe8a10825c568d7c18fe1ed6e3fd.tar.gz gentoo-2108f8e38104fe8a10825c568d7c18fe1ed6e3fd.tar.bz2 gentoo-2108f8e38104fe8a10825c568d7c18fe1ed6e3fd.zip |
user.eclass: Introduce esetshell
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/user.eclass | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/eclass/user.eclass b/eclass/user.eclass index 54d7a3fdbe28..3bd381b0c089 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -465,4 +465,65 @@ esethome() { esac } +# @FUNCTION: esetshell +# @USAGE: <user> <shell> +# @DESCRIPTION: +# Update the shell in a platform-agnostic way. +# Required parameters is the username and the new shell. +# Specify -1 if you want to set shell to platform-specific nologin. +esetshell() { + _assert_pkg_ebuild_phase ${FUNCNAME} + + # get the username + local euser=$1; shift + if [[ -z ${euser} ]] ; then + eerror "No username specified !" + die "Cannot call esetshell without a username" + fi + + # lets see if the username already exists + if [[ -z $(egetent passwd "${euser}") ]] ; then + ewarn "User does not exist, cannot set shell -- skipping." + return 1 + fi + + # handle shell + local eshell=$1; shift + if [[ -z ${eshell} ]] ; then + eerror "No shell specified !" + die "Cannot call esetshell without a shell or '-1'" + fi + + if [[ ${eshell} == "-1" ]] ; then + eshell=$(user_get_nologin) + fi + + # exit with no message if shell is up to date + if [[ $(egetshell "${euser}") == ${eshell} ]]; then + return 0 + fi + + einfo "Updating shell for user '${euser}' ..." + einfo " - Shell: ${eshell}" + + # update the shell + case ${CHOST} in + *-freebsd*|*-dragonfly*) + pw usermod "${euser}" -s "${eshell}" && return 0 + [[ $? == 8 ]] && eerror "${euser} is in use, cannot update shell" + eerror "There was an error when attempting to update the shell for ${euser}" + eerror "Please update it manually on your system:" + eerror "\t pw usermod \"${euser}\" -s \"${eshell}\"" + ;; + + *) + usermod -s "${eshell}" "${euser}" && return 0 + [[ $? == 8 ]] && eerror "${euser} is in use, cannot update shell" + eerror "There was an error when attempting to update the shell for ${euser}" + eerror "Please update it manually on your system (as root):" + eerror "\t usermod -s \"${eshell}\" \"${euser}\"" + ;; + esac +} + fi |