From 2108f8e38104fe8a10825c568d7c18fe1ed6e3fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 6 Jun 2019 16:26:46 +0200 Subject: [PATCH] user.eclass: Introduce esetshell MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- eclass/user.eclass | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) 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: +# @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 -- 2.26.2