aboutsummaryrefslogtreecommitdiff
path: root/tools/XBMCLive/live-initramfs/scripts/live-bottom/23networking
blob: 72aaf12e257505470e6e07acdc48c89785984eca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/sh

#set -e

# initramfs-tools header

PREREQ=""

prereqs()
{
	echo "${PREREQ}"
}

case "${1}" in
	prereqs)
		prereqs
		exit 0
		;;
esac

# live-initramfs header

if [ -n "${NONETWORKING}" ]
then
	exit 0
fi

. /scripts/live-functions

log_begin_msg "Preconfiguring networking"

# live-initramfs script

IFFILE="/root/etc/network/interfaces"

if [ "${STATICIP}" = "frommedia" -a -e  "${IFFILE}" ]
then
	# will use existent /etc/network/interfaces
	log_end_msg
	exit 0
fi

cat > "${IFFILE}" << EOF
auto lo
iface lo inet loopback

EOF

if [ -x /sbin/udevadm ]
then
	# lenny
	udevadm trigger
	udevadm settle
else
	# etch
	udevtrigger
	udevsettle
fi

if [ -z "${NETBOOT}" -a -n "${STATICIP}" -a "${STATICIP}" != "frommedia" ]
then
	parsed=$(echo "${STATICIP}" | sed -e 's/:/ /g')

	for ifline in ${parsed}
	do
		ifname="$(echo ${ifline} | cut -f1 -d ',')"
		ifaddress="$(echo ${ifline} | cut -f2 -d ',')"
		ifnetmask="$(echo ${ifline} | cut -f3 -d ',')"
		ifgateway="$(echo ${ifline} | cut -f4 -d ',')"

cat >> "${IFFILE}" << EOF
auto ${ifname}
iface ${ifname} inet static
    address ${ifaddress}
    netmask ${ifnetmask}
    gateway ${ifgateway}

EOF

	done
else
	if [ -z "${NETBOOT}" ]
	then
		# default, dhcp assigned
		method="dhcp"
	else
		# make sure that the preconfigured interface would not get reassigned by dhcp
		# on startup by ifup script - otherwise our root fs might be disconnected!
		method="manual"
	fi

	# iterate the physical interfaces and add them to the interfaces list
	if [ "${method}" != dhcp ] || ([ ! -x /root/usr/sbin/NetworkManager ] && [ ! -x /root/usr/sbin/wicd ])
	then
		for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*
		do
			[ -e ${interface} ] || continue
			i="$(basename ${interface})"

cat >> "${IFFILE}" << EOF
auto ${i}
iface ${i} inet ${method}

EOF

		done
	fi

	if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ]
	then
		if [ -f /netboot.config ]
		then
			# create a resolv.conf if it is not present or empty
			cp /netboot.config /root/var/log/netboot.config

			rc_search=$(cat netboot.config | awk '/domain/{print $3}')
			rc_server0=$(cat netboot.config | awk '/dns0/{print $5}')
			rc_server1=$(cat netboot.config | awk '/dns0/{print $8}')
			rc_server0="nameserver ${rc_server0}"

			if [ "${rc_server1}" = "0.0.0.0" ]
			then
				rc_server1=""
			else
				rc_server1="nameserver ${rc_server1}"
			fi

cat > /root/etc/resolv.conf << EOF
# /etc/resolv.conf
# Autogenerated by live-initramfs
search ${rc_search}
domain ${rc_search}
${rc_server0}
${rc_server1}
EOF

			cat /root/etc/resolv.conf >> /root/var/log/netboot.config
		fi
	fi
fi

#if [ ! -x /root/usr/sbin/NetworkManager ]
#then
#	for i in eth0 eth1 eth2 ath0 wlan0
#	do
#		grep -q "iface ${i}" ${IFFILE} && continue
#
#cat >> "${IFFILE}" << EOF
#auto ${i}
#iface ${i} inet dhcp
#
#EOF
#
#	done
#fi

log_end_msg