sys-user.eclass: refactor (and fix) the pkg_pretend checks.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 29 Aug 2017 18:35:26 +0000 (14:35 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 29 Aug 2017 18:35:26 +0000 (14:35 -0400)
eclass/sys-user.eclass

index e14cdfb733ec1a5947f8f681f1ef341b449c917d..6fb8f7ab17c96e289d5762ab109c0b5eb0c0c287 100644 (file)
@@ -132,22 +132,20 @@ sys-user_modify() {
 
 sys-user_pkg_pretend() {
        # Sanity checks that would otherwise run code in global scope.
-
-       # Next ensure that no other username owns an important UID.
        if [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]]; then
-               # Ok, the UID is important. Make sure nobody else has it. Or
+
+               # The UID is important, so make sure nobody else has it. Or
                # rather, nobody else *with a different username* has it.
                local oldname=$(sys-user_getname "${SYS_USER_UID}")
-               if [[ "${SYS_USER_NAME}" != "${oldname}" ]]; then
+               if [[ -n "${oldname}" ]] && \
+                          [[ "${SYS_USER_NAME}" != "${oldname}" ]]; then
                        die "important UID ${SYS_USER_UID} already belongs to ${oldname}"
                fi
-       fi
 
-       # Finally, ensure that this username doesn't already exist with
-       # another UID if its UID is supposedly important.
-       local olduid=$(sys-user_getuid "${SYS_USER_NAME}")
-       if [[ -n "${olduid}" ]]; then
-               if [[ "${SYS_USER_UID_IMPORTANT}" == "true" ]] && \
+               # Ensure that this username doesn't already exist with another
+               # UID if its UID is supposedly important.
+               local olduid=$(sys-user_getuid "${SYS_USER_NAME}")
+               if [[ -n "${olduid}" ]] && \
                           [[ "${SYS_USER_UID}" != "${olduid}" ]]; then
                        # The UID is important and specified, but there is already a
                        # system user with this name and a different UID. Halp.