Allow canceling sysinstall(8) and sysupgrade(8) gracefully.

This commit is contained in:
Jonas 'Sortie' Termansen 2016-08-28 19:53:51 +02:00
parent 252c78f010
commit a90d4dbf23
4 changed files with 59 additions and 15 deletions

View File

@ -146,6 +146,15 @@ void prompt(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* question, const char* question,
const char* answer) 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 ) while ( true )
{ {
@ -169,9 +178,11 @@ void prompt(char* buffer,
} }
if ( !strcmp(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); fflush(stdout);
execute((const char*[]) { "sh", NULL }, "f"); execute((const char*[]) { "sh", NULL }, "f");
if ( catch_if_shell )
break;
continue; continue;
} }
if ( !strcmp(buffer, "!man") ) if ( !strcmp(buffer, "!man") )

View File

@ -31,6 +31,11 @@ void prompt(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* question, const char* question,
const char* answer); 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, void password(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* question); const char* question);

View File

@ -774,7 +774,7 @@ int main(void)
text("\n"); text("\n");
textf("We are now ready to install %s %s. Take a moment to verify " 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"); text("\n");
printf(" %-16s system architecture\n", uts.machine); printf(" %-16s system architecture\n", uts.machine);
for ( size_t i = 0; i < mountpoints_used; i++ ) for ( size_t i = 0; i < mountpoints_used; i++ )
@ -798,14 +798,24 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input),
"Install " BRAND_DISTRIBUTION_NAME "? (yes/no)", "yes"); "Install " BRAND_DISTRIBUTION_NAME "? (yes/no/poweroff/reboot)",
if ( strcasecmp(input, "yes") != 0 ) "yes");
if ( !strcasecmp(input, "yes") )
break;
else if ( !strcasecmp(input, "no") )
{ {
text("Everything isn't sane? Answer '!' to get a shell or type ^C " text("Answer '!' to get a shell. Type !man to view the "
"to abort the install.\n"); "installation(7) manual page.\n");
text("Alternatively, you can answer 'poweroff' or 'reboot' to "
"cancel the installation.\n");
continue; continue;
} }
break; else if ( !strcasecmp(input, "poweroff") )
exit(0);
else if ( !strcasecmp(input, "reboot") )
exit(1);
else
continue;
} }
text("\n"); text("\n");

View File

@ -652,7 +652,7 @@ int main(void)
conf.grub && (conf.ports || (conf.system && can_run_old_abi)); 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 " 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"); text("\n");
char abibuf[16]; char abibuf[16];
printf(" %-16s system architecture\n", uts.machine); printf(" %-16s system architecture\n", uts.machine);
@ -692,15 +692,33 @@ int main(void)
printf(" %-16s will not be updated\n", "bootloader"); printf(" %-16s will not be updated\n", "bootloader");
text("\n"); text("\n");
prompt(input, sizeof(input), while ( true )
"Upgrade? (yes/no)", "yes");
if ( strcasecmp(input, "yes") != 0 )
{ {
text("Everything isn't sane? Answer '!' to get a shell or type ^C " promptx(input, sizeof(input),
"to abort the upgrade.\n"); "Upgrade? (yes/no/poweroff/reboot)", "yes", true);
continue; 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"); text("\n");