]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/installer/main.c
installer: Enable new partitioning code to be run in unattended mode
[ipfire-2.x.git] / src / installer / main.c
index bb73fc24c04519a8b76ab8c8746be2853f7db093..f197dc351c39a054ba1099717856769d9af4d6cc 100644 (file)
@@ -111,8 +111,11 @@ static int newtWinOkCancel(const char* title, const char* message, int width, in
        newtTextboxSetText(textbox, message);
        newtFormAddComponent(form, textbox);
 
-       newtComponent btn_ok = newtButton((width - 16) / 3, height - 4, btn_txt_ok);
-       newtComponent btn_cancel = newtButton((width - 16) / 3 * 2 + 9, height - 4,
+       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);
 
        newtFormAddComponents(form, btn_ok, btn_cancel, NULL);
@@ -209,11 +212,13 @@ static struct lang {
        const char* code;
        char* name;
 } languages[NUM_LANGS + 1] = {
+       { "da.utf8",    "Danish (Dansk)" },
        { "nl_NL.utf8", "Dutch (Nederlands)" },
        { "en_US.utf8", "English" },
        { "fr_FR.utf8", "French (Français)" },
        { "de_DE.utf8", "German (Deutsch)" },
        { "pl_PL.utf8", "Polish (Polski)" },
+       { "pt_BR.utf8", "Portuguese (Brasil)" },
        { "ru_RU.utf8", "Russian (Русский)" },
        { "es_ES.utf8", "Spanish (Español)" },
        { "tr_TR.utf8", "Turkish (Türkçe)" },
@@ -233,7 +238,7 @@ int main(int argc, char *argv[]) {
        int rc = 0;
        char commandstring[STRING_SIZE];
        int choice;
-       char shortlangname[10];
+       char language[STRING_SIZE];
        char message[STRING_SIZE];
        char title[STRING_SIZE];
        int allok = 0;
@@ -276,17 +281,16 @@ int main(int argc, char *argv[]) {
 
        snprintf(title, sizeof(title), "%s - %s", NAME, SLOGAN);
 
-       if (! (cmdfile = fopen("/proc/cmdline", "r")))
-       {
+       if (! (cmdfile = fopen("/proc/cmdline", "r"))) {
                fprintf(flog, "Couldn't open commandline: /proc/cmdline\n");
        } else {
                fgets(line, STRING_SIZE, cmdfile);
-               
+
                // check if we have to make an unattended install
-               if (strstr (line, "unattended") != NULL) {
+               if (strstr(line, "installer.unattended") != NULL) {
+                   splashWindow(title, _("Warning: Unattended installation will start in 10 seconds..."), 10);
                    unattended = 1;
-                   runcommandwithstatus("/bin/sleep 10", title, "WARNING: Unattended installation will start in 10 seconds...", NULL);
-               }               
+               }
                // check if we have to patch for serial console
                if (strstr (line, "console=ttyS0") != NULL) {
                    serialconsole = 1;
@@ -309,15 +313,16 @@ int main(int argc, char *argv[]) {
                }
                langnames[NUM_LANGS] = NULL;
 
-           rc = newtWinMenu(_("Language selection"), _("Select the language you wish to use for the installation."),
+               rc = newtWinMenu(_("Language selection"), _("Select the language you wish to use for the installation."),
                        50, 5, 5, 8, langnames, &choice, _("OK"), NULL);
 
                assert(choice <= NUM_LANGS);
 
                fprintf(flog, "Selected language: %s (%s)\n", languages[choice].name, languages[choice].code);
+               snprintf(language, sizeof(language), languages[choice].code);
 
-               setenv("LANGUAGE", languages[choice].code, 1);
-               setlocale(LC_ALL, languages[choice].code);
+               setenv("LANGUAGE", language, 1);
+               setlocale(LC_ALL, language);
        }
 
        char* helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
@@ -384,7 +389,7 @@ int main(int argc, char *argv[]) {
        int part_type = HW_PART_TYPE_NORMAL;
 
        // Scan for disks to install on.
-       struct hw_disk** disks = hw_find_disks(hw);
+       struct hw_disk** disks = hw_find_disks(hw, sourcedrive);
 
        struct hw_disk** selected_disks = NULL;
        unsigned int num_selected_disks = 0;
@@ -400,8 +405,10 @@ int main(int argc, char *argv[]) {
                        goto EXIT;
 
                // exactly one disk has been found
-               } else if (num_disks == 1) {
-                       selected_disks = hw_select_disks(disks, NULL);
+               // or if we are running in unattended mode, we will select
+               // the first disk and go with that one
+               } else if ((num_disks == 1) || (unattended && num_disks >= 1)) {
+                       selected_disks = hw_select_first_disk(disks);
 
                // more than one usable disk has been found and
                // the user needs to choose what to do with them
@@ -436,6 +443,11 @@ int main(int argc, char *argv[]) {
                        }
                }
 
+               // Don't print the auto-selected harddisk setup in
+               // unattended mode.
+               if (unattended)
+                       break;
+
                num_selected_disks = hw_count_disks(selected_disks);
 
                if (num_selected_disks == 1) {
@@ -463,7 +475,8 @@ int main(int argc, char *argv[]) {
 
                // Currently not supported
                } else {
-                       errorbox(_("You disk configuration is currently not supported."));
+                       errorbox(_("Your disk configuration is currently not supported."));
+                       fprintf(flog, "Num disks selected: %d\n", num_selected_disks);
                }
 
                if (selected_disks) {
@@ -487,6 +500,7 @@ int main(int argc, char *argv[]) {
        fprintf(flog, "  swap   : %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap));
        fprintf(flog, "  root   : %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root));
        fprintf(flog, "  data   : %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data));
+       fprintf(flog, "Memory   : %lluMB\n", BYTES2MB(hw_memory()));
 
        // Warn the user if there is not enough space to create a swap partition
        if (!unattended && !*destination->part_swap) {
@@ -540,6 +554,10 @@ int main(int argc, char *argv[]) {
                }
 
                newtPopWindow();
+       } else {
+               // We will have to destroy all RAID setups that may have
+               // been on the devices that we want to use now.
+               hw_destroy_raid_superblocks(destination, logfile);
        }
 
        // Execute the partitioning...
@@ -588,7 +606,7 @@ int main(int argc, char *argv[]) {
        }
 
        /* Save language und local settings */
-       write_lang_configs(shortlangname);
+       write_lang_configs(language);
 
        /* Build cache lang file */
        snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
@@ -600,23 +618,22 @@ int main(int argc, char *argv[]) {
        // Installing bootloader...
        statuswindow(60, 4, title, _("Installing the bootloader..."));
 
-       rc = hw_install_bootloader(destination, logfile);
-       if (rc) {
-               errorbox(_("Unable to install the bootloader."));
-               goto EXIT;
-       }
-
-       newtPopWindow();
-
        /* Serial console ? */
        if (serialconsole) {
                /* grub */
-               replace("/harddisk/boot/grub/grub.conf", "splashimage", "#splashimage");
-               replace("/harddisk/boot/grub/grub.conf", "#serial", "serial");
-               replace("/harddisk/boot/grub/grub.conf", "#terminal", "terminal");
-               replace("/harddisk/boot/grub/grub.conf", " panic=10 ", " console=ttyS0,115200n8 panic=10 ");
+               FILE* f = fopen(DESTINATION_MOUNT_PATH "/etc/default/grub", "a");
+               if (!f) {
+                       errorbox(_("Unable to open /etc/default/grub for writing."));
+                       goto EXIT;
+               }
+
+               fprintf(f, "GRUB_TERMINAL=\"serial\"\n");
+               fprintf(f, "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=%d\"\n", SERIAL_BAUDRATE);
+               fclose(f);
 
-               /*inittab*/
+               replace(DESTINATION_MOUNT_PATH "/etc/default/grub", "panic=10", "panic=10 console=ttyS0,115200n8");
+
+               /* inittab */
                replace("/harddisk/etc/inittab", "1:2345:respawn:", "#1:2345:respawn:");
                replace("/harddisk/etc/inittab", "2:2345:respawn:", "#2:2345:respawn:");
                replace("/harddisk/etc/inittab", "3:2345:respawn:", "#3:2345:respawn:");
@@ -626,6 +643,14 @@ int main(int argc, char *argv[]) {
                replace("/harddisk/etc/inittab", "#7:2345:respawn:", "7:2345:respawn:");
        }
 
+       rc = hw_install_bootloader(destination, logfile);
+       if (rc) {
+               errorbox(_("Unable to install the bootloader."));
+               goto EXIT;
+       }
+
+       newtPopWindow();
+
        /* Set marker that the user has already accepted the gpl */
        mysystem(logfile, "/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted");