From a90d4dbf23657ee145d33d9b0143c7b0308d8aaa Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 28 Aug 2016 19:53:51 +0200 Subject: [PATCH] Allow canceling sysinstall(8) and sysupgrade(8) gracefully. --- sysinstall/interactive.c | 13 ++++++++++++- sysinstall/interactive.h | 5 +++++ sysinstall/sysinstall.c | 22 ++++++++++++++++------ sysinstall/sysupgrade.c | 34 ++++++++++++++++++++++++++-------- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/sysinstall/interactive.c b/sysinstall/interactive.c index 82187b5f..8e02b7ca 100644 --- a/sysinstall/interactive.c +++ b/sysinstall/interactive.c @@ -146,6 +146,15 @@ void prompt(char* buffer, size_t buffer_size, const char* question, const char* answer) +{ + promptx(buffer, buffer_size, question, answer, false); +} + +void promptx(char* buffer, + size_t buffer_size, + const char* question, + const char* answer, + bool catch_if_shell) { while ( true ) { @@ -169,9 +178,11 @@ void prompt(char* buffer, } if ( !strcmp(buffer, "!") ) { - printf("Type 'exit' to return to install.\n"); + printf("Type 'exit' to return to the %s.\n", prompt_man_page); fflush(stdout); execute((const char*[]) { "sh", NULL }, "f"); + if ( catch_if_shell ) + break; continue; } if ( !strcmp(buffer, "!man") ) diff --git a/sysinstall/interactive.h b/sysinstall/interactive.h index 6069fe2a..7f69936a 100644 --- a/sysinstall/interactive.h +++ b/sysinstall/interactive.h @@ -31,6 +31,11 @@ void prompt(char* buffer, size_t buffer_size, const char* question, const char* answer); +void promptx(char* buffer, + size_t buffer_size, + const char* question, + const char* answer, + bool catch_if_shell); void password(char* buffer, size_t buffer_size, const char* question); diff --git a/sysinstall/sysinstall.c b/sysinstall/sysinstall.c index 6f9cc247..ae5acf74 100644 --- a/sysinstall/sysinstall.c +++ b/sysinstall/sysinstall.c @@ -774,7 +774,7 @@ int main(void) text("\n"); textf("We are now ready to install %s %s. Take a moment to verify " - "everything is sane.\n", BRAND_DISTRIBUTION_NAME, VERSIONSTR); + "everything is in order.\n", BRAND_DISTRIBUTION_NAME, VERSIONSTR); text("\n"); printf(" %-16s system architecture\n", uts.machine); for ( size_t i = 0; i < mountpoints_used; i++ ) @@ -798,14 +798,24 @@ int main(void) while ( true ) { prompt(input, sizeof(input), - "Install " BRAND_DISTRIBUTION_NAME "? (yes/no)", "yes"); - if ( strcasecmp(input, "yes") != 0 ) + "Install " BRAND_DISTRIBUTION_NAME "? (yes/no/poweroff/reboot)", + "yes"); + if ( !strcasecmp(input, "yes") ) + break; + else if ( !strcasecmp(input, "no") ) { - text("Everything isn't sane? Answer '!' to get a shell or type ^C " - "to abort the install.\n"); + text("Answer '!' to get a shell. Type !man to view the " + "installation(7) manual page.\n"); + text("Alternatively, you can answer 'poweroff' or 'reboot' to " + "cancel the installation.\n"); continue; } - break; + else if ( !strcasecmp(input, "poweroff") ) + exit(0); + else if ( !strcasecmp(input, "reboot") ) + exit(1); + else + continue; } text("\n"); diff --git a/sysinstall/sysupgrade.c b/sysinstall/sysupgrade.c index c591b33a..252df712 100644 --- a/sysinstall/sysupgrade.c +++ b/sysinstall/sysupgrade.c @@ -652,7 +652,7 @@ int main(void) conf.grub && (conf.ports || (conf.system && can_run_old_abi)); textf("We are now ready to upgrade to %s %s. Take a moment to verify " - "everything is sane.\n", BRAND_DISTRIBUTION_NAME, VERSIONSTR); + "everything is in order.\n", BRAND_DISTRIBUTION_NAME, VERSIONSTR); text("\n"); char abibuf[16]; printf(" %-16s system architecture\n", uts.machine); @@ -692,15 +692,33 @@ int main(void) printf(" %-16s will not be updated\n", "bootloader"); text("\n"); - prompt(input, sizeof(input), - "Upgrade? (yes/no)", "yes"); - if ( strcasecmp(input, "yes") != 0 ) + while ( true ) { - text("Everything isn't sane? Answer '!' to get a shell or type ^C " - "to abort the upgrade.\n"); - continue; + promptx(input, sizeof(input), + "Upgrade? (yes/no/poweroff/reboot)", "yes", true); + if ( !strcasecmp(input, "yes") ) + break; + else if ( !strcasecmp(input, "no") ) + { + text("Answer '!' to get a shell. Type !man to view the " + "upgrade(7) manual page. You can edit the upgrade.conf(5) " + "configuration file of the target system to change which " + "upgrade operations are performed.\n"); + text("Alternatively, you can answer 'poweroff' or 'reboot' to " + "cancel the upgrade.\n"); + continue; + } + else if ( !strcasecmp(input, "poweroff") ) + exit(0); + else if ( !strcasecmp(input, "reboot") ) + exit(1); + else if ( !strcasecmp(input, "!") ) + break; + else + continue; } - break; + if ( !strcasecmp(input, "yes") ) + break; } text("\n");