]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/40network/module-setup.sh
Factor out all the "type -V" commands
[thirdparty/dracut.git] / modules.d / 40network / module-setup.sh
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 # called by dracut
6 check() {
7 local _program
8
9 require_binaries ip arping dhclient || return 1
10
11 return 255
12 }
13
14 # called by dracut
15 depends() {
16 return 0
17 }
18
19 # called by dracut
20 installkernel() {
21 # Include wired net drivers, excluding wireless
22
23 net_module_filter() {
24 local _net_drivers='eth_type_trans|register_virtio_device|usbnet_open'
25 local _unwanted_drivers='/(wireless|isdn|uwb|net/ethernet|net/phy|net/team)/'
26 local _ret
27 # subfunctions inherit following FDs
28 local _merge=8 _side2=9
29 function nmf1() {
30 local _fname _fcont
31 while read _fname; do
32 [[ $_fname =~ $_unwanted_drivers ]] && continue
33 case "$_fname" in
34 *.ko) _fcont="$(< $_fname)" ;;
35 *.ko.gz) _fcont="$(gzip -dc $_fname)" ;;
36 *.ko.xz) _fcont="$(xz -dc $_fname)" ;;
37 esac
38 [[ $_fcont =~ $_net_drivers
39 && ! $_fcont =~ iw_handler_get_spy ]] \
40 && echo "$_fname"
41 done
42 return 0
43 }
44 function rotor() {
45 local _f1 _f2
46 while read _f1; do
47 echo "$_f1"
48 if read _f2; then
49 echo "$_f2" 1>&${_side2}
50 fi
51 done | nmf1 1>&${_merge}
52 return 0
53 }
54 # Use two parallel streams to filter alternating modules.
55 set +x
56 eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1"
57 [[ $debug ]] && set -x
58 return 0
59 }
60
61 { find_kernel_modules_by_path drivers/net; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/net; fi; } \
62 | net_module_filter | instmods
63
64 #instmods() will take care of hostonly
65 instmods \
66 =drivers/net/phy \
67 =drivers/net/team \
68 =drivers/net/ethernet \
69 ecb arc4 bridge stp llc ipv6 bonding 8021q af_packet virtio_net
70 }
71
72 # called by dracut
73 install() {
74 local _arch _i _dir
75 inst_multiple ip arping dhclient sed
76 inst_multiple -o ping ping6
77 inst_multiple -o brctl
78 inst_multiple -o teamd teamdctl teamnl
79 inst_simple /etc/libnl/classid
80 inst_script "$moddir/ifup.sh" "/sbin/ifup"
81 inst_script "$moddir/netroot.sh" "/sbin/netroot"
82 inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
83 inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh"
84 inst_simple "$moddir/dhclient.conf" "/etc/dhclient.conf"
85 inst_hook pre-udev 50 "$moddir/ifname-genrules.sh"
86 inst_hook pre-udev 60 "$moddir/net-genrules.sh"
87 inst_hook cmdline 91 "$moddir/dhcp-root.sh"
88 inst_hook cmdline 92 "$moddir/parse-ibft.sh"
89 inst_hook cmdline 95 "$moddir/parse-vlan.sh"
90 inst_hook cmdline 96 "$moddir/parse-bond.sh"
91 inst_hook cmdline 96 "$moddir/parse-team.sh"
92 inst_hook cmdline 97 "$moddir/parse-bridge.sh"
93 inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
94 inst_hook cmdline 99 "$moddir/parse-ifname.sh"
95 inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
96
97 _arch=$(uname -m)
98
99 inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
100 {"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*"
101
102 dracut_need_initqueue
103 }
104