X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=blobdiff_plain;f=src%2Finstaller%2Fmain.c;h=01a9cc61c0a0311589ebda1b0947f0e50ed42c33;hp=d3e1c6e3edcedf32a9a2b7ab1e7a4ac44e5eb7bf;hb=3e1145e1a0b1a08bf61d6c4962eeae48e3d0c355;hpb=a8fca24560c74f0c37a270f93bd957f0c0b981f6 diff --git a/src/installer/main.c b/src/installer/main.c index d3e1c6e3ed..01a9cc61c0 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -25,7 +25,7 @@ #define INST_FILECOUNT 21000 #define LICENSE_FILE "/cdrom/COPYING" -#define SOURCE_TEMPFILE "/tmp/downloaded-image.iso" +#define SOURCE_TEMPFILE "/tmp/downloads/image.iso" extern char url[STRING_SIZE]; @@ -104,6 +104,37 @@ static int newtWinOkCancel(const char* title, const char* message, int width, in const char* btn_txt_ok, const char* btn_txt_cancel) { int ret = 1; + unsigned int btn_width_ok = strlen(btn_txt_ok); + unsigned int btn_width_cancel = strlen(btn_txt_cancel); + + // Maybe make the box wider to fix both buttons inside + unsigned int min_width = btn_width_ok + btn_width_cancel + 5; + if (width < min_width) + width = min_width; + + unsigned int btn_pos_ok = (width / 3) - (btn_width_ok / 2) - 1; + unsigned int btn_pos_cancel = (width * 2 / 3) - (btn_width_cancel / 2) - 1; + + // Move buttons a bit if they overlap + while ((btn_pos_ok + btn_width_ok + 5) > btn_pos_cancel) { + // Move the cancel button to the right if there is enough space left + if ((btn_pos_cancel + btn_width_cancel + 2) < width) { + ++btn_pos_cancel; + continue; + } + + // Move the OK button to the left if possible + if (btn_pos_ok > 1) { + --btn_pos_ok; + continue; + } + + // If they still overlap, we cannot fix the situtation + // and break. Should actually never get here, because we + // adjust the width of the window earlier. + break; + } + newtCenteredWindow(width, height, title); newtComponent form = newtForm(NULL, NULL, 0); @@ -112,12 +143,8 @@ static int newtWinOkCancel(const char* title, const char* message, int width, in newtTextboxSetText(textbox, message); newtFormAddComponent(form, textbox); - unsigned int btn_width_ok = strlen(btn_txt_ok); - unsigned int btn_width_cancel = strlen(btn_txt_cancel); - - newtComponent btn_ok = newtButton((width / 3) - (btn_width_ok / 2) - 2, height - 4, btn_txt_ok); - newtComponent btn_cancel = newtButton((width * 2 / 3) - (btn_width_cancel / 2) - 2, height - 4, - btn_txt_cancel); + newtComponent btn_ok = newtButton(btn_pos_ok, height - 4, btn_txt_ok); + newtComponent btn_cancel = newtButton(btn_pos_cancel, height - 4, btn_txt_cancel); newtFormAddComponents(form, btn_ok, btn_cancel, NULL); @@ -233,6 +260,7 @@ static struct config { int perform_download; int disable_swap; char download_url[STRING_SIZE]; + char postinstall[STRING_SIZE]; } config = { .unattended = 0, .serial_console = 0, @@ -240,6 +268,7 @@ static struct config { .perform_download = 0, .disable_swap = 0, .download_url = DOWNLOAD_URL, + .postinstall = "\0", }; static void parse_command_line(struct config* c) { @@ -280,6 +309,13 @@ static void parse_command_line(struct config* c) { strncpy(c->download_url, val, sizeof(c->download_url)); c->perform_download = 1; + // Require networking for the download + c->require_networking = 1; + + // postinstall script + } else if (strcmp(key, "installer.postinstall") == 0) { + strncpy(c->postinstall, val, sizeof(c->postinstall)); + // Require networking for the download c->require_networking = 1; } @@ -376,7 +412,13 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL, language); } - char* helpline = center_string(_("/ between elements | selects | next screen"), screen_cols); + // Set helpline + char* helpline = NULL; + if (config.unattended) + helpline = center_string(_("Unattended mode"), screen_cols); + else + helpline = center_string(_("/ between elements | selects | next screen"), screen_cols); + newtPushHelpLine(helpline); if (!config.unattended) { @@ -460,7 +502,7 @@ int main(int argc, char *argv[]) { FILE* f = fopen(SOURCE_TEMPFILE, "r"); if (f) { - sourcedrive = SOURCE_TEMPFILE; + sourcedrive = strdup(SOURCE_TEMPFILE); fclose(f); } else { char reason[STRING_SIZE] = "-"; @@ -807,8 +849,28 @@ int main(int argc, char *argv[]) { // Umount source drive and eject hw_umount(SOURCE_MOUNT_PATH); - snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive); - mysystem(logfile, commandstring); + // Free downloaded ISO image + if (strcmp(sourcedrive, SOURCE_TEMPFILE) == 0) { + rc = unlink(sourcedrive); + if (rc) + fprintf(flog, "Could not free downloaded ISO image: %s\n", sourcedrive); + + // or eject real images + } else { + snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive); + mysystem(logfile, commandstring); + } + + // Download and execute the postinstall script + if (*config.postinstall) { + snprintf(commandstring, sizeof(commandstring), + "/usr/bin/execute-postinstall.sh %s %s", DESTINATION_MOUNT_PATH, config.postinstall); + + if (runcommandwithstatus(commandstring, title, _("Running post-install script..."), logfile)) { + errorbox(_("Post-install script failed.")); + goto EXIT; + } + } if (!config.unattended) { snprintf(message, sizeof(message), _( @@ -833,19 +895,28 @@ EXIT: newtFinished(); // Free resources - free(system_release); - free(roottext); - free(helpline); + if (system_release) + free(system_release); + + if (roottext) + free(roottext); + + if (helpline) + free(helpline); + + if (sourcedrive) + free(sourcedrive); - free(sourcedrive); - free(destination); + if (destination) + free(destination); hw_stop_all_raid_arrays(logfile); if (selected_disks) hw_free_disks(selected_disks); - hw_free(hw); + if (hw) + hw_free(hw); fcloseall();