From 95ec6aaf25cb32bded8ff48282f19468dc89a297 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 6 Jun 2019 16:21:28 +0200 Subject: [PATCH] user.eclass: Factor out finding nologin into separate function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- eclass/user.eclass | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/eclass/user.eclass b/eclass/user.eclass index 8afbc101fac3..54d7a3fdbe28 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -70,6 +70,31 @@ egetent() { esac } +# @FUNCTION: user_get_nologin +# @INTERNAL +# @DESCRIPTION: +# Find an appropriate 'nologin' shell for the platform, and output +# its path. +user_get_nologin() { + local eshell + + for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do + [[ -x ${ROOT}${eshell} ]] && break + done + + if [[ ${eshell} == "/dev/null" ]] ; then + ewarn "Unable to identify the shell to use, proceeding with userland default." + case ${USERLAND} in + GNU) eshell="/bin/false" ;; + BSD) eshell="/sbin/nologin" ;; + Darwin) eshell="/usr/sbin/nologin" ;; + *) die "Unable to identify the default shell for userland ${USERLAND}" + esac + fi + + echo "${eshell}" +} + # @FUNCTION: enewuser # @USAGE: [-F] [-M] [uid] [shell] [homedir] [groups] # @DESCRIPTION: @@ -152,19 +177,7 @@ enewuser() { die "Pass '-1' as the shell parameter" fi else - for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do - [[ -x ${ROOT}${eshell} ]] && break - done - - if [[ ${eshell} == "/dev/null" ]] ; then - eerror "Unable to identify the shell to use, proceeding with userland default." - case ${USERLAND} in - GNU) eshell="/bin/false" ;; - BSD) eshell="/sbin/nologin" ;; - Darwin) eshell="/usr/sbin/nologin" ;; - *) die "Unable to identify the default shell for userland ${USERLAND}" - esac - fi + eshell=$(user_get_nologin) fi einfo " - Shell: ${eshell}" opts+=( -s "${eshell}" ) -- 2.26.2