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 09/19] user.eclass: Introduce esetshell
Date: Sun, 09 Jun 2019 11:31:48
Message-Id: 20190609112814.15907-10-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH v3 00/19] User/group packages by "Michał Górny"
1 ---
2 eclass/user.eclass | 61 ++++++++++++++++++++++++++++++++++++++++++++++
3 1 file changed, 61 insertions(+)
4
5 diff --git a/eclass/user.eclass b/eclass/user.eclass
6 index 54d7a3fdbe28..3bd381b0c089 100644
7 --- a/eclass/user.eclass
8 +++ b/eclass/user.eclass
9 @@ -465,4 +465,65 @@ esethome() {
10 esac
11 }
12
13 +# @FUNCTION: esetshell
14 +# @USAGE: <user> <shell>
15 +# @DESCRIPTION:
16 +# Update the shell in a platform-agnostic way.
17 +# Required parameters is the username and the new shell.
18 +# Specify -1 if you want to set shell to platform-specific nologin.
19 +esetshell() {
20 + _assert_pkg_ebuild_phase ${FUNCNAME}
21 +
22 + # get the username
23 + local euser=$1; shift
24 + if [[ -z ${euser} ]] ; then
25 + eerror "No username specified !"
26 + die "Cannot call esetshell without a username"
27 + fi
28 +
29 + # lets see if the username already exists
30 + if [[ -z $(egetent passwd "${euser}") ]] ; then
31 + ewarn "User does not exist, cannot set shell -- skipping."
32 + return 1
33 + fi
34 +
35 + # handle shell
36 + local eshell=$1; shift
37 + if [[ -z ${eshell} ]] ; then
38 + eerror "No shell specified !"
39 + die "Cannot call esetshell without a shell or '-1'"
40 + fi
41 +
42 + if [[ ${eshell} == "-1" ]] ; then
43 + eshell=$(user_get_nologin)
44 + fi
45 +
46 + # exit with no message if shell is up to date
47 + if [[ $(egetshell "${euser}") == ${eshell} ]]; then
48 + return 0
49 + fi
50 +
51 + einfo "Updating shell for user '${euser}' ..."
52 + einfo " - Shell: ${eshell}"
53 +
54 + # update the shell
55 + case ${CHOST} in
56 + *-freebsd*|*-dragonfly*)
57 + pw usermod "${euser}" -s "${eshell}" && return 0
58 + [[ $? == 8 ]] && eerror "${euser} is in use, cannot update shell"
59 + eerror "There was an error when attempting to update the shell for ${euser}"
60 + eerror "Please update it manually on your system:"
61 + eerror "\t pw usermod \"${euser}\" -s \"${eshell}\""
62 + ;;
63 +
64 + *)
65 + usermod -s "${eshell}" "${euser}" && return 0
66 + [[ $? == 8 ]] && eerror "${euser} is in use, cannot update shell"
67 + eerror "There was an error when attempting to update the shell for ${euser}"
68 + eerror "Please update it manually on your system (as root):"
69 + eerror "\t usermod -s \"${eshell}\" \"${euser}\""
70 + ;;
71 + esac
72 +}
73 +
74 fi
75 --
76 2.22.0.rc3