]> gitweb.michael.orlitzky.com - mjo-overlay.git/blobdiff - eclass/sys-user.eclass
sys-user.eclass: add an inline TODO.
[mjo-overlay.git] / eclass / sys-user.eclass
index 6c0c2b81469cca5e989c17f88a1de3b83b5a6548..9042f0699593f81c1478aea8d878adb0efeae5bf 100644 (file)
@@ -9,6 +9,7 @@
 # This eclass does most of the work for the sys-user/ packages that
 # supply system user accounts.
 
+# Needed for egetshell and egethome.
 inherit user
 
 EXPORT_FUNCTIONS pkg_pretend src_unpack src_configure src_compile src_install src_test pkg_preinst pkg_postinst pkg_prerm
@@ -76,6 +77,8 @@ sys-user_src_compile() { :; }
 sys-user_src_test() { :; }
 
 sys-user_getuid() {
+       [[ $# -eq 1 ]] || die "usage: sys-user_getuid <username>"
+
        # Output the real UID of the given user, or the empty string if the
        # user does not exist on the system.
        echo $(id --real --user "${1}")
@@ -102,6 +105,22 @@ sys-user_create() {
 }
 
 
+sys-user_modify() {
+       # Modify the existing user named $SYS_USER_NAME to match the values
+       # contained in the following variables:
+       #
+       #  * SYS_USER_UID
+       #  * SYS_USER_SHELL
+       #  * SYS_USER_HOME
+       #  * SYS_USER_GROUPS
+       #
+       usermod ${SYS_USER_UID:+--uid }"${SYS_USER_UID}" \
+                       ${SYS_USER_GROUPS:+--append --groups }"${SYS_USER_GROUPS}" \
+                       --shell "${SYS_USER_SHELL}" \
+                       --home-dir "${SYS_USER_HOME}" \
+                       "${SYS_USER_NAME}"
+}
+
 sys-user_pkg_pretend() {
        # Sanity checks that would otherwise run code in global scope.
        #
@@ -159,6 +178,9 @@ sys-user_src_configure() {
                fi
        fi
 
+       # TODO: if the requested (unimportant) UID is not available, we
+       # should set SYS_USER_UID to the empty string.
+
        # The "useradd" and "usermod" tools expect a comma-separated list,
        # so change our spaces to commas. Having duplicates in the list is
        # not a problem for those two tools.
@@ -223,8 +245,9 @@ sys-user_pkg_preinst() {
                fi
 
                # The user already exists, so all we have left to do is to try
-               # to append SYS_USER_GROUPS to the existing groups.
-               usermod --append --groups "${SYS_USER_GROUPS}" \
+               # to append SYS_USER_GROUPS to the existing groups. The home
+               # dir, shell, and uid should all match already.
+               sys-user_modify \
                        || die "failed to append groups to existing user ${SYS_USER_NAME}"
        fi
 }