diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-09-17 23:01:13 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-10-02 15:08:35 +0200 |
commit | 84edd52121ff9573d4da42ebbf85f73e07418a60 (patch) | |
tree | 62f3b7d148b55f396bf677528a6436888f3b69cc /src | |
parent | home: Prompt for auxiliary groups in homectl firstboot (diff) | |
download | systemd-84edd52121ff9573d4da42ebbf85f73e07418a60.tar.xz systemd-84edd52121ff9573d4da42ebbf85f73e07418a60.zip |
home: Prompt for shell in homectl firstboot
Diffstat (limited to 'src')
-rw-r--r-- | src/home/homectl.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/home/homectl.c b/src/home/homectl.c index a2678c8140..d1883f7421 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -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); } |