]> gitweb.michael.orlitzky.com - mjo-overlay.git/blobdiff - eclass/sys-user.eclass
sys-user.eclass: add a sys-user_getuid() function and use it two places.
[mjo-overlay.git] / eclass / sys-user.eclass
index 549e8b38aae57040f8caf6ff2f8cf977d77d3a05..95417c79a8516ec4f53031cfe6c442d43e3eb77f 100644 (file)
@@ -1,6 +1,5 @@
 # Copyright 1999-2017 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Id$
 
 # @ECLASS: sys-user.eclass
 # @MAINTAINER:
@@ -74,6 +73,13 @@ sys-user_src_unpack() { :; }
 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
@@ -110,7 +116,7 @@ sys-user_pkg_pretend() {
        # 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 [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]] && \
                           [[ "${SYS_USER_UID}" != "${olduid}" ]]; then
                        # The UID is important and specified, but there is already a
@@ -130,7 +136,7 @@ sys-user_src_configure() {
                # 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=$(sys-user_getuid "${SYS_USER_NAME}")
                fi
 
                if (( "${SYS_USER_HOME}" == -1 )); then
@@ -208,11 +214,11 @@ sys-user_pkg_preinst() {
                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