aboutsummaryrefslogtreecommitdiffstats
path: root/initramfs-init.in
diff options
context:
space:
mode:
authorAin <41307858+nero@users.noreply.github.com>2018-09-11 13:21:19 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2018-11-08 16:17:47 +0000
commit83f3b26cac43c01607b8e3da33bb457f1a9ab7a7 (patch)
tree4353b652dfce69afafa5e1dfb76ee0ed03ddf78d /initramfs-init.in
parenta9463e4a91b20f9e097f2e294c9f29e4ad26c13d (diff)
downloadmkinitfs-83f3b26cac43c01607b8e3da33bb457f1a9ab7a7.tar.bz2
mkinitfs-83f3b26cac43c01607b8e3da33bb457f1a9ab7a7.tar.xz
Cleanup and improve documentation for ip= parameter
Diffstat (limited to 'initramfs-init.in')
-rwxr-xr-xinitramfs-init.in42
1 files changed, 24 insertions, 18 deletions
diff --git a/initramfs-init.in b/initramfs-init.in
index 5cbf29f..22e4250 100755
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -146,14 +146,6 @@ ip_choose_if() {
[ -e "$x" ] && echo ${x##*/} && return
}
-# ip_set <device> <ip> <netmask> <gateway-ip>
-ip_set() {
- ifconfig "$1" "$2" netmask "$3" || return $?
- if [ -n "$4" ]; then
- ip route add 0.0.0.0/0 via "$4" dev "$1" || return $?
- fi
-}
-
# if "ip=dhcp" is specified on the command line, we obtain an IP address
# using udhcpc. we do this now and not by enabling kernel-mode DHCP because
# kernel-model DHCP appears to require that network drivers be built into
@@ -162,19 +154,24 @@ ip_set() {
#
# You need af_packet.ko available as well modules for your Ethernet card.
#
+# See https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
+# for documentation on the format.
+#
# Valid syntaxes:
-# ip=client-ip:server-ip:gw-ip:netmask:hostname:device:autoconf
+# ip=client-ip:server-ip:gw-ip:netmask:hostname:device:autoconf:
+# :dns0-ip:dns1-ip:ntp0-ip
# ip=dhcp
-# "server-ip" and "hostname" are not supported here.
+# "server-ip", "hostname" and "ntp0-ip" are not supported here.
# Default (when configure_ip is called without setting ip=):
# ip=dhcp
#
configure_ip() {
[ -n "$MAC_ADDRESS" ] && return
- local ops=${KOPT_ip:-dhcp}
+
local IFS=':'
- set -- $ops
+ set -- ${KOPT_ip:-dhcp}
unset IFS
+
local client_ip="$1"
local gw_ip="$3"
local netmask="$4"
@@ -182,16 +179,19 @@ configure_ip() {
local autoconf="$7"
local dns1="$8"
local dns2="$9"
+
case "$client_ip" in
- off|none|'') return;;
+ off|none) return;;
dhcp) autoconf="dhcp";;
esac
[ -n "$device" ] || device=$(ip_choose_if)
+
if [ -z "$device" ]; then
echo "ERROR: IP requested but no network device was found"
return 1
fi
+
if [ "$autoconf" = "dhcp" ]; then
# automatic configuration
if [ ! -e /usr/share/udhcpc/default.script ]; then
@@ -199,18 +199,24 @@ configure_ip() {
return 1
fi
ebegin "Obtaining IP via DHCP ($device)..."
- ifconfig $device 0.0.0.0
- udhcpc -i $device -f -q
+ ifconfig "$device" 0.0.0.0
+ udhcpc -i "$device" -f -q
eend $?
else
# manual configuration
[ -n "$client_ip" -a -n "$netmask" ] || return
ebegin "Setting IP ($device)..."
- ip_set "$device" "$client_ip" "$netmask" "$gw_ip"
+ if ifconfig "$device" "$client_ip" netmask "$netmask"; then
+ [ -z "$gw_ip" ] || ip route add 0.0.0.0/0 via "$gw_ip" dev "$device"
+ fi
eend $?
- [ -n "$dns1" ] && echo "nameserver $dns1" >> /etc/resolv.conf
- [ -n "$dns2" ] && echo "nameserver $dns2" >> /etc/resolv.conf
fi
+
+ # Never executes if variables are empty
+ for i in $dns1 $dns2; do
+ echo "nameserver $i" >> /etc/resolv.conf
+ done
+
MAC_ADDRESS=$(cat /sys/class/net/$device/address)
}