From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A75D9138334 for ; Thu, 20 Jun 2019 08:17:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A54F7E0A99; Thu, 20 Jun 2019 08:17:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 78C55E0A99 for ; Thu, 20 Jun 2019 08:17:18 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1C6EF346563 for ; Thu, 20 Jun 2019 08:17:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8272462A for ; Thu, 20 Jun 2019 08:17:13 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1561018608.a171a801ebaeb0020bfa183b7da1f202ea45ae5f.mgorny@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/user.eclass X-VCS-Directories: eclass/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: a171a801ebaeb0020bfa183b7da1f202ea45ae5f X-VCS-Branch: master Date: Thu, 20 Jun 2019 08:17:13 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 5fc0716d-51b2-4c3e-9108-d7e81d58ce53 X-Archives-Hash: 5cdcaa4400ae657cb84d162fdbf7760e commit: a171a801ebaeb0020bfa183b7da1f202ea45ae5f Author: Michał Górny gentoo org> AuthorDate: Sun Jun 9 06:19:48 2019 +0000 Commit: Michał Górny gentoo org> CommitDate: Thu Jun 20 08:16:48 2019 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a171a801 user.eclass: Support getting & setting comment field Signed-off-by: Michał Górny gentoo.org> eclass/user.eclass | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/eclass/user.eclass b/eclass/user.eclass index fc883c96535..0e7aa43d893 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -413,6 +413,27 @@ egetshell() { egetent passwd "$1" | cut -d: -f${pos} } +# @FUNCTION: egetcomment +# @USAGE: +# @DESCRIPTION: +# Gets the comment field for the specified user. +egetcomment() { + local pos + + [[ $# -eq 1 ]] || die "usage: egetshell " + + case ${CHOST} in + *-freebsd*|*-dragonfly*) + pos=8 + ;; + *) # Linux, NetBSD, OpenBSD, etc... + pos=5 + ;; + esac + + egetent passwd "$1" | cut -d: -f${pos} +} + # @FUNCTION: esethome # @USAGE: # @DESCRIPTION: @@ -546,4 +567,60 @@ esetshell() { esac } +# @FUNCTION: esetcomment +# @USAGE: +# @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