From 6b0ddb461569ecc7df0579fc7acd6823953bd353 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 20 Aug 2017 12:13:04 +0200 Subject: [PATCH] Add keys to sysinstall and sysupgrade prompts. --- sysinstall/interactive.c | 5 ++++- sysinstall/interactive.h | 2 ++ sysinstall/sysinstall.c | 31 +++++++++++++++++-------------- sysinstall/sysupgrade.c | 29 ++++++++++++++++------------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/sysinstall/interactive.c b/sysinstall/interactive.c index 008cd94c..20703476 100644 --- a/sysinstall/interactive.c +++ b/sysinstall/interactive.c @@ -144,18 +144,21 @@ void textf(const char* format, ...) void prompt(char* buffer, size_t buffer_size, + const char* autoconf_name, const char* question, const char* answer) { - promptx(buffer, buffer_size, question, answer, false); + promptx(buffer, buffer_size, autoconf_name, question, answer, false); } void promptx(char* buffer, size_t buffer_size, + const char* autoconf_name, const char* question, const char* answer, bool catch_if_shell) { + (void) autoconf_name; while ( true ) { printf("\e[1m"); diff --git a/sysinstall/interactive.h b/sysinstall/interactive.h index 7f69936a..0971bed6 100644 --- a/sysinstall/interactive.h +++ b/sysinstall/interactive.h @@ -29,10 +29,12 @@ __attribute__((format(printf, 1, 2))) void textf(const char* format, ...); void prompt(char* buffer, size_t buffer_size, + const char* autoconf_name, const char* question, const char* answer); void promptx(char* buffer, size_t buffer_size, + const char* autoconf_name, const char* question, const char* answer, bool catch_if_shell); diff --git a/sysinstall/sysinstall.c b/sysinstall/sysinstall.c index 9a081927..f35589fb 100644 --- a/sysinstall/sysinstall.c +++ b/sysinstall/sysinstall.c @@ -424,7 +424,8 @@ int main(void) "software installed to properly install this operating system.\n"); while ( true ) { - prompt(input, sizeof(input), "Sure you want to proceed?", "no"); + prompt(input, sizeof(input), "ignore_missing_programs", + "Sure you want to proceed?", "no"); if ( strcasecmp(input, "no") == 0 ) return 0; if ( strcasecmp(input, "yes") == 0 ) @@ -453,7 +454,7 @@ int main(void) }; size_t num_readies = sizeof(readies) / sizeof(readies[0]); const char* ready = readies[arc4random_uniform(num_readies)]; - prompt(input, sizeof(input), "Ready?", ready); + prompt(input, sizeof(input), "ready", "Ready?", ready); text("\n"); text("This is not yet a fully fledged operating system. You should adjust " @@ -475,7 +476,7 @@ int main(void) while ( kblayout_setable ) { // TODO: Detect the name of the current keyboard layout. - prompt(input, sizeof(input), + prompt(input, sizeof(input), "kblayout", "Choose your keyboard layout ('?' or 'L' for list)", "default"); if ( !strcmp(input, "?") || !strcmp(input, "l") || @@ -561,7 +562,7 @@ int main(void) const char* def = good ? "no" : "yes"; while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "videomode", "Select a default display resolution? (yes/no)", def); if ( strcasecmp(input, "no") && strcasecmp(input, "yes") ) continue; @@ -617,7 +618,7 @@ int main(void) while ( true ) { const char* def = bootloader_default ? "yes" : "no"; - prompt(accept_grub, sizeof(accept_grub), + prompt(accept_grub, sizeof(accept_grub), "grub", "Install a new GRUB bootloader?", def); if ( strcasecmp(accept_grub, "no") == 0 || strcasecmp(accept_grub, "yes") == 0 ) @@ -639,6 +640,7 @@ int main(void) while ( true ) { prompt(accept_grub_password, sizeof(accept_grub_password), + "grub_password", "Password protect interactive bootloader? (yes/no)", "yes"); if ( strcasecmp(accept_grub_password, "no") == 0 || strcasecmp(accept_grub_password, "yes") == 0 ) @@ -661,8 +663,8 @@ int main(void) if ( !strcmp(first, "") ) { char answer[32]; - prompt(answer, sizeof(answer), - "Empty password is stupid, are you sure? (yes/no)", "no"); + prompt(answer, sizeof(answer), "grub_password_empty", + "Empty password is stupid, are you sure? (yes/no)", "no"); if ( strcasecmp(answer, "yes") != 0 ) continue; } @@ -790,6 +792,7 @@ int main(void) while ( true ) { prompt(return_to_disked, sizeof(return_to_disked), + "missing_bios_boot_partition", "Return to disked to make a BIOS boot partition?", "yes"); if ( strcasecmp(accept_grub, "no") == 0 || strcasecmp(accept_grub, "yes") == 0 ) @@ -827,7 +830,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "confirm_install", "Install " BRAND_DISTRIBUTION_NAME "? " "(yes/no/poweroff/reboot/halt)", "yes"); if ( !strcasecmp(input, "yes") ) @@ -961,7 +964,7 @@ int main(void) fclose(defhost_fp); } char hostname[HOST_NAME_MAX + 1] = ""; - prompt(hostname, sizeof(hostname), "System hostname?", + prompt(hostname, sizeof(hostname), "hostname", "System hostname?", defhost[0] ? defhost : NULL); if ( !install_configurationf("etc/hostname", "w", "%s\n", hostname) ) continue; @@ -1000,7 +1003,7 @@ int main(void) if ( !strcmp(first, "") ) { char answer[32]; - prompt(answer, sizeof(answer), + prompt(answer, sizeof(answer), "empty_password", "Empty password is stupid, are you sure? (yes/no)", "no"); if ( strcasecmp(answer, "yes") != 0 ) continue; @@ -1051,7 +1054,7 @@ int main(void) const char* question = "Setup a user? (enter username or 'no')"; if ( made_user ) question = "Setup another user? (enter username or 'no')"; - prompt(userstr, sizeof(userstr), question, "no"); + prompt(userstr, sizeof(userstr), NULL, question, "no"); if ( !strcmp(userstr, "no") ) break; if ( !strcmp(userstr, "yes") ) @@ -1065,7 +1068,7 @@ int main(void) continue; } static char name[256]; - prompt(name, sizeof(name), "Full name of user?", user); + prompt(name, sizeof(name), NULL, "Full name of user?", user); char first[128]; char second[128]; while ( true ) @@ -1081,7 +1084,7 @@ int main(void) if ( !strcmp(first, "") ) { char answer[32]; - prompt(answer, sizeof(answer), + prompt(answer, sizeof(answer), "empty_password", "Empty password is stupid, are you sure? (yes/no)", "no"); if ( strcasecmp(answer, "yes") != 0 ) continue; @@ -1144,7 +1147,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "finally", "What now? (poweroff/reboot/halt/boot)", "boot"); if ( !strcasecmp(input, "poweroff") ) exit(0); diff --git a/sysinstall/sysupgrade.c b/sysinstall/sysupgrade.c index fbadb17a..180b1cbb 100644 --- a/sysinstall/sysupgrade.c +++ b/sysinstall/sysupgrade.c @@ -370,7 +370,8 @@ int main(void) "software installed to properly upgrade installations.\n"); while ( true ) { - prompt(input, sizeof(input), "Sure you want to proceed?", "no"); + prompt(input, sizeof(input), "ignore_missing_programs", + "Sure you want to proceed?", "no"); if ( strcasecmp(input, "no") == 0 ) return 0; if ( strcasecmp(input, "yes") == 0 ) @@ -400,14 +401,14 @@ int main(void) }; size_t num_readies = sizeof(readies) / sizeof(readies[0]); const char* ready = readies[arc4random_uniform(num_readies)]; - prompt(input, sizeof(input), "Ready?", ready); + prompt(input, sizeof(input), "ready", "Ready?", ready); text("\n"); bool kblayout_setable = 0 <= tcgetblob(0, "kblayout", NULL, 0); while ( kblayout_setable ) { // TODO: Detect the name of the current keyboard layout. - prompt(input, sizeof(input), + prompt(input, sizeof(input), "kblayout", "Choose your keyboard layout ('?' or 'L' for list)", "default"); if ( !strcmp(input, "?") || !strcmp(input, "l") || @@ -481,7 +482,7 @@ int main(void) const char* def = good ? "no" : "yes"; while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "videomode", "Select display resolution? (yes/no)", def); if ( strcasecmp(input, "no") && strcasecmp(input, "yes") ) continue; @@ -521,7 +522,8 @@ int main(void) { while ( true ) { - prompt(input, sizeof(input), "No existing installations found, " + prompt(input, sizeof(input), "run_installer_instead", + "No existing installations found, " "run installer instead? (yes/no)", "yes"); if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) break; @@ -551,7 +553,8 @@ int main(void) const char* def = NULL; if ( installations_count == 1 ) def = path_of_blockdevice(installations[0].bdev); - prompt(input, sizeof(input), "Which installation to upgrade?", def); + prompt(input, sizeof(input), "which_installaton", + "Which installation to upgrade?", def); target = NULL; for ( size_t i = 0; i < installations_count; i++ ) { @@ -585,7 +588,7 @@ int main(void) "promise this will work!\n", target->machine, source_machine); while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "switch_architecture", "Change the existing installation to another architecture?", "no"); if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) @@ -605,7 +608,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "downgrade_release", "Downgrade to an earlier release?", "no"); if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) break; @@ -622,7 +625,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "skip_release", "Skip across releases?", "no"); if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) break; @@ -641,7 +644,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "downgrade_abi", "Downgrade to an earlier ABI?", "no"); if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) break; @@ -707,7 +710,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "cancel_pending_sysmerge", "Cancel pending sysmerge upgrade?", "yes"); if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) break; @@ -774,7 +777,7 @@ int main(void) while ( true ) { - promptx(input, sizeof(input), + promptx(input, sizeof(input), "confirm_upgrade", "Upgrade? (yes/no/poweroff/reboot/halt)", "yes", true); if ( !strcasecmp(input, "yes") ) break; @@ -930,7 +933,7 @@ int main(void) while ( true ) { - prompt(input, sizeof(input), + prompt(input, sizeof(input), "finally", "What now? (poweroff/reboot/halt)", "reboot"); if ( !strcasecmp(input, "poweroff") ) return 0;