installer: Allow to start networking without ISO download
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 12 Oct 2014 12:30:51 +0000 (14:30 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 12 Oct 2014 12:30:51 +0000 (14:30 +0200)
config/rootfiles/common/installer
src/installer/Makefile.am
src/installer/downloadsource.sh
src/installer/dracut-module/module-setup.sh
src/installer/hw.c
src/installer/main.c
src/installer/start-networking.sh [new file with mode: 0644]

index f28d984..71b537d 100644 (file)
@@ -1,4 +1,5 @@
 #usr/bin/downloadsource.sh
+#usr/bin/start-networking.sh
 #usr/bin/installer
 #usr/lib/dracut/modules.d/99installer
 #usr/lib/dracut/modules.d/99installer/70-dhcpcd.exe
index 59a5312..f52a594 100644 (file)
@@ -33,7 +33,8 @@ bin_PROGRAMS = \
        installer
 
 bin_SCRIPTS = \
-       downloadsource.sh
+       downloadsource.sh \
+       start-networking.sh
 
 #- installer -------------------------------------------------------------------
 
index 1f6c432..7504c19 100644 (file)
@@ -32,13 +32,6 @@ if ( [ "$CMDLINE" == "1" ]); then
        IPFireISO=`echo ${CMDLINE:POS} | cut -d"=" -f2 | cut -d" " -f1`
 fi
 
-echo
-echo "Configure Network with DHCP..."
-dhcpcd
-echo
-echo "Sleep 15s..."
-sleep 15
-echo
 echo "Download with wget..."
 wget $IPFireISO -O /tmp/download.iso -t3 -U IPFire_NetInstall/2.x
 wget $IPFireISO.md5 -O /tmp/download.iso.md5 -t3 -U IPFire_NetInstall/2.x
index 0aa77c9..31caa54 100755 (executable)
@@ -34,8 +34,9 @@ install() {
     # Extraction
     inst_multiple tar gzip lzma xz
 
-    # DHCP Client
-    inst dhcpcd
+    # Networking
+    inst_multiple dhcpcd ethtool hostname ip ping wget
+    inst /usr/bin/start-networking.sh
     inst /var/ipfire/dhcpc/dhcpcd-run-hooks
     inst /var/ipfire/dhcpc/dhcpcd.conf
     for file in /var/ipfire/dhcpc/dhcpcd-hooks/*; do
@@ -44,7 +45,7 @@ install() {
     inst "$moddir/70-dhcpcd.exe" "/var/ipfire/dhcpc/dhcpcd-hooks/70-dhcpcd.exe"
 
     # Misc. tools
-    inst_multiple eject ping touch wget
+    inst_multiple cut grep eject killall md5sum touch
     inst_multiple -o fdisk cfdisk df ps top
 
     # Hardware IDs
index ecc4dc3..4e65a8b 100644 (file)
@@ -1037,3 +1037,7 @@ void hw_sync() {
        sync();
        sync();
 }
+
+int hw_start_networking(const char* output) {
+       return mysystem(output, "/usr/bin/start-networking.sh");
+}
index 94603b8..520ae3a 100644 (file)
@@ -247,6 +247,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] = "";
 
@@ -291,6 +292,12 @@ int main(int argc, char *argv[]) {
                    splashWindow(title, _("Warning: Unattended installation will start in 10 seconds..."), 10);
                    unattended = 1;
                }
+
+               // 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;
@@ -338,18 +345,53 @@ 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) {
+                       runcommandwithstatus("/usr/bin/downloadsource.sh",
+                               title, _("Downloading installation image..."), logfile);
+
+                       if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
+                               errorbox(_("Download error"));
+                               goto EXIT;
+                       }
+
+                       fgets(sourcedrive, 5, handle);
+                       fclose(handle);
+               }
        }
 
        assert(sourcedrive);
diff --git a/src/installer/start-networking.sh b/src/installer/start-networking.sh
new file mode 100644 (file)
index 0000000..faeeb17
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2014  IPFire Team  <info@ipfire.org>                          #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+function list_interfaces() {
+       local interface
+
+       for interface in /sys/class/net/*; do
+               [ -d "${interface}" ] || continue
+
+               interface="$(basename ${interface})"
+               case "${interface}" in
+                       eth*)
+                               echo "${interface}"
+                               ;;
+               esac
+       done
+}
+
+function try_dhcp() {
+       local interface="${1}"
+
+       # Bring up the interface
+       ip link set "${interface}" up
+
+       # Try to make the lights of the adapter light up
+       ethtool -i "${interface}" &>/dev/null
+
+       # Start the DHCP client
+       dhcpcd "${interface}"
+}
+
+function main() {
+       local interface
+       for interface in $(list_interfaces); do
+               if ! try_dhcp "${interface}"; then
+                       echo "Could not acquire an IP address on ${interface}"
+                       continue
+               fi
+
+               echo "Successfully started on ${interface}"
+               return 0
+       done
+
+       return 1
+}
+
+main