|
3 | 3 |
|
4 | 4 | . /etc/default/inithooks |
5 | 5 |
|
6 | | -[ -e $INITHOOKS_CONF ] && . $INITHOOKS_CONF |
7 | | -[ -z "$IP_CONFIG" ] && exit 0 |
8 | | -[ "$IP_CONFIG" != "manual" ] && [ "$IP_CONFIG" != "static" ] && [ "$IP_CONFIG" != "dhcp" ] && exit 1 |
9 | | -[ ! -e /etc/network/interfaces ] && exit 1 |
10 | | - |
11 | | -# if IP_CONFIG is not changed skip this script and avoid a interface reconfiguration |
12 | | -grep "iface eth0 inet $IP_CONFIG" /etc/network/interfaces >/dev/null && exit 0 |
13 | | - |
14 | | -ifdown --exclude=lo -a |
15 | | - |
16 | | -# since debian 8 (systemd) ifdown does no longer take the interface down |
17 | | -# if we change between manual, static or dhcp this does not work anymore |
18 | | -# as ifup won't do anything |
19 | | -ip link set eth0 down |
20 | | - |
21 | | -echo "# interfaces(5) file used by ifup(8) and ifdown(8)" >/etc/network/interfaces |
22 | | -echo >>/etc/network/interfaces |
23 | | -echo "auto lo" >>/etc/network/interfaces |
24 | | -echo "iface lo inet loopback" >>/etc/network/interfaces |
25 | | -echo >>/etc/network/interfaces |
26 | | -echo "auto eth0" >>/etc/network/interfaces |
27 | | -echo "iface eth0 inet $IP_CONFIG" >>/etc/network/interfaces |
28 | | -echo " hostname $(head -1 /etc/hostname)" >>/etc/network/interfaces |
29 | | - |
30 | | -if [ "$IP_CONFIG" = "static" ]; then |
31 | | - echo " address $IP_ADDRESS" >>/etc/network/interfaces |
32 | | - echo " netmask $IP_NETMASK" >>/etc/network/interfaces |
33 | | - echo " gateway $IP_GW" >>/etc/network/interfaces |
34 | | - echo " dns-nameservers $IP_DNS1 $IP_DNS2" >>/etc/network/interfaces |
35 | | -fi |
| 6 | +fatal() { echo "fatal $@" >&2; exit 1; } |
| 7 | + |
| 8 | +[[ -e $INITHOOKS_CONF ]] && . $INITHOOKS_CONF |
| 9 | +[[ -z "$IP_CONFIG" ]] && exit 0 |
| 10 | +[[ "$IP_CONFIG" != "manual" ]] \ |
| 11 | + && [[ "$IP_CONFIG" != "static" ]] \ |
| 12 | + && [[ "$IP_CONFIG" != "dhcp" ]] \ |
| 13 | + && fatal "IP_CONFIG set incorrectly" |
| 14 | +[[ ! -e /etc/network/interfaces ]] && fatal "intefaces file not found" |
| 15 | + |
| 16 | +APP=$(turnkey-version -n) |
| 17 | + |
| 18 | +IP_IFACE="eth0" |
| 19 | +[[ "$APP" == "lxc" ]] && IP_IFACE="br0" |
| 20 | + |
| 21 | +# if IP_CONFIG is not changed skip this script and avoid a interface |
| 22 | +# reconfiguration |
| 23 | +grep "iface $IP_IFACE inet $IP_CONFIG" /etc/network/interfaces >/dev/null \ |
| 24 | + && exit 0 |
| 25 | + |
| 26 | +# since debian 8 (systemd) ifdown no longer takes the interface down if we |
| 27 | +# change between manual, static or dhcp so using 'ip' instead |
| 28 | +ip link set $IP_IFACE down |
| 29 | + |
| 30 | +cat > /etc/network/interfaces <<EOF |
| 31 | +# interfaces(5) file - generated by TurnKey firstboot |
| 32 | +
|
| 33 | +auto lo |
| 34 | +iface lo inet loopback |
| 35 | +
|
| 36 | +auto $IP_IFACE |
| 37 | +iface $IP_IFACE inet $IP_CONFIG |
| 38 | + hostname $(head -1 /etc/hostname) |
| 39 | +EOF |
| 40 | + |
| 41 | +if [[ "$IP_CONFIG" == "static" ]]; then |
| 42 | + cat > /etc/network/interfaces <<EOF |
| 43 | + hostname $(head -1 /etc/hostname) |
| 44 | + address $IP_ADDRESS |
| 45 | + netmask $IP_NETMASK |
| 46 | + gateway $IP_GW |
| 47 | + dns-nameservers $IP_DNS1 $IP_DNS2 |
| 48 | +EOF |
36 | 49 |
|
37 | 50 | ifup --exclude=lo -a |
38 | 51 |
|
|
0 commit comments