2f4d93d9f6fabcb18e2ce87f136fbc5d233c461f
[platform/upstream/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 check() {
6     local _program
7     . $dracutfunctions
8
9     for _program in ip arping dhclient ; do
10         if ! type -P $_program >/dev/null; then
11             derror "Could not find program \"$_program\" required by network."
12             return 1
13         fi
14     done
15
16     return 255
17 }
18
19 depends() {
20     [ -d /etc/sysconfig/network-scripts/ ] && echo ifcfg
21     return 0
22 }
23
24 installkernel() {
25     # Include wired net drivers, excluding wireless
26
27     net_module_filter() {
28         local _net_drivers='eth_type_trans|register_virtio_device'
29         local _unwanted_drivers='/(wireless|isdn|uwb)/'
30         # subfunctions inherit following FDs
31         local _merge=8 _side2=9
32         function nmf1() {
33             local _fname _fcont
34             while read _fname; do
35                 [[ $_fname =~ $_unwanted_drivers ]] && continue
36                 case "$_fname" in
37                     *.ko)    _fcont="$(<        $_fname)" ;;
38                     *.ko.gz) _fcont="$(gzip -dc $_fname)" ;;
39                     *.ko.xz) _fcont="$(xz -dc   $_fname)" ;;
40                 esac
41                 [[   $_fcont =~ $_net_drivers
42                 && ! $_fcont =~ iw_handler_get_spy ]] \
43                 && echo "$_fname"
44             done
45         }
46         function rotor() {
47             local _f1 _f2
48             while read _f1; do
49                 echo "$_f1"
50                 if read _f2; then
51                     echo "$_f2" 1>&${_side2}
52                 fi
53             done | nmf1 1>&${_merge}
54         }
55         # Use two parallel streams to filter alternating modules.
56         set +x
57         eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1"
58         [[ $debug ]] && set -x
59     }
60
61     { find_kernel_modules_by_path drivers/net; find_kernel_modules_by_path drivers/s390/net; } \
62         | net_module_filter | instmods
63
64     instmods ecb arc4
65     # bridge modules
66     instmods bridge stp llc
67     instmods ipv6
68     # bonding
69     instmods bonding
70 }
71
72 install() {
73     local _arch _i _dir
74     dracut_install ip arping tr dhclient
75     dracut_install -o brctl ifenslave
76     inst "$moddir/ifup" "/sbin/ifup"
77     inst "$moddir/netroot" "/sbin/netroot"
78     inst "$moddir/dhclient-script" "/sbin/dhclient-script"
79     inst "$moddir/net-lib.sh" "/lib/net-lib.sh"
80     inst_simple "$moddir/dhclient.conf" "/etc/dhclient.conf"
81     inst_hook pre-udev 50 "$moddir/ifname-genrules.sh"
82     inst_hook pre-udev 60 "$moddir/net-genrules.sh"
83     inst_hook cmdline 91 "$moddir/dhcp-root.sh"
84     inst_hook cmdline 96 "$moddir/parse-bond.sh"
85     inst_hook cmdline 97 "$moddir/parse-bridge.sh"
86     inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
87     inst_hook cmdline 99 "$moddir/parse-ifname.sh"
88     inst_hook pre-pivot 10 "$moddir/kill-dhclient.sh"
89
90     _arch=$(uname -m)
91
92     for _dir in "$usrlibdir/tls/$_arch" "$usrlibdir/tls" "$usrlibdir/$_arch" \
93         "$usrlibdir" "$libdir"; do
94         for _i in "$_dir"/libnss_dns.so.* "$_dir"/libnss_mdns4_minimal.so.*; do
95             [ -e "$_i" ] && dracut_install "$_i"
96         done
97     done
98
99 }
100