1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
eclass/user.eclass | 77 ++++++++++++++++++++++++++++++++++++++++++++++ |
4 |
1 file changed, 77 insertions(+) |
5 |
|
6 |
diff --git a/eclass/user.eclass b/eclass/user.eclass |
7 |
index ceb805675cf6..f4f6c75f3b71 100644 |
8 |
--- a/eclass/user.eclass |
9 |
+++ b/eclass/user.eclass |
10 |
@@ -417,6 +417,27 @@ egetshell() { |
11 |
egetent passwd "$1" | cut -d: -f${pos} |
12 |
} |
13 |
|
14 |
+# @FUNCTION: egetcomment |
15 |
+# @USAGE: <user> |
16 |
+# @DESCRIPTION: |
17 |
+# Gets the comment field for the specified user. |
18 |
+egetcomment() { |
19 |
+ local pos |
20 |
+ |
21 |
+ [[ $# -eq 1 ]] || die "usage: egetshell <user>" |
22 |
+ |
23 |
+ case ${CHOST} in |
24 |
+ *-freebsd*|*-dragonfly*) |
25 |
+ pos=8 |
26 |
+ ;; |
27 |
+ *) # Linux, NetBSD, OpenBSD, etc... |
28 |
+ pos=5 |
29 |
+ ;; |
30 |
+ esac |
31 |
+ |
32 |
+ egetent passwd "$1" | cut -d: -f${pos} |
33 |
+} |
34 |
+ |
35 |
# @FUNCTION: esethome |
36 |
# @USAGE: <user> <homedir> |
37 |
# @DESCRIPTION: |
38 |
@@ -550,4 +571,60 @@ esetshell() { |
39 |
esac |
40 |
} |
41 |
|
42 |
+# @FUNCTION: esetcomment |
43 |
+# @USAGE: <user> <comment> |
44 |
+# @DESCRIPTION: |
45 |
+# Update the comment field in a platform-agnostic way. |
46 |
+# Required parameters is the username and the new comment. |
47 |
+esetcomment() { |
48 |
+ _assert_pkg_ebuild_phase ${FUNCNAME} |
49 |
+ |
50 |
+ # get the username |
51 |
+ local euser=$1; shift |
52 |
+ if [[ -z ${euser} ]] ; then |
53 |
+ eerror "No username specified !" |
54 |
+ die "Cannot call esetcomment without a username" |
55 |
+ fi |
56 |
+ |
57 |
+ # lets see if the username already exists |
58 |
+ if [[ -z $(egetent passwd "${euser}") ]] ; then |
59 |
+ ewarn "User does not exist, cannot set comment -- skipping." |
60 |
+ return 1 |
61 |
+ fi |
62 |
+ |
63 |
+ # handle comment |
64 |
+ local ecomment=$1; shift |
65 |
+ if [[ -z ${ecomment} ]] ; then |
66 |
+ eerror "No comment specified !" |
67 |
+ die "Cannot call esetcomment without a comment" |
68 |
+ fi |
69 |
+ |
70 |
+ # exit with no message if comment is up to date |
71 |
+ if [[ $(egetcomment "${euser}") == ${ecomment} ]]; then |
72 |
+ return 0 |
73 |
+ fi |
74 |
+ |
75 |
+ einfo "Updating comment for user '${euser}' ..." |
76 |
+ einfo " - Comment: ${ecomment}" |
77 |
+ |
78 |
+ # update the comment |
79 |
+ case ${CHOST} in |
80 |
+ *-freebsd*|*-dragonfly*) |
81 |
+ pw usermod "${euser}" -c "${ecomment}" && return 0 |
82 |
+ [[ $? == 8 ]] && eerror "${euser} is in use, cannot update comment" |
83 |
+ eerror "There was an error when attempting to update the comment for ${euser}" |
84 |
+ eerror "Please update it manually on your system:" |
85 |
+ eerror "\t pw usermod \"${euser}\" -c \"${ecomment}\"" |
86 |
+ ;; |
87 |
+ |
88 |
+ *) |
89 |
+ usermod -c "${ecomment}" "${euser}" && return 0 |
90 |
+ [[ $? == 8 ]] && eerror "${euser} is in use, cannot update comment" |
91 |
+ eerror "There was an error when attempting to update the comment for ${euser}" |
92 |
+ eerror "Please update it manually on your system (as root):" |
93 |
+ eerror "\t usermod -c \"${ecomment}\" \"${euser}\"" |
94 |
+ ;; |
95 |
+ esac |
96 |
+} |
97 |
+ |
98 |
fi |
99 |
-- |
100 |
2.22.0.rc3 |