Tweak german console example
[linux_from_scratch.git] / udev-lfs / init-net-rules.sh
bloba90652ee76ed36616f5698987d430dc672236106
1 #! /bin/bash
3 # This script generates rules for persistent network device naming
4 # Data from udev-182 75-persistent-net-generator.rules
5 # Updated fof udev-197 (DEVICES=en*)
7 RULES=/etc/udev/rules.d/70-persistent-net.rules
8 DEVICES=$(eval echo /sys/class/net/{en*,eth*,ath*,wlan*[0-9],msh*,ra*,sta*,ctc*,lcs*,hsi*})
10 function usage
12 echo $msg
13 echo "init-net-rules.sh is an LFS-specific script to initialize"
14 echo "$RULES"
15 exit 1
18 declare -A VENDORS_IGNORED
19 VENDORS_IGNORED['52:54:00:']="kvm"
20 VENDORS_IGNORED['00:0c:29:']="vmware"
21 VENDORS_IGNORED['00:50:56:']="vmware"
22 VENDORS_IGNORED['00:15:5d:']="hyper-v"
23 VENDORS_IGNORED['00:00:00:']="invalid"
25 declare -A VENDORS
26 VENDORS['02:07:01:']="Interlan, DEC, etc"
27 VENDORS['02:60:60:']="3com"
28 VENDORS['02:60:8c:']="3Com IBM PC; Imagen. etc"
29 VENDORS['02:a0:c9:']="intel"
30 VENDORS['02:aa:3c:']="Olivetti"
31 VENDORS['02:cf:1f:']="Masscomp, Silicon Graphics, etc"
32 VENDORS['02:e0:3b:']="Gigabit"
33 VENDORS['02:e6:d3:']="BTI"
34 VENDORS['52:54:00:']="Realtek"
35 VENDORS['52:54:4c:']="Novell"
36 VENDORS['52:54:ab:']="Realtek"
37 VENDORS['e2:0c:0f:']="Kingston"
38 VENDORS['00:16:3e:']="Xensource"
40 function ignore_if
42 if [[ "${VENDORS_IGNORED[$VENDOR]}" != "" ]]; then return 0; fi
43 if [[ "${VENDORS[$VENDOR]}" != "" ]]; then return 1; fi
45 byte2=$(echo $VENDOR | cut -c2)
46 if echo $byte2 | grep -q "[2367abef]"; then return 0; fi
48 return 1 # Default is to not ignore
51 function comment
53 # Not implemented
54 # SUBSYSTEMS=="pci"
55 # export COMMENT="PCI device $attr{vendor}:$attr{device} ($driver)"
57 # SUBSYSTEMS=="usb", ATTRS{idVendor}=="?*"
58 # export COMMENT="USB device 0x$attr{idVendor}:0x$attr{idProduct} ($driver)"
60 # SUBSYSTEMS=="pcmcia",
61 # export COMMENT="PCMCIA device $attr{card_id}:$attr{manf_id} ($driver)"
63 # SUBSYSTEMS=="ieee1394",
64 # export COMMENT="Firewire device $attr{host_id})"
66 # ibmveth likes to use "locally administered" MAC addresses
67 # DRIVERS=="ibmveth",
68 # export COMMENT="ibmveth ($id)"
70 # S/390 uses id matches only, do not use MAC address match
71 # SUBSYSTEMS=="ccwgroup",
72 # export COMMENT="S/390 $driver device at $id",
73 # export MATCHID="$id"
74 # export MATCHDRV="$driver"
75 # export MATCHADDR=""
77 # Default
78 driver=$(basename $(readlink -f $NIC/device/driver/module))
79 export COMMENT="net device ${driver}"
82 if ! mountpoint -q /sys; then
83 msg="/sys must be mounted"
84 usage
87 if ! mountpoint -q /proc; then
88 msg="/proc must be mounted"
89 usage
92 if [ -e $RULES ]; then
93 msg="The rules file already exists"
94 usage
97 # Ignore Xen virtual interfaces
98 if [ -e /proc/xen ]; then
99 msg="The rules file should not be created in the Xen environment"
100 usage
103 # Variables used to communicate with write_net_rules:
104 # INTERFACE simple interface name
105 # MATCHADDR MAC address used for the match
106 # MATCHID bus_id used for the match
107 # MATCHDRV driver name used for the match
108 # MATCHIFTYPE interface type match
109 # COMMENT comment to add to the generated rule
110 # INTERFACE_NAME requested name supplied by external tool
111 # INTERFACE_NEW new interface name returned by rule writer
113 for NIC in $DEVICES; do
114 IF=${NIC##*/}
115 if echo $NIC | grep -q '*' ; then continue; fi
117 export INTERFACE=${NIC##*/} # Simple interface name
118 export MATCHADDR="$(cat $NIC/address)" # Read MAC address
120 VENDOR=$(echo $MATCHADDR | cut -c-9)
121 if ignore_if; then continue; fi
123 export MATCHDEVID="$(cat $NIC/dev_id)"
124 export MATCHIFTYPE="$(cat $NIC/type)" # Read interface type
125 comment
127 /lib/udev/write_net_rules
128 done