network/netroot.sh: better handling of $netroot and dhcp

if $netroot is emtpy, get it from cmdline

check cmdline directly for root=dhcp(6) and netroot=dhcp(6)
Harald Hoyer 2015-09-10 13:23:32 +02:00
parent 7cddfbbadb
commit 17cee31b11
1 changed files with 11 additions and 6 deletions

View File

@ -14,6 +14,11 @@ command -v setup_net >/dev/null || . /lib/net-lib.sh
# no sense in doing something if no (net)root info is available
# or root is already there
[ -d $NEWROOT/proc ] && exit 0

if [ -z "$netroot" ]; then
netroot=$(getarg netroot=)
fi

[ -z "$netroot" ] && exit 1

# Set or override primary interface
@ -35,7 +40,7 @@ esac
# Figure out the handler for root=dhcp by recalling all netroot cmdline
# handlers when this is not called from manually network bringing up.
if [ -z "$2" ]; then
if [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] ; then
if getarg "root=dhcp" || getarg "netroot=dhcp" || getarg "root=dhcp6" || getarg "netroot=dhcp6"; then
# Load dhcp options
[ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts

@ -47,6 +52,8 @@ if [ -z "$2" ]; then
exit 1
fi

rm -f -- $hookdir/initqueue/finished/dhcp.sh

# Set netroot to new_root_path, so cmdline parsers don't call
netroot=$new_root_path

@ -76,9 +83,7 @@ source_hook netroot $netif

# Run the handler; don't store the root, it may change from device to device
# XXX other variables to export?
if $handler $netif $netroot $NEWROOT; then
rm -f -- $hookdir/initqueue/finished/dhcp.sh
# Network rootfs mount successful - save interface info for ifcfg etc.
save_netinfo $netif
fi
[ -n "$handler" ] && "$handler" "$netif" "$netroot" "$NEWROOT"
save_netinfo $netif

exit 0