]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/installer/main.c
installer: use sysinfo() for memory detection
[ipfire-2.x.git] / src / installer / main.c
index c5adb0adfc754ec37f668124ae3e31d00bdd9772..1f7ec2b4ba8f6d3cc5a85fd2ad264d3a6c816f18 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;
@@ -315,9 +320,10 @@ int main(int argc, char *argv[]) {
                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 +390,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;
@@ -451,7 +457,7 @@ int main(int argc, char *argv[]) {
                } else if (num_selected_disks == 2) {
                        snprintf(message, sizeof(message),
                                _("The installation program will now set up a RAID configuration on the selected harddisks:\n\n  %s\n  %s\n\n"
-                               "Do you agree to continue?"), (*selected_disks)->description, (*selected_disks + 1)->description);
+                               "Do you agree to continue?"), selected_disks[0]->description, selected_disks[1]->description);
                        rc = newtWinOkCancel(_("RAID Setup"), message, 50, 14,
                                _("Delete all data"), _("Cancel"));
 
@@ -464,6 +470,7 @@ int main(int argc, char *argv[]) {
                // Currently not supported
                } else {
                        errorbox(_("You disk configuration is currently not supported."));
+                       fprintf(flog, "Num disks selected: %d\n", num_selected_disks);
                }
 
                if (selected_disks) {
@@ -487,6 +494,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 +548,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 +600,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 +612,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 console\"\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 +637,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");
 
@@ -637,6 +656,13 @@ int main(int argc, char *argv[]) {
                mysystem(logfile, commandstring);
        }
 
+       // 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);
 
@@ -671,13 +697,7 @@ EXIT:
        free(helpline);
 
        free(sourcedrive);
-
-       if (destination) {
-               hw_sync();
-
-               hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
-               free(destination);
-       }
+       free(destination);
 
        hw_stop_all_raid_arrays(logfile);