Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH v3 08/19] user.eclass: Factor out finding nologin into separate function
Date: Sun, 09 Jun 2019 11:31:29
Message-Id: 20190609112814.15907-9-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH v3 00/19] User/group packages by "Michał Górny"
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 eclass/user.eclass | 39 ++++++++++++++++++++++++++-------------
4 1 file changed, 26 insertions(+), 13 deletions(-)
5
6 diff --git a/eclass/user.eclass b/eclass/user.eclass
7 index 8afbc101fac3..54d7a3fdbe28 100644
8 --- a/eclass/user.eclass
9 +++ b/eclass/user.eclass
10 @@ -70,6 +70,31 @@ egetent() {
11 esac
12 }
13
14 +# @FUNCTION: user_get_nologin
15 +# @INTERNAL
16 +# @DESCRIPTION:
17 +# Find an appropriate 'nologin' shell for the platform, and output
18 +# its path.
19 +user_get_nologin() {
20 + local eshell
21 +
22 + for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do
23 + [[ -x ${ROOT}${eshell} ]] && break
24 + done
25 +
26 + if [[ ${eshell} == "/dev/null" ]] ; then
27 + ewarn "Unable to identify the shell to use, proceeding with userland default."
28 + case ${USERLAND} in
29 + GNU) eshell="/bin/false" ;;
30 + BSD) eshell="/sbin/nologin" ;;
31 + Darwin) eshell="/usr/sbin/nologin" ;;
32 + *) die "Unable to identify the default shell for userland ${USERLAND}"
33 + esac
34 + fi
35 +
36 + echo "${eshell}"
37 +}
38 +
39 # @FUNCTION: enewuser
40 # @USAGE: <user> [-F] [-M] [uid] [shell] [homedir] [groups]
41 # @DESCRIPTION:
42 @@ -152,19 +177,7 @@ enewuser() {
43 die "Pass '-1' as the shell parameter"
44 fi
45 else
46 - for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do
47 - [[ -x ${ROOT}${eshell} ]] && break
48 - done
49 -
50 - if [[ ${eshell} == "/dev/null" ]] ; then
51 - eerror "Unable to identify the shell to use, proceeding with userland default."
52 - case ${USERLAND} in
53 - GNU) eshell="/bin/false" ;;
54 - BSD) eshell="/sbin/nologin" ;;
55 - Darwin) eshell="/usr/sbin/nologin" ;;
56 - *) die "Unable to identify the default shell for userland ${USERLAND}"
57 - esac
58 - fi
59 + eshell=$(user_get_nologin)
60 fi
61 einfo " - Shell: ${eshell}"
62 opts+=( -s "${eshell}" )
63 --
64 2.22.0.rc3