]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/installer/main.c
installer: Fix umounting destination
[ipfire-2.x.git] / src / installer / main.c
index ad388e6a910cf512d891d5dd1610dc2c3bb17ec0..d02db2834afeccb60c891d88964640c6edf44000 100644 (file)
@@ -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);
 
@@ -262,7 +289,7 @@ static void parse_command_line(struct config* c) {
                        char* key = strsep(&val, "=");
 
                        // serial console
-                       if (strcmp(token, "console=ttyS0") == 0)
+                       if ((strcmp(key, "console") == 0) && (strncmp(val, "ttyS", 4) == 0))
                                c->serial_console = 1;
 
                        // enable networking?
@@ -385,7 +412,13 @@ int main(int argc, char *argv[]) {
                setlocale(LC_ALL, language);
        }
 
-       char* helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
+       // Set helpline
+       char* helpline = NULL;
+       if (config.unattended)
+               helpline = center_string(_("Unattended mode"), screen_cols);
+       else
+               helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
+
        newtPushHelpLine(helpline);
 
        if (!config.unattended) {
@@ -469,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] = "-";
@@ -806,16 +839,6 @@ int main(int argc, char *argv[]) {
                free(backup_file);
        }
 
-       // Umount the destination drive
-       hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
-
-       // Stop the RAID array if we are using RAID
-       if (destination->is_raid)
-               hw_stop_all_raid_arrays(logfile);
-
-       // Umount source drive and eject
-       hw_umount(SOURCE_MOUNT_PATH);
-
        // Download and execute the postinstall script
        if (*config.postinstall) {
                snprintf(commandstring, sizeof(commandstring),
@@ -827,10 +850,44 @@ int main(int argc, char *argv[]) {
                }
        }
 
-       snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive);
-       mysystem(logfile, commandstring);
+       // Umount the destination drive
+       statuswindow(60, 4, title, _("Umounting filesystems..."));
+
+       rc = hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
+       if (rc) {
+               // Show an error message if filesystems could not be umounted properly
+               snprintf(message, sizeof(message),
+                       _("Could not umount all filesystems successfully:\n\n  %s"), strerror(errno));
+               errorbox(message);
+               goto EXIT;
+       }
+
+       // Umount source drive and eject
+       hw_umount(SOURCE_MOUNT_PATH);
 
-       if (!config.unattended) {
+       // 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);
+       }
+       newtPopWindow();
+
+       // Stop the RAID array if we are using RAID
+       if (destination->is_raid)
+               hw_stop_all_raid_arrays(logfile);
+
+       // Show a short message that the installation went well and
+       // wait a moment so that all disk caches get flushed.
+       if (config.unattended) {
+               splashWindow(title, _("Unattended installation has finished. The system will be shutting down in a moment..."), 5);
+
+       } else {
                snprintf(message, sizeof(message), _(
                        "%s was successfully installed!\n\n"
                        "Please remove any installation mediums from this system and hit the reboot button. "
@@ -853,19 +910,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();