From: Michael Tremer Date: Sun, 12 Oct 2014 12:30:51 +0000 (+0200) Subject: installer: Allow to start networking without ISO download X-Git-Tag: v2.17-core87~103^2~51^2~3 X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=commitdiff_plain;h=7d114284653340a32c29f576a1c33faf5a21aca1 installer: Allow to start networking without ISO download --- diff --git a/config/rootfiles/common/installer b/config/rootfiles/common/installer index f28d984742..71b537dd33 100644 --- a/config/rootfiles/common/installer +++ b/config/rootfiles/common/installer @@ -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 diff --git a/src/installer/Makefile.am b/src/installer/Makefile.am index 59a5312fbd..f52a5940ac 100644 --- a/src/installer/Makefile.am +++ b/src/installer/Makefile.am @@ -33,7 +33,8 @@ bin_PROGRAMS = \ installer bin_SCRIPTS = \ - downloadsource.sh + downloadsource.sh \ + start-networking.sh #- installer ------------------------------------------------------------------- diff --git a/src/installer/downloadsource.sh b/src/installer/downloadsource.sh index 1f6c432dd8..7504c198fd 100644 --- a/src/installer/downloadsource.sh +++ b/src/installer/downloadsource.sh @@ -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 diff --git a/src/installer/dracut-module/module-setup.sh b/src/installer/dracut-module/module-setup.sh index 0aa77c9458..31caa5489d 100755 --- a/src/installer/dracut-module/module-setup.sh +++ b/src/installer/dracut-module/module-setup.sh @@ -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 diff --git a/src/installer/hw.c b/src/installer/hw.c index ecc4dc3924..4e65a8b7a0 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -1037,3 +1037,7 @@ void hw_sync() { sync(); sync(); } + +int hw_start_networking(const char* output) { + return mysystem(output, "/usr/bin/start-networking.sh"); +} diff --git a/src/installer/main.c b/src/installer/main.c index 94603b8bbd..520ae3a8b1 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -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 index 0000000000..faeeb17237 --- /dev/null +++ b/src/installer/start-networking.sh @@ -0,0 +1,65 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2014 IPFire Team # +# # +# 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 . # +# # +############################################################################### + +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