From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH v3 12/19] user.eclass: Support getting & setting comment field
Date: Sun, 9 Jun 2019 13:28:07 +0200 [thread overview]
Message-ID: <20190609112814.15907-13-mgorny@gentoo.org> (raw)
In-Reply-To: <20190609112814.15907-1-mgorny@gentoo.org>
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/user.eclass | 77 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/eclass/user.eclass b/eclass/user.eclass
index ceb805675cf6..f4f6c75f3b71 100644
--- a/eclass/user.eclass
+++ b/eclass/user.eclass
@@ -417,6 +417,27 @@ egetshell() {
egetent passwd "$1" | cut -d: -f${pos}
}
+# @FUNCTION: egetcomment
+# @USAGE: <user>
+# @DESCRIPTION:
+# Gets the comment field for the specified user.
+egetcomment() {
+ local pos
+
+ [[ $# -eq 1 ]] || die "usage: egetshell <user>"
+
+ case ${CHOST} in
+ *-freebsd*|*-dragonfly*)
+ pos=8
+ ;;
+ *) # Linux, NetBSD, OpenBSD, etc...
+ pos=5
+ ;;
+ esac
+
+ egetent passwd "$1" | cut -d: -f${pos}
+}
+
# @FUNCTION: esethome
# @USAGE: <user> <homedir>
# @DESCRIPTION:
@@ -550,4 +571,60 @@ esetshell() {
esac
}
+# @FUNCTION: esetcomment
+# @USAGE: <user> <comment>
+# @DESCRIPTION:
+# Update the comment field in a platform-agnostic way.
+# Required parameters is the username and the new comment.
+esetcomment() {
+ _assert_pkg_ebuild_phase ${FUNCNAME}
+
+ # get the username
+ local euser=$1; shift
+ if [[ -z ${euser} ]] ; then
+ eerror "No username specified !"
+ die "Cannot call esetcomment without a username"
+ fi
+
+ # lets see if the username already exists
+ if [[ -z $(egetent passwd "${euser}") ]] ; then
+ ewarn "User does not exist, cannot set comment -- skipping."
+ return 1
+ fi
+
+ # handle comment
+ local ecomment=$1; shift
+ if [[ -z ${ecomment} ]] ; then
+ eerror "No comment specified !"
+ die "Cannot call esetcomment without a comment"
+ fi
+
+ # exit with no message if comment is up to date
+ if [[ $(egetcomment "${euser}") == ${ecomment} ]]; then
+ return 0
+ fi
+
+ einfo "Updating comment for user '${euser}' ..."
+ einfo " - Comment: ${ecomment}"
+
+ # update the comment
+ case ${CHOST} in
+ *-freebsd*|*-dragonfly*)
+ pw usermod "${euser}" -c "${ecomment}" && return 0
+ [[ $? == 8 ]] && eerror "${euser} is in use, cannot update comment"
+ eerror "There was an error when attempting to update the comment for ${euser}"
+ eerror "Please update it manually on your system:"
+ eerror "\t pw usermod \"${euser}\" -c \"${ecomment}\""
+ ;;
+
+ *)
+ usermod -c "${ecomment}" "${euser}" && return 0
+ [[ $? == 8 ]] && eerror "${euser} is in use, cannot update comment"
+ eerror "There was an error when attempting to update the comment for ${euser}"
+ eerror "Please update it manually on your system (as root):"
+ eerror "\t usermod -c \"${ecomment}\" \"${euser}\""
+ ;;
+ esac
+}
+
fi
--
2.22.0.rc3
next prev parent reply other threads:[~2019-06-09 11:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-09 11:27 [gentoo-dev] [PATCH v3 00/19] User/group packages Michał Górny
2019-06-09 11:27 ` [gentoo-dev] [PATCH v3 01/19] user.eclass: Remove dead/broken Darwin support Michał Górny
2019-06-09 11:27 ` [gentoo-dev] [PATCH v3 02/19] user.eclass: NetBSD has 'getent' Michał Górny
2019-06-09 11:27 ` [gentoo-dev] [PATCH v3 03/19] user.eclass: Do not create user-group automatically Michał Górny
2019-06-09 11:27 ` [gentoo-dev] [PATCH v3 04/19] user.eclass: Prevent automated home creation in useradd Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 05/19] user.eclass: Support disabling home directory creation Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 06/19] user.eclass: Support forcing specified UID/GID Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 07/19] user.eclass: Die if no free UID/GID is found Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 08/19] user.eclass: Factor out finding nologin into separate function Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 09/19] user.eclass: Introduce esetshell Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 10/19] user.eclass: Introduce eget{user,group}name Michał Górny
2019-06-09 16:18 ` Michael Orlitzky
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 11/19] user.eclass: Also permit using functions in pkg_*rm phases Michał Górny
2019-06-09 16:12 ` Michael Orlitzky
2019-06-09 11:28 ` Michał Górny [this message]
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 13/19] user.eclass: Introduce e{get,set}groups Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 14/19] acct-group.eclass: A new eclass to maintain group accounts Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 15/19] acct-user.eclass: A new eclass to maintain user accounts Michał Górny
2019-06-09 11:35 ` Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 16/19] acct-user.eclass: Supporting locking & unlocking accounts Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 17/19] acct-group/ftp: Add 'ftp' group (GID 21) Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 18/19] acct-user/ftp: Add 'ftp' user (UID 21) Michał Górny
2019-06-09 11:28 ` [gentoo-dev] [PATCH v3 19/19] net-ftp/ftpbase: Utilize {group,user}/ftp Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190609112814.15907-13-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox