# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id$
# @ECLASS: sys-user.eclass
# @MAINTAINER:
sys-user_src_compile() { :; }
sys-user_src_test() { :; }
+sys-user_getuid() {
+ # Output the real UID of the given user, or the empty string if the
+ # user does not exist on the system.
+ local username="${1}"
+ echo $(id --real --user "${username}")
+}
+
sys-user_next_uid() {
local euid;
for (( euid = 101; euid <= 999; euid++ )); do
# Finally, ensure that this username doesn't already exist with
# another UID if its UID is supposedly important.
- if [[ -n $(egetent passwd "${SYS_USER_NAME}") ]]; then
- local olduid=$(id --real --user "${SYS_USER_NAME}")
+ local olduid=$(sys-user_getuid "${SYS_USER_NAME}")
+ if [[ -n "${olduid}" ]]; then
if [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]] && \
[[ "${SYS_USER_UID}" != "${olduid}" ]]; then
# The UID is important and specified, but there is already a
}
sys-user_src_configure() {
- if [[ -n $(egetent passwd "${SYS_USER_NAME}") ]]; then
+ local current_uid=$(sys-user_getuid "${SYS_USER_NAME}")
+ if [[ -n "${current_uid}" ]]; then
# UPGRADE PATH: This user already exists, so if the eclass
# consumer doesn't care about some settings, we can reuse the
# pre-existing ones.
# prevents us from incrementing the UID on a reinstall, and doing
# so would break most packages that need a system user to exist.
if [[ "${SYS_USER_UID_IMPORTANT}" != "true" ]]; then
- SYS_USER_UID=$(id --real --user "${SYS_USER_NAME}")
+ SYS_USER_UID="${current_uid}"
fi
if (( "${SYS_USER_HOME}" == -1 )); then
}
sys-user_pkg_preinst() {
- if [[ -z $(egetent passwd "${SYS_USER_NAME}") ]]; then
+ if [[ -z $(sys-user_getuid "${SYS_USER_NAME}") ]]; then
# The user does not already exist. This is the nice and easy
# case because no matter how we got here, we want to go ahead
# and create the (new) user.
local oldshell=$(egetshell "${SYS_USER_NAME}")
if [[ "${oldhome}" != "${SYS_USER_HOME}" ]]; then
- die "home directory conflict for new user ${SYS_USER_HOME}"
+ die "home directory conflict for new user: ${SYS_USER_HOME}"
fi
if [[ "${oldhshell}" != "${SYS_USER_SHELL}" ]]; then
- die "shell conflict for new user ${SYS_USER_HOME}"
+ die "shell conflict for new user: ${SYS_USER_SHELL}"
fi
# The user already exists, so all we have left to do is to try
# that this new version is going to add. At this point, in our
# pkg_postinst(), the old version's pkg_prerm() phase should have
# already happened.
- if [[ -n $(egetent passwd "${SYS_USER_NAME}") ]]; then
+ if [[ -n $(sys-user_getuid "${SYS_USER_NAME}") ]]; then
die "User ${SYS_USER_NAME} already exists during an upgrade."
else
enewuser "${SYS_USER_NAME}" \
}
sys-user_pkg_prerm() {
- if [[ -z $(egetent passwd "${SYS_USER_NAME}") ]]; then
+ if [[ -z $(sys-user_getuid "${SYS_USER_NAME}") ]]; then
# We have successfully done nothing.
ewarn "Tried to remove nonexistent user ${SYS_USER_NAME}."
else