Subversion Repositories livecd

Rev

Rev 128 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 128 Rev 144
1
#!/bin/bash
1
#!/bin/bash
2
#
2
#
3
# chkconfig: 345 04 96
3
# chkconfig: 345 04 96
4
# description:  Noninteractive HW detection and configuration \
4
# description:  Noninteractive HW detection and configuration \
5
#               in particular configure network devices. \
5
#               in particular configure network devices. \
6
#               Used on LiveCD systems.
6
#               Used on LiveCD systems.
7
#
7
#
8
# Urs Beyerle, PSI
8
# Urs Beyerle, PSI
9
#
9
#
10
 
10
 
11
### -----------------------------------------------------------
11
### -----------------------------------------------------------
12
### definitions
12
### definitions
13
### -----------------------------------------------------------
13
### -----------------------------------------------------------
14
 
14
 
15
# dir of mounted /$MOUNTDIR/live
15
# dir of mounted /$MOUNTDIR/live
16
MOUNTDIR=livecd
16
MOUNTDIR=livecd
17
 
17
 
18
# source functions
18
# source functions
19
. /$MOUNTDIR/live/liblinuxlive
19
. /$MOUNTDIR/live/liblinuxlive
20
. /etc/init.d/functions
20
. /etc/init.d/functions
21
 
21
 
22
# do not run, if we change runlevels
22
# do not run, if we change runlevels
23
touch /var/lock/subsys/kudzu-auto
23
touch /var/lock/subsys/kudzu-auto
24
 
24
 
25
 
-
 
26
### -----------------------------------------------------------
25
### -----------------------------------------------------------
27
### Get boot parameters
26
### Get boot parameters
28
### -----------------------------------------------------------
27
### -----------------------------------------------------------
29
 
28
 
30
# do not start network
29
# do not start network
31
NONET=$( cmdline_parameter nonet )
30
NONET=$( cmdline_parameter nonet )
32
 
31
 
33
# static IP
32
# static IP
34
IPADDR=$( cmdline_value ip )
33
IPADDR=$( cmdline_value ip )
35
 
34
 
36
# gateway
35
# gateway
37
GATEWAY=$( cmdline_value gw )
36
GATEWAY=$( cmdline_value gw )
38
 
37
 
39
# netmask
38
# netmask
40
NETMASK=$( cmdline_value netmask )
39
NETMASK=$( cmdline_value netmask )
41
 
40
 
42
# start WLAN network on boot
41
# start WLAN network on boot
43
WLAN=$( cmdline_parameter wlan )
42
WLAN=$( cmdline_parameter wlan )
44
 
43
 
45
# do not apply any fixes (for debugging)
44
# do not apply any fixes (for debugging)
46
NOFIX=$( cmdline_parameter nofix )
45
NOFIX=$( cmdline_parameter nofix )
47
 
46
 
48
 
47
 
49
 
-
 
50
### -----------------------------------------------------------
48
### -----------------------------------------------------------
51
### Main
49
### Function start_kudzu_auto
52
### -----------------------------------------------------------
50
### -----------------------------------------------------------
53
 
51
 
54
### run kudzu in quiet mode
52
start_kudzu_auto() {
55
action $"Hardware auto-detection, please wait... " /usr/sbin/kudzu -q
-
 
56
 
53
 
-
 
54
    ### run kudzu in quiet mode
-
 
55
    action $"Hardware auto-detection, please wait... " /usr/sbin/kudzu -q
57
 
56
 
-
 
57
 
58
### never start on boot the following network devices (wifi0)
58
    ### never start on boot the following network devices (wifi0)
59
if [ ! $NOFIX ]; then
59
    if [ ! $NOFIX ]; then
60
    for iface in wifi0; do
60
	for iface in wifi0; do
61
	for file in networking/profiles/default/ifcfg \
61
	    for file in networking/profiles/default/ifcfg \
62
	    networking/devices/ifcfg \
62
	        	networking/devices/ifcfg \
63
	    network-scripts/ifcfg; do
63
		        network-scripts/ifcfg; do
64
	  if [ -e /etc/sysconfig/${file}-${iface} ]; then
64
	      if [ -e /etc/sysconfig/${file}-${iface} ]; then
65
	      sed -i "s/ONBOOT=.*/ONBOOT=no/" /etc/sysconfig/${file}-${iface}
65
		  sed -i "s/ONBOOT=.*/ONBOOT=no/" /etc/sysconfig/${file}-${iface}
66
	  fi
66
	      fi
-
 
67
	    done
67
	done
68
	done
68
    done
69
    fi
69
fi
-
 
70
 
70
 
71
 
71
 
72
### do not start network devices, if NONET is defined
72
    ### do not start network devices, if NONET is defined
73
if [ $NONET ]; then
73
    if [ $NONET ]; then
74
    # find all network devices (exclude loopback device)
74
        # find all network devices (exclude loopback device)
75
    config_files=$( find /etc/sysconfig -name ifcfg-* 2>/dev/null | grep -v ifcfg-lo )
75
	config_files=$( find /etc/sysconfig -name ifcfg-* 2>/dev/null | grep -v ifcfg-lo )
76
    for file in $config_files; do
76
	for file in $config_files; do
77
	sed -i "s/ONBOOT=.*/ONBOOT=no/" $file
77
	    sed -i "s/ONBOOT=.*/ONBOOT=no/" $file
78
    done
78
	done
79
fi
79
    fi
80
 
80
    
81
 
81
 
82
### define static IP and gateway, netmask
82
    ### define static IP and gateway, netmask
83
if [ $IPADDR ]; then    
83
    if [ $IPADDR ]; then    
84
    if [ ! $GATEWAY ]; then
84
	if [ ! $GATEWAY ]; then
85
	# default gatway x.y.z.1
85
            # default gatway x.y.z.1
86
	GATEWAY=$( echo $IPADDR | awk -F"." '{ print $1"."$2"."$3".1" }' )
86
	    GATEWAY=$( echo $IPADDR | awk -F"." '{ print $1"."$2"."$3".1" }' )
87
	if [ ! $NETMASK ]; then
87
	    if [ ! $NETMASK ]; then
88
	    NETMASK=255.255.255.0
88
		NETMASK=255.255.255.0
-
 
89
	    fi
89
	fi
90
	fi
-
 
91
        # create config files for eth0
-
 
92
	for iface in eth0; do
-
 
93
	    for file in networking/profiles/default/ifcfg \
-
 
94
	        	networking/devices/ifcfg \
-
 
95
		        network-scripts/ifcfg; do
-
 
96
	      sed -i "s/BOOTPROTO=.*/BOOTPROTO=none/" /etc/sysconfig/${file}-${iface}
-
 
97
	      echo "IPADDR=$IPADDR" > /etc/sysconfig/${file}-${iface}
-
 
98
	      echo "NETMASK=$NETMASK" > /etc/sysconfig/${file}-${iface}
-
 
99
	      echo "GATEWAY=$GATEWAY" > /etc/sysconfig/${file}-${iface}
-
 
100
	    done
-
 
101
	done
90
    fi
102
    fi
-
 
103
    
-
 
104
    
91
    # create config files for eth0
105
    ### activate Atheros WLAN
-
 
106
    lspci | grep -q Ethernet.*Atheros
-
 
107
    if [ "$?" = "0" ]; then
92
    for iface in eth0; do
108
        # bring ath0 up
-
 
109
	ifconfig ath0 up > /dev/null 2>&1
-
 
110
        # replace wifi0 with ath0
93
	for file in networking/profiles/default/ifcfg \
111
	for file in networking/profiles/default/ifcfg \
94
	            networking/devices/ifcfg \
112
	            networking/devices/ifcfg \
95
	            network-scripts/ifcfg; do
113
	            network-scripts/ifcfg; do
-
 
114
	  if [ -e /etc/sysconfig/${file}-wifi0 ]; then
96
	  sed -i "s/BOOTPROTO=.*/BOOTPROTO=none/" /etc/sysconfig/${file}-${iface}
115
	      mv /etc/sysconfig/${file}-wifi0 /etc/sysconfig/${file}-ath0
97
	  echo "IPADDR=$IPADDR" > /etc/sysconfig/${file}-${iface}
116
	      sed -i "s/wifi0/ath0/" /etc/sysconfig/${file}-ath0
98
	  echo "NETMASK=$NETMASK" > /etc/sysconfig/${file}-${iface}
117
	      grep -q Wireless /etc/sysconfig/${file}-ath0
99
	  echo "GATEWAY=$GATEWAY" > /etc/sysconfig/${file}-${iface}
118
	      [ "$?" != "0" ] && echo "TYPE=Wireless" >> /etc/sysconfig/${file}-ath0
-
 
119
	  fi
100
	done
120
	done
101
    done
121
    fi
102
fi
-
 
103
 
-
 
104
 
-
 
105
### activate Atheros WLAN
-
 
106
lspci | grep -q Ethernet.*Atheros
-
 
107
if [ "$?" = "0" ]; then
-
 
108
    # bring ath0 up
-
 
109
    ifconfig ath0 up > /dev/null 2>&1
-
 
110
    # replace wifi0 with ath0
-
 
111
    for file in networking/profiles/default/ifcfg \
-
 
112
	networking/devices/ifcfg \
-
 
113
	network-scripts/ifcfg; do
-
 
114
      if [ -e /etc/sysconfig/${file}-wifi0 ]; then
-
 
115
	  mv /etc/sysconfig/${file}-wifi0 /etc/sysconfig/${file}-ath0
-
 
116
	  sed -i "s/wifi0/ath0/" /etc/sysconfig/${file}-ath0
-
 
117
	  grep -q Wireless /etc/sysconfig/${file}-ath0
-
 
118
	  [ "$?" != "0" ] && echo "TYPE=Wireless" >> /etc/sysconfig/${file}-ath0
-
 
119
      fi
122
    
120
    done
123
    
121
fi
-
 
122
 
-
 
123
 
-
 
124
### configure iwl4965 Intel WLAN Chip
124
    ### configure iwl4965 Intel WLAN Chip
125
lspci | grep -q Wireless.*4965
125
    lspci | grep -q Wireless.*4965
126
if [ "$?" = "0" ]; then
-
 
127
    find /lib/modules/ 2>&1 | grep -q iwl4965.ko
-
 
128
    if [ "$?" = "0" ]; then
126
    if [ "$?" = "0" ]; then
-
 
127
	find /lib/modules/ 2>&1 | grep -q iwl4965.ko
-
 
128
	if [ "$?" = "0" ]; then
129
	grep -q iwl4965 /etc/modprobe.conf
129
	    grep -q iwl4965 /etc/modprobe.conf
130
	if [ "$?" != "0" ]; then
130
	    if [ "$?" != "0" ]; then
131
	    echo "alias wlan0 iwl4965" >> /etc/modprobe.conf
131
		echo "alias wlan0 iwl4965" >> /etc/modprobe.conf
132
	fi
132
	    fi
133
	if [ ! -e /etc/sysconfig/network-scripts/ifcfg-wlan0 ]; then
133
	    if [ ! -e /etc/sysconfig/network-scripts/ifcfg-wlan0 ]; then
134
	    cat > /etc/sysconfig/network-scripts/ifcfg-wlan0 <<EOF
134
		cat > /etc/sysconfig/network-scripts/ifcfg-wlan0 <<EOF
135
TYPE=Wireless
135
TYPE=Wireless
136
DEVICE=wlan0
136
DEVICE=wlan0
137
BOOTPROTO=dhcp
137
BOOTPROTO=dhcp
138
NETMASK=
138
NETMASK=
139
DHCP_HOSTNAME=
139
DHCP_HOSTNAME=
140
IPADDR=
140
IPADDR=
141
DOMAIN=
141
DOMAIN=
142
ONBOOT=no
142
ONBOOT=no
143
USERCTL=no
143
USERCTL=no
144
IPV6INIT=no
144
IPV6INIT=no
145
PEERDNS=yes
145
PEERDNS=yes
146
ESSID=
146
ESSID=
147
CHANNEL=6
147
CHANNEL=6
148
MODE=Managed
148
MODE=Managed
149
RATE=Auto
149
RATE=Auto
150
EOF
150
EOF
151
	    ln /etc/sysconfig/network-scripts/ifcfg-wlan0 /etc/sysconfig/networking/devices/ifcfg-wlan0
151
                ln /etc/sysconfig/network-scripts/ifcfg-wlan0 /etc/sysconfig/networking/devices/ifcfg-wlan0
152
	    ln /etc/sysconfig/network-scripts/ifcfg-wlan0 /etc/sysconfig/networking/profiles/default/ifcfg-wlan0 
152
		ln /etc/sysconfig/network-scripts/ifcfg-wlan0 /etc/sysconfig/networking/profiles/default/ifcfg-wlan0 
-
 
153
	    fi
153
	fi
154
	fi
154
    fi
155
    fi
155
fi
-
 
156
 
156
 
157
 
157
 
158
### do not start WLAN devices on boot
158
    ### do not start WLAN devices on boot
159
if [ ! $WLAN ]; then
159
    if [ ! $WLAN ]; then
160
    # find all network devices (exclude loopback device)
160
        # find all network devices (exclude loopback device)
161
    config_files=$( find /etc/sysconfig -name ifcfg-* 2>/dev/null | grep -v ifcfg-lo )
161
	config_files=$( find /etc/sysconfig -name ifcfg-* 2>/dev/null | grep -v ifcfg-lo )
162
    for file in $config_files; do
162
	for file in $config_files; do
163
	# WLAN device?
163
            # WLAN device?
164
	grep -q TYPE=Wireless $file
164
	    grep -q TYPE=Wireless $file
165
        if [ "$?" = "0" ]; then
165
	    if [ "$?" = "0" ]; then
166
	    sed -i "s/ONBOOT=.*/ONBOOT=no/" $file
166
		sed -i "s/ONBOOT=.*/ONBOOT=no/" $file
167
	fi
167
	    fi
168
    done
168
	done
-
 
169
    fi     
-
 
170
 
169
fi
171
}
-
 
172
 
-
 
173
 
-
 
174
### -----------------------------------------------------------
-
 
175
### Main
-
 
176
### -----------------------------------------------------------
-
 
177
 
-
 
178
case "$1" in
-
 
179
 start)
-
 
180
     start_kudzu_auto
-
 
181
     ;;
-
 
182
 
-
 
183
 stop)
-
 
184
     ;;
-
 
185
 
-
 
186
 *)
-
 
187
     echo $"Usage: $0 {start|stop}"
-
 
188
     exit 1
-
 
189
     ;;
170
 
190
 
-
 
191
esac