Add keys to sysinstall and sysupgrade prompts.

This commit is contained in:
Jonas 'Sortie' Termansen 2017-08-20 12:13:04 +02:00
parent bfc852be08
commit 6b0ddb4615
4 changed files with 39 additions and 28 deletions

View File

@ -144,18 +144,21 @@ void textf(const char* format, ...)
void prompt(char* buffer, void prompt(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* autoconf_name,
const char* question, const char* question,
const char* answer) const char* answer)
{ {
promptx(buffer, buffer_size, question, answer, false); promptx(buffer, buffer_size, autoconf_name, question, answer, false);
} }
void promptx(char* buffer, void promptx(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* autoconf_name,
const char* question, const char* question,
const char* answer, const char* answer,
bool catch_if_shell) bool catch_if_shell)
{ {
(void) autoconf_name;
while ( true ) while ( true )
{ {
printf("\e[1m"); printf("\e[1m");

View File

@ -29,10 +29,12 @@ __attribute__((format(printf, 1, 2)))
void textf(const char* format, ...); void textf(const char* format, ...);
void prompt(char* buffer, void prompt(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* autoconf_name,
const char* question, const char* question,
const char* answer); const char* answer);
void promptx(char* buffer, void promptx(char* buffer,
size_t buffer_size, size_t buffer_size,
const char* autoconf_name,
const char* question, const char* question,
const char* answer, const char* answer,
bool catch_if_shell); bool catch_if_shell);

View File

@ -424,7 +424,8 @@ int main(void)
"software installed to properly install this operating system.\n"); "software installed to properly install this operating system.\n");
while ( true ) 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 ) if ( strcasecmp(input, "no") == 0 )
return 0; return 0;
if ( strcasecmp(input, "yes") == 0 ) if ( strcasecmp(input, "yes") == 0 )
@ -453,7 +454,7 @@ int main(void)
}; };
size_t num_readies = sizeof(readies) / sizeof(readies[0]); size_t num_readies = sizeof(readies) / sizeof(readies[0]);
const char* ready = readies[arc4random_uniform(num_readies)]; const char* ready = readies[arc4random_uniform(num_readies)];
prompt(input, sizeof(input), "Ready?", ready); prompt(input, sizeof(input), "ready", "Ready?", ready);
text("\n"); text("\n");
text("This is not yet a fully fledged operating system. You should adjust " text("This is not yet a fully fledged operating system. You should adjust "
@ -475,7 +476,7 @@ int main(void)
while ( kblayout_setable ) while ( kblayout_setable )
{ {
// TODO: Detect the name of the current keyboard layout. // 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"); "Choose your keyboard layout ('?' or 'L' for list)", "default");
if ( !strcmp(input, "?") || if ( !strcmp(input, "?") ||
!strcmp(input, "l") || !strcmp(input, "l") ||
@ -561,7 +562,7 @@ int main(void)
const char* def = good ? "no" : "yes"; const char* def = good ? "no" : "yes";
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "videomode",
"Select a default display resolution? (yes/no)", def); "Select a default display resolution? (yes/no)", def);
if ( strcasecmp(input, "no") && strcasecmp(input, "yes") ) if ( strcasecmp(input, "no") && strcasecmp(input, "yes") )
continue; continue;
@ -617,7 +618,7 @@ int main(void)
while ( true ) while ( true )
{ {
const char* def = bootloader_default ? "yes" : "no"; 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); "Install a new GRUB bootloader?", def);
if ( strcasecmp(accept_grub, "no") == 0 || if ( strcasecmp(accept_grub, "no") == 0 ||
strcasecmp(accept_grub, "yes") == 0 ) strcasecmp(accept_grub, "yes") == 0 )
@ -639,6 +640,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(accept_grub_password, sizeof(accept_grub_password), prompt(accept_grub_password, sizeof(accept_grub_password),
"grub_password",
"Password protect interactive bootloader? (yes/no)", "yes"); "Password protect interactive bootloader? (yes/no)", "yes");
if ( strcasecmp(accept_grub_password, "no") == 0 || if ( strcasecmp(accept_grub_password, "no") == 0 ||
strcasecmp(accept_grub_password, "yes") == 0 ) strcasecmp(accept_grub_password, "yes") == 0 )
@ -661,8 +663,8 @@ int main(void)
if ( !strcmp(first, "") ) if ( !strcmp(first, "") )
{ {
char answer[32]; char answer[32];
prompt(answer, sizeof(answer), prompt(answer, sizeof(answer), "grub_password_empty",
"Empty password is stupid, are you sure? (yes/no)", "no"); "Empty password is stupid, are you sure? (yes/no)", "no");
if ( strcasecmp(answer, "yes") != 0 ) if ( strcasecmp(answer, "yes") != 0 )
continue; continue;
} }
@ -790,6 +792,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(return_to_disked, sizeof(return_to_disked), prompt(return_to_disked, sizeof(return_to_disked),
"missing_bios_boot_partition",
"Return to disked to make a BIOS boot partition?", "yes"); "Return to disked to make a BIOS boot partition?", "yes");
if ( strcasecmp(accept_grub, "no") == 0 || if ( strcasecmp(accept_grub, "no") == 0 ||
strcasecmp(accept_grub, "yes") == 0 ) strcasecmp(accept_grub, "yes") == 0 )
@ -827,7 +830,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "confirm_install",
"Install " BRAND_DISTRIBUTION_NAME "? " "Install " BRAND_DISTRIBUTION_NAME "? "
"(yes/no/poweroff/reboot/halt)", "yes"); "(yes/no/poweroff/reboot/halt)", "yes");
if ( !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "yes") )
@ -961,7 +964,7 @@ int main(void)
fclose(defhost_fp); fclose(defhost_fp);
} }
char hostname[HOST_NAME_MAX + 1] = ""; char hostname[HOST_NAME_MAX + 1] = "";
prompt(hostname, sizeof(hostname), "System hostname?", prompt(hostname, sizeof(hostname), "hostname", "System hostname?",
defhost[0] ? defhost : NULL); defhost[0] ? defhost : NULL);
if ( !install_configurationf("etc/hostname", "w", "%s\n", hostname) ) if ( !install_configurationf("etc/hostname", "w", "%s\n", hostname) )
continue; continue;
@ -1000,7 +1003,7 @@ int main(void)
if ( !strcmp(first, "") ) if ( !strcmp(first, "") )
{ {
char answer[32]; char answer[32];
prompt(answer, sizeof(answer), prompt(answer, sizeof(answer), "empty_password",
"Empty password is stupid, are you sure? (yes/no)", "no"); "Empty password is stupid, are you sure? (yes/no)", "no");
if ( strcasecmp(answer, "yes") != 0 ) if ( strcasecmp(answer, "yes") != 0 )
continue; continue;
@ -1051,7 +1054,7 @@ int main(void)
const char* question = "Setup a user? (enter username or 'no')"; const char* question = "Setup a user? (enter username or 'no')";
if ( made_user ) if ( made_user )
question = "Setup another user? (enter username or 'no')"; 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") ) if ( !strcmp(userstr, "no") )
break; break;
if ( !strcmp(userstr, "yes") ) if ( !strcmp(userstr, "yes") )
@ -1065,7 +1068,7 @@ int main(void)
continue; continue;
} }
static char name[256]; 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 first[128];
char second[128]; char second[128];
while ( true ) while ( true )
@ -1081,7 +1084,7 @@ int main(void)
if ( !strcmp(first, "") ) if ( !strcmp(first, "") )
{ {
char answer[32]; char answer[32];
prompt(answer, sizeof(answer), prompt(answer, sizeof(answer), "empty_password",
"Empty password is stupid, are you sure? (yes/no)", "no"); "Empty password is stupid, are you sure? (yes/no)", "no");
if ( strcasecmp(answer, "yes") != 0 ) if ( strcasecmp(answer, "yes") != 0 )
continue; continue;
@ -1144,7 +1147,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "finally",
"What now? (poweroff/reboot/halt/boot)", "boot"); "What now? (poweroff/reboot/halt/boot)", "boot");
if ( !strcasecmp(input, "poweroff") ) if ( !strcasecmp(input, "poweroff") )
exit(0); exit(0);

View File

@ -370,7 +370,8 @@ int main(void)
"software installed to properly upgrade installations.\n"); "software installed to properly upgrade installations.\n");
while ( true ) 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 ) if ( strcasecmp(input, "no") == 0 )
return 0; return 0;
if ( strcasecmp(input, "yes") == 0 ) if ( strcasecmp(input, "yes") == 0 )
@ -400,14 +401,14 @@ int main(void)
}; };
size_t num_readies = sizeof(readies) / sizeof(readies[0]); size_t num_readies = sizeof(readies) / sizeof(readies[0]);
const char* ready = readies[arc4random_uniform(num_readies)]; const char* ready = readies[arc4random_uniform(num_readies)];
prompt(input, sizeof(input), "Ready?", ready); prompt(input, sizeof(input), "ready", "Ready?", ready);
text("\n"); text("\n");
bool kblayout_setable = 0 <= tcgetblob(0, "kblayout", NULL, 0); bool kblayout_setable = 0 <= tcgetblob(0, "kblayout", NULL, 0);
while ( kblayout_setable ) while ( kblayout_setable )
{ {
// TODO: Detect the name of the current keyboard layout. // 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"); "Choose your keyboard layout ('?' or 'L' for list)", "default");
if ( !strcmp(input, "?") || if ( !strcmp(input, "?") ||
!strcmp(input, "l") || !strcmp(input, "l") ||
@ -481,7 +482,7 @@ int main(void)
const char* def = good ? "no" : "yes"; const char* def = good ? "no" : "yes";
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "videomode",
"Select display resolution? (yes/no)", def); "Select display resolution? (yes/no)", def);
if ( strcasecmp(input, "no") && strcasecmp(input, "yes") ) if ( strcasecmp(input, "no") && strcasecmp(input, "yes") )
continue; continue;
@ -521,7 +522,8 @@ int main(void)
{ {
while ( true ) 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"); "run installer instead? (yes/no)", "yes");
if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") )
break; break;
@ -551,7 +553,8 @@ int main(void)
const char* def = NULL; const char* def = NULL;
if ( installations_count == 1 ) if ( installations_count == 1 )
def = path_of_blockdevice(installations[0].bdev); 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; target = NULL;
for ( size_t i = 0; i < installations_count; i++ ) 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); "promise this will work!\n", target->machine, source_machine);
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "switch_architecture",
"Change the existing installation to another architecture?", "Change the existing installation to another architecture?",
"no"); "no");
if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") )
@ -605,7 +608,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "downgrade_release",
"Downgrade to an earlier release?", "no"); "Downgrade to an earlier release?", "no");
if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") )
break; break;
@ -622,7 +625,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "skip_release",
"Skip across releases?", "no"); "Skip across releases?", "no");
if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") )
break; break;
@ -641,7 +644,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "downgrade_abi",
"Downgrade to an earlier ABI?", "no"); "Downgrade to an earlier ABI?", "no");
if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") )
break; break;
@ -707,7 +710,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "cancel_pending_sysmerge",
"Cancel pending sysmerge upgrade?", "yes"); "Cancel pending sysmerge upgrade?", "yes");
if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "no") || !strcasecmp(input, "yes") )
break; break;
@ -774,7 +777,7 @@ int main(void)
while ( true ) while ( true )
{ {
promptx(input, sizeof(input), promptx(input, sizeof(input), "confirm_upgrade",
"Upgrade? (yes/no/poweroff/reboot/halt)", "yes", true); "Upgrade? (yes/no/poweroff/reboot/halt)", "yes", true);
if ( !strcasecmp(input, "yes") ) if ( !strcasecmp(input, "yes") )
break; break;
@ -930,7 +933,7 @@ int main(void)
while ( true ) while ( true )
{ {
prompt(input, sizeof(input), prompt(input, sizeof(input), "finally",
"What now? (poweroff/reboot/halt)", "reboot"); "What now? (poweroff/reboot/halt)", "reboot");
if ( !strcasecmp(input, "poweroff") ) if ( !strcasecmp(input, "poweroff") )
return 0; return 0;