summaryrefslogtreecommitdiffstats
path: root/modules.d/slx-network/scripts/udhcpc-trigger.stage3
diff options
context:
space:
mode:
authorJonathan Bauer2020-07-28 14:57:16 +0200
committerJonathan Bauer2020-07-29 12:55:52 +0200
commit092ec5bd8ea2f1913543e85287e143fe5b139103 (patch)
tree641a5b42ea72edc39a057c0202f4d4405c732604 /modules.d/slx-network/scripts/udhcpc-trigger.stage3
parent[slx-splash] reactivate systemd messages if fbsplash fails (diff)
downloadsystemd-init-092ec5bd8ea2f1913543e85287e143fe5b139103.tar.gz
systemd-init-092ec5bd8ea2f1913543e85287e143fe5b139103.tar.xz
systemd-init-092ec5bd8ea2f1913543e85287e143fe5b139103.zip
[slx-network] new style KCL
Diffstat (limited to 'modules.d/slx-network/scripts/udhcpc-trigger.stage3')
-rwxr-xr-xmodules.d/slx-network/scripts/udhcpc-trigger.stage334
1 files changed, 22 insertions, 12 deletions
diff --git a/modules.d/slx-network/scripts/udhcpc-trigger.stage3 b/modules.d/slx-network/scripts/udhcpc-trigger.stage3
index d54939a8..27c0f22a 100755
--- a/modules.d/slx-network/scripts/udhcpc-trigger.stage3
+++ b/modules.d/slx-network/scripts/udhcpc-trigger.stage3
@@ -32,26 +32,25 @@ if [ -n "$SLX_PXE_CLIENT_IP" ]; then
#...some address is already configured...
if [ "x${SLX_PXE_CLIENT_IP}" != "x${ip}" ]; then
#...it's a different one, reconfigure...
- echo "..reconfiguring ${SLX_PXE_CLIENT_IP} to ${ip}.."
+ echo "..reconfiguring '${SLX_PXE_CLIENT_IP}' to '${ip}'."
# remove default route and let it be added again below, as it might get lost when changing the primary address on the interface
ip route del default 2>/dev/null
ip addr del "$SLX_PXE_CLIENT_IP" dev "${interface}" 2>/dev/null
ip addr add "${ip}/$(ipcalc -s -p "${ip}" "${subnet}" | sed s/.*=//)" dev "${interface}"
+ echo "SLX_DHCP_CLIENT_IP='$ip'" >> "$NETWORK_CONF"
fi
else
#...no address configured yet, just add...
echo "..adding ${ip}.."
ip addr add "${ip}/$(ipcalc -s -p "${ip}" "${subnet}" | sed s/.*=//)" dev "${interface}"
fi
-echo "SLX_DHCP_CLIENT_IP='$ip'" >> "$NETWORK_CONF"
# Same procedure for default gateway
-if [ -n "${router}" ]; then
- if [ -s "$SLX_PXE_GATEWAY" ]; then
- if [ "x${SLX_PXE_GATEWAY}" != "x${router}" ]; then
- echo "..reconfiguring default gw from ${SLX_PXE_GATEWAY} to ${router}.."
- ip route replace default via "$router"
- fi
+if [ -n "$router" ]; then
+ if [ -n "$SLX_PXE_GATEWAY" ] && [ "$SLX_PXE_GATEWAY" != "$router" ]; then
+ echo "..reconfiguring default gw from '$SLX_PXE_GATEWAY' to '$router'."
+ ip route del default 2>/dev/null
+ ip route add default via "$router"
else
ip route add default via "$router"
fi
@@ -65,21 +64,30 @@ fi
rm -f -- "/etc/resolv.conf"
+reverse_lookup() {
+ [ -z "$dns" ] && return
+ [ -z "$1" ] && return
+ timeout -t 3 nslookup "$1" | grep -E "^Address +[0-9]+: +$1 " | head -n 1 | awk '{print $4}'
+}
+
+echo "# From DHCP in stage 3.1" >> "$NETWORK_CONF"
+
# DNS/domain?
if [ -n "$dns" ]; then
echo "..got DNS.."
- echo "# From DHCP in stage 3.1" >> "$NETWORK_CONF"
echo "SLX_DNS='$dns'" >> "$NETWORK_CONF"
fi
for srv in $dns; do
echo "nameserver $srv" >> "/etc/resolv.conf"
done
+
if [ -z "$domain" ]; then
# try to get domain via reverse lookup if empty
echo "..trying to get domain via DNS, as DHCP didn't supply one.."
- fqdn=$(timeout -t 3 nslookup "$ip" | grep -E "^Address +[0-9]+: +$ip " | head -n 1 | awk '{print $4}')
+ fqdn="$(reverse_lookup "$ip")"
domain="${fqdn#*.}"
fi
+
# Add domain to list of search domains if not in there yet
if [ -n "$domain" ] && [ -n "$search" ]; then
FOUND=no
@@ -90,11 +98,13 @@ if [ -n "$domain" ] && [ -n "$search" ]; then
elif [ -n "$domain" ]; then
search="$domain"
fi
+
# Write out
if [ -n "$domain" ]; then
echo "domain $domain" >> "/etc/resolv.conf"
echo "SLX_NET_DOMAIN='$domain'" >> "/run/openslx/network.conf"
fi
+
if [ -n "$search" ]; then
echo "search $search" >> "/etc/resolv.conf"
echo "SLX_NET_SEARCH='$search'" >> "/run/openslx/network.conf"
@@ -113,7 +123,7 @@ else
if [ -z "$hostname" ]; then
# as with domain, if there's no hostname, try to get via DNS
echo "..trying to get hostname via DNS, as DHCP didn't supply one.."
- [ -z "$fqdn" ] && fqdn=$(timeout -t 3 nslookup "$ip" | grep -E "^Address +[0-9]+: +$ip " | head -n 1 | awk '{print $4}')
+ [ -z "$fqdn" ] && fqdn="$(reverse_lookup "$ip")"
hostname="${fqdn%%.*}"
elif [ -n "$domain" ]; then
fqdn="${hostname}.${domain%% *}" # in case domain is a list
@@ -132,7 +142,7 @@ if [ -n "$hostname" ]; then
echo "$hostname" > "/etc/hostname"
echo "127.0.0.1 localhost" > "/etc/hosts"
echo "127.0.1.1 $fqdn $hostname" >> "/etc/hosts"
- echo "SLX_HOSTNAME='$hostname'" >> "/run/openslx/network.conf"
+ echo "SLX_HOSTNAME='$hostname'" >> "$NETWORK_CONF"
fi
touch /.network