Use PERSISTENCE_PATH with a trailing "/".
[debian-live-boot.git] / components / 9990-netbase.sh
blob496c3ff1d6e1389341e9bb1a516fadde57355c84
1 #!/bin/sh
3 #set -e
5 Netbase ()
7 if [ -n "${NONETWORKING}" ]
8 then
9 return
12 # FIXME: stop hardcoding overloading of initramfs-tools functions
13 . /scripts/functions
14 . /lib/live/boot/9990-initramfs-tools.sh
16 log_begin_msg "Preconfiguring networking"
18 IFFILE="/root/etc/network/interfaces"
19 DNSFILE="/root/etc/resolv.conf"
21 if [ "${STATICIP}" = "frommedia" ] && [ -e "${IFFILE}" ]
22 then
23 # will use existent /etc/network/interfaces
24 log_end_msg
25 return
28 cat > "${IFFILE}" << EOF
29 auto lo
30 iface lo inet loopback
32 EOF
34 udevadm trigger
35 udevadm settle
37 if [ -z "${NETBOOT}" ] && [ -n "${STATICIP}" ] && [ "${STATICIP}" != "frommedia" ]
38 then
39 parsed=$(echo "${STATICIP}" | sed -e 's|,| |g')
41 for ifline in ${parsed}
43 ifname="$(echo ${ifline} | cut -f1 -d ':')"
44 ifaddress="$(echo ${ifline} | cut -f2 -d ':')"
45 ifnetmask="$(echo ${ifline} | cut -f3 -d ':')"
46 ifgateway="$(echo ${ifline} | cut -f4 -d ':')"
47 nameserver="$(echo ${ifline} | cut -f5 -d ':')"
49 cat >> "${IFFILE}" << EOF
50 allow-hotplug ${ifname}
51 iface ${ifname} inet static
52 address ${ifaddress}
53 netmask ${ifnetmask}
54 EOF
56 if [ -n "${ifgateway}" ]
57 then
59 cat >> "${IFFILE}" << EOF
60 gateway ${ifgateway}
62 EOF
66 if [ -n "${nameserver}" ]
67 then
68 if [ -e "${DNSFILE}" ]
69 then
70 grep -v ^nameserver "${DNSFILE}" > "${DNSFILE}.tmp"
71 mv "${DNSFILE}.tmp" "${DNSFILE}"
74 echo "nameserver ${nameserver}" >> "${DNSFILE}"
76 done
77 else
78 if [ -z "${NETBOOT}" ] || [ -n "${DHCP}" ]
79 then
80 # default, dhcp assigned
81 method="dhcp"
82 else
83 # make sure that the preconfigured interface would not get reassigned by dhcp
84 # on startup by ifup script - otherwise our root fs might be disconnected!
85 method="manual"
88 # iterate the physical interfaces and add them to the interfaces list and also add when ethdevice= called on cmdline
89 if [ "${method}" != dhcp ] || ([ ! -x /root/usr/sbin/NetworkManager ] && [ ! -x /root/usr/sbin/wicd ]) || [ ! -z "${ETHDEVICE}" ]
90 then
91 for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*
93 [ -e ${interface} ] || continue
94 i="$(basename ${interface})"
96 cat >> "${IFFILE}" << EOF
97 allow-hotplug ${i}
98 iface ${i} inet ${method}
102 done
105 if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ]
106 then
107 if [ -f /netboot.config ]
108 then
109 # create a resolv.conf if it is not present or empty
110 cp /netboot.config /root/var/log/netboot.config
112 rc_search=$(cat netboot.config | awk '/domain/ { print $3 }')
113 rc_server0="$(cat netboot.config | awk '/dns0/ { print $5 }')"
115 cat > /root/etc/resolv.conf << EOF
116 search ${rc_search}
117 domain ${rc_search}
118 nameserver ${rc_server0}
121 rc_server1=$(cat netboot.config | awk '/dns0/ { print $8 }')
123 if [ "${rc_server1}" ! = "0.0.0.0" ]
124 then
125 echo "nameserver ${rc_server1}" >> /root/etc/resolv.conf
128 cat /root/etc/resolv.conf >> /root/var/log/netboot.config
133 log_end_msg