]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/40network/netroot.sh
use "rm --" to guard against filenames beginning with "-"
[thirdparty/dracut.git] / modules.d / 40network / netroot.sh
CommitLineData
7d7efa4a 1#!/bin/sh
cc02093d
HH
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
7d7efa4a 4
fb59f4c9 5PATH=/usr/sbin:/usr/bin:/sbin:/bin
25aa3c5a
WW
6command -v getarg >/dev/null || . /lib/dracut-lib.sh
7command -v setup_net >/dev/null || . /lib/net-lib.sh
7d7efa4a 8
05e2c592
PS
9# Huh? Empty $1?
10[ -z "$1" ] && exit 1
11
957bc5c9
DY
12# [ ! -z $2 ] means this is for manually bringing up network
13# instead of real netroot; If It's called without $2, then there's
14# no sense in doing something if no (net)root info is available
a55d10c0 15# or root is already there
c6c704fd
HH
16[ -d $NEWROOT/proc ] && exit 0
17[ -z "$netroot" ] && exit 1
8ecd9d01 18
3b403b32 19# Set or override primary interface
a55d10c0 20netif=$1
8ecd9d01 21[ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev
7d7efa4a 22
b819f519
HH
23case "$netif" in
24 ??:??:??:??:??:??) # MAC address
25 for i in /sys/class/net/*/address; do
26 mac=$(cat $i)
27 if [ "$mac" = "$netif" ]; then
28 i=${i%/address}
29 netif=${i##*/}
30 break
31 fi
32 done
33esac
34
3b403b32 35# Figure out the handler for root=dhcp by recalling all netroot cmdline
957bc5c9
DY
36# handlers when this is not called from manually network bringing up.
37if [ -z "$2" ]; then
38 if [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] ; then
957bc5c9
DY
39 # Load dhcp options
40 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
41
42 # If we have a specific bootdev with no dhcpoptions or empty root-path,
43 # we die. Otherwise we just warn
44 if [ -z "$new_root_path" ] ; then
45 [ -n "$BOOTDEV" ] && die "No dhcp root-path received for '$BOOTDEV'"
46 warn "No dhcp root-path received for '$BOOTDEV' trying other interfaces if available"
47 exit 1
48 fi
8ecd9d01 49
957bc5c9
DY
50 # Set netroot to new_root_path, so cmdline parsers don't call
51 netroot=$new_root_path
50e7ff76 52
957bc5c9
DY
53 # FIXME!
54 for f in $hookdir/cmdline/90*.sh; do
55 [ -f "$f" ] && . "$f";
56 done
57 else
58 rootok="1"
59 fi
7d7efa4a 60
957bc5c9
DY
61 # Check: do we really know how to handle (net)root?
62 [ -z "$root" ] && die "No or empty root= argument"
63 [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"
50e7ff76 64
957bc5c9
DY
65 handler=${netroot%%:*}
66 handler=${handler%%4}
67 handler=$(command -v ${handler}root)
68 if [ -z "$netroot" ] || [ ! -e "$handler" ] ; then
69 die "No handler for netroot type '$netroot'"
70 fi
50e7ff76
PS
71fi
72
73# Source netroot hooks before we start the handler
c6c704fd 74source_hook netroot $netif
50e7ff76 75
7d7efa4a
DD
76# Run the handler; don't store the root, it may change from device to device
77# XXX other variables to export?
9cdfd735 78if $handler $netif $netroot $NEWROOT; then
32bd2fbb 79 rm -f -- $hookdir/initqueue/finished/dhcp.sh
e173f0b3
WW
80 # Network rootfs mount successful - save interface info for ifcfg etc.
81 save_netinfo $netif
7d7efa4a
DD
82fi
83exit 0