ref: 83dd78258053cd102e8425beb159a2be7e6b912f
parent: 7f538f1e2f33dd44c66693442e7713ca16e26d8b
author: Ain <41307858+nero@users.noreply.github.com>
date: Thu Aug 9 15:57:28 CDT 2018
Fix network setup when only ip= is explicitly given Previously, configure_ip was only called from code paths of other boot options that require network. This fixes the passing of -n to nlplug-findfs and --no-network to the apk memory bootstrap.
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -277,6 +277,16 @@
[ -e "$rtc" ]
}
+# This is used to predict if network access will be necessary
+is_url() {
+ case "$1" in
+ http://*|https://*|ftp://*)
+ return 0;;
+ *)
+ return 1;;
+ esac
+}
+
# read the kernel options. we need surve things like:
# acpi_osi="!Windows 2006" xen-pciback.hide=(01:00.0)
set -- $(cat /proc/cmdline)
@@ -360,6 +370,15 @@
[ -d /dev/shm ] || mkdir /dev/shm
mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
+# determine if we are going to need networking
+if [ -n "$KOPT_ip" ] || [ -n "$KOPT_nbd" ] || \
+ is_url "$KOPT_apkovl" || is_url "$ALPINE_REPO"; then
+
+ do_networking=true
+else
+ do_networking=false
+fi
+
if [ -n "$KOPT_dasd" ]; then
for mod in dasd_mod dasd_eckd_mod dasd_fba_mod; do
modprobe $mod
@@ -413,6 +432,7 @@
fi
if [ -n "$KOPT_nbd" ]; then
+ # TODO: Might fail because nlplug-findfs hasn't plugged eth0 yet
configure_ip
setup_nbd || echo "Failed to setup nbd device."
fi
@@ -471,7 +491,7 @@
exec /bin/busybox sh
fi
-if [ -n "$ALPINE_REPO" ]; then
+if $do_networking; then
repoopts="-n"
else
repoopts="-b $repofile"
@@ -484,6 +504,11 @@
$repoopts -a /tmp/apkovls
eend $?
+# Setup network interfaces
+if $do_networking; then
+ configure_ip
+fi
+
# early console?
if [ "$SINGLEMODE" = "yes" ]; then
echo "Entering single mode. Type 'exit' to continue booting."
@@ -502,27 +527,22 @@
mount -t tmpfs -o $rootflags tmpfs $sysroot
-case "$KOPT_apkovl" in
- '')
- if [ -e /tmp/apkovls ]; then
- ovl=$(head -n 1 /tmp/apkovls)
- fi
- ;;
- http://*|https://*|ftp://*)
- configure_ip
+if [ -z "$KOPT_apkovl" ]; then
+ # Not manually set, use the apkovl found by nlplug
+ if [ -e /tmp/apkovls ]; then
+ ovl=$(head -n 1 /tmp/apkovls)
+ fi
+elif is_url "$KOPT_apkovl"; then
+ # Fetch apkovl via network
+ MACHINE_UUID=$(cat /sys/class/dmi/id/product_uuid)
+ url="${KOPT_apkovl/{MAC\}/$MAC_ADDRESS}"
+ url="${url/{UUID\}/$MACHINE_UUID}"
+ ovl=/tmp/${url##*/}
+ wget -O "$ovl" "$url" || ovl=
+else
+ ovl="$KOPT_apkovl"
+fi
- MACHINE_UUID=$(cat /sys/class/dmi/id/product_uuid)
- url="${KOPT_apkovl/{MAC\}/$MAC_ADDRESS}"
- url="${url/{UUID\}/$MACHINE_UUID}"
- ovl=/tmp/${url##*/}
- wget -O "$ovl" "$url" || ovl=
- ;;
- *)
- ovl="$KOPT_apkovl"
- ;;
-esac
-
-
# parse pkgs=pkg1,pkg2
if [ -n "$KOPT_pkgs" ]; then
pkgs=$(echo "$KOPT_pkgs" | tr ',' ' ' )
@@ -620,9 +640,6 @@
# generate apk repositories file. needs to be done after relocation
find_boot_repositories > $repofile
-# set up network if needed
-[ "$ALPINE_REPO" ] && configure_ip
-
# silently fix apk arch in case the apkovl does not match
if [ -r "$sysroot"/etc/apk/arch ]; then
apk_arch="$(apk --print-arch)"
@@ -664,7 +681,7 @@
fi
apkflags="--initramfs-diskless-boot --progress"
-if [ -z "$ALPINE_REPO" ]; then
+if [ -z "$MAC_ADDRESS" ]; then
apkflags="$apkflags --no-network"
else
apkflags="$apkflags --update-cache"