]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/installer/main.c
installer: Remove reading the path of the downloaded ISO
[ipfire-2.x.git] / src / installer / main.c
index e5da6ec9baf205a3d94ea6defabe8688cd3bc19d..411121c125f73196348f22d50c59ca6058fffbee 100644 (file)
 
 #include <assert.h>
 #include <errno.h>
+#include <libsmooth.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mount.h>
 
 #include "hw.h"
-#include "install.h"
 
 // Translation
 #include <libintl.h>
@@ -25,6 +25,7 @@
 #define INST_FILECOUNT 21000
 #define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
 #define LICENSE_FILE   "/cdrom/COPYING"
+#define SOURCE_TEMPFILE "/tmp/downloaded-image.iso"
 
 extern char url[STRING_SIZE];
 
@@ -247,6 +248,7 @@ int main(int argc, char *argv[]) {
                
        int unattended = 0;
        int serialconsole = 0;
+       int require_networking = 0;
        struct keyvalue *unattendedkv = initkeyvalues();
        char restore_file[STRING_SIZE] = "";
 
@@ -281,17 +283,22 @@ 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 the installer should start networking
+               if (strstr(line, "installer.net") != NULL) {
+                       require_networking = 1;
+               }
+
                // check if we have to patch for serial console
                if (strstr (line, "console=ttyS0") != NULL) {
                    serialconsole = 1;
@@ -314,7 +321,7 @@ 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);
@@ -339,18 +346,54 @@ int main(int argc, char *argv[]) {
        /* Search for a source drive that holds the right
         * version of the image we are going to install. */
        sourcedrive = hw_find_source_medium(hw);
-
        fprintf(flog, "Source drive: %s\n", sourcedrive);
+
+       /* If we could not find a source drive, we will try
+        * downloading the install image */
        if (!sourcedrive) {
-               newtWinMessage(title, _("OK"), _("No local source media found. Starting download."));
-               runcommandwithstatus("/bin/downloadsource.sh", title, _("Downloading installation image ..."), logfile);
-               if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
-                       errorbox(_("Download error"));
+               require_networking = 1;
+
+               if (!unattended) {
+                       rc = newtWinOkCancel(title, _("No source drive could be found.\n\n"
+                               "You can try to download the required installation data. "
+                               "Please make sure to connect your machine to a network and "
+                               "the installer will try connect to acquire an IP address."),
+                               55, 10, _("Download installation image"), _("Cancel"));
+
+                       if (rc != 0)
+                               goto EXIT;
+               }
+       }
+
+       // Try starting the networking if we require it
+       if (require_networking) {
+               statuswindow(60, 4, title, _("Trying to start networking (DHCP)..."));
+
+               rc = hw_start_networking(logfile);
+               newtPopWindow();
+
+               if (rc) {
+                       errorbox(_("Networking could not be started "
+                               "but is required to go on with the installation.\n\n"
+                               "Please connect your machine to a network with a "
+                               "DHCP server and retry."));
                        goto EXIT;
                }
 
-               fgets(sourcedrive, 5, handle);
-               fclose(handle);
+               // Download the image if required
+               if (!sourcedrive) {
+                       snprintf(commandstring, sizeof(commandstring), "/usr/bin/downloadsource.sh %s", SOURCE_TEMPFILE);
+                       runcommandwithstatus(commandstring, title, _("Downloading installation image..."), logfile);
+
+                       FILE* f = fopen(SOURCE_TEMPFILE, "r");
+                       if (f) {
+                               sourcedrive = SOURCE_TEMPFILE;
+                               fclose(f);
+                       } else {
+                               errorbox(_("The installation image could not be downloaded."));
+                               goto EXIT;
+                       }
+               }
        }
 
        assert(sourcedrive);
@@ -406,8 +449,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
@@ -442,6 +487,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) {
@@ -469,7 +519,7 @@ 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);
                }