user.eclass: Factor out finding nologin into separate function
authorMichał Górny <mgorny@gentoo.org>
Thu, 6 Jun 2019 14:21:28 +0000 (16:21 +0200)
committerMichał Górny <mgorny@gentoo.org>
Thu, 20 Jun 2019 08:16:43 +0000 (10:16 +0200)
Signed-off-by: Michał Górny <mgorny@gentoo.org>
eclass/user.eclass

index 8afbc101fac3fe37bb9405f9ee9e3a280c956a83..54d7a3fdbe28bc3de68ebfe35ab2cbd974423a38 100644 (file)
@@ -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: <user> [-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}" )