From bdd7cd264a0afd883260751c64789f4f37dd5ead Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Jul 2019 13:43:31 +0200 Subject: [PATCH 1/2] firstboot: suppress locale menu if there's nothing to choose from --- src/firstboot/firstboot.c | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index e0c834cfc3..b60ef572cf 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -219,25 +219,46 @@ static int prompt_locale(void) { if (r < 0) return log_error_errno(r, "Cannot query locales list: %m"); - print_welcome(); + if (strv_isempty(locales)) + log_debug("No locales found, skipping locale selection."); + else if (strv_length(locales) == 1) { - printf("\nAvailable Locales:\n\n"); - r = show_menu(locales, 3, 22, 60); - if (r < 0) - return r; + if (streq(locales[0], SYSTEMD_DEFAULT_LOCALE)) + log_debug("Only installed locale is default locale anyway, not setting locale explicitly."); + else { + log_debug("Only a single locale available (%s), selecting it as default.", locales[0]); - putchar('\n'); + arg_locale = strdup(locales[0]); + if (!arg_locale) + return log_oom(); - r = prompt_loop("Please enter system locale name or number", locales, locale_is_valid, &arg_locale); - if (r < 0) - return r; + /* Not setting arg_locale_message here, since it defaults to LANG anyway */ + } + } else { + print_welcome(); - if (isempty(arg_locale)) - return 0; + printf("\nAvailable Locales:\n\n"); + r = show_menu(locales, 3, 22, 60); + if (r < 0) + return r; - r = prompt_loop("Please enter system message locale name or number", locales, locale_is_valid, &arg_locale_messages); - if (r < 0) - return r; + putchar('\n'); + + r = prompt_loop("Please enter system locale name or number", locales, locale_is_valid, &arg_locale); + if (r < 0) + return r; + + if (isempty(arg_locale)) + return 0; + + r = prompt_loop("Please enter system message locale name or number", locales, locale_is_valid, &arg_locale_messages); + if (r < 0) + return r; + + /* Suppress the messages setting if it's the same as the main locale anyway */ + if (streq_ptr(arg_locale, arg_locale_messages)) + arg_locale_messages = mfree(arg_locale_messages); + } return 0; } From 4aeadec7e66f59e7a7846a5e91de045564dba23b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Jul 2019 13:52:01 +0200 Subject: [PATCH 2/2] firstboot: use color in welcome text --- src/firstboot/firstboot.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index b60ef572cf..74b83f348b 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -87,20 +87,31 @@ static bool press_any_key(void) { } static void print_welcome(void) { - _cleanup_free_ char *pretty_name = NULL; + _cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL; static bool done = false; + const char *pn; int r; if (done) return; - r = parse_os_release(arg_root, "PRETTY_NAME", &pretty_name, NULL); + r = parse_os_release( + arg_root, + "PRETTY_NAME", &pretty_name, + "ANSI_COLOR", &ansi_color, + NULL); if (r < 0) log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r, "Failed to read os-release file, ignoring: %m"); - printf("\nWelcome to your new installation of %s!\nPlease configure a few basic system settings:\n\n", - isempty(pretty_name) ? "Linux" : pretty_name); + pn = isempty(pretty_name) ? "Linux" : pretty_name; + + if (colors_enabled()) + printf("\nWelcome to your new installation of \x1B[%sm%s\x1B[0m!\n", ansi_color, pn); + else + printf("\nWelcome to your new installation of %s!\n", pn); + + printf("\nPlease configure your system!\n\n"); press_any_key();