]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
home: Prompt for shell in homectl firstboot
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 17 Sep 2024 21:01:13 +0000 (23:01 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 2 Oct 2024 13:08:35 +0000 (15:08 +0200)
src/home/homectl.c

index a2678c8140619709e30ceb8876b8b81d9070888d..d1883f7421adf37ea2a56566dc9d7fa62726097a 100644 (file)
@@ -2608,6 +2608,45 @@ static int create_interactively(void) {
                         return log_error_errno(r, "Failed to set memberOf field: %m");
         }
 
+        _cleanup_free_ char *shell = NULL;
+
+        for (;;) {
+                shell = mfree(shell);
+
+                r = ask_string(&shell,
+                               "%s Please enter the shell to use for user %s (empty to skip): ",
+                               special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), username);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to query user for username: %m");
+
+                if (isempty(shell)) {
+                        log_info("No data entered, skipping.");
+                        break;
+                }
+
+                if (!valid_shell(shell)) {
+                        log_notice("Specified shell is not a valid UNIX shell path, try again: %s", shell);
+                        continue;
+                }
+
+                r = RET_NERRNO(access(shell, X_OK));
+                if (r >= 0)
+                        break;
+
+                if (r != -ENOENT)
+                        return log_error_errno(r, "Failed to check if shell %s exists: %m", shell);
+
+                log_notice("Specified shell '%s' is not installed, try another one.", shell);
+        }
+
+        if (shell) {
+                log_info("Selected %s as the shell for user %s", shell, username);
+
+                r = sd_json_variant_set_field_string(&arg_identity_extra, "shell", shell);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to set shell field: %m");
+        }
+
         return create_home_common(/* input= */ NULL);
 }