diff options
Diffstat (limited to 'modules.d/slx-network/hooks/s3-parse-network-kcl.sh')
-rwxr-xr-x | modules.d/slx-network/hooks/s3-parse-network-kcl.sh | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/modules.d/slx-network/hooks/s3-parse-network-kcl.sh b/modules.d/slx-network/hooks/s3-parse-network-kcl.sh index 123d2d03..37dc7814 100755 --- a/modules.d/slx-network/hooks/s3-parse-network-kcl.sh +++ b/modules.d/slx-network/hooks/s3-parse-network-kcl.sh @@ -28,15 +28,25 @@ parse_kcl_ip() { # parse new style 'ipv4.*=...' parameters parse_kcl_ipv4() { + local param for param in "ip" "router" "dns" "hostname" "domain" "search" "if" "ntpsrv" "subnet"; do local current="$(getarg ipv4.${param}=)" - echo "KCL '$param'='$current'" + echo "ipv4.'$param'='$current'" [ -z "$current" ] && continue declare -g "${param}=${current}" done } parse_kcl() { + # backwards compat for old style hostname/dns/domain + local conf + for conf in hostname dns domain; do + conf_value="$(getarg ${conf}=)" + if [ -n "$conf_value" ]; then + echo "legacy '$conf'='$conf_value'" + declare -g "${conf}=${conf_value}" + fi + done # we assume (and we should) that both variants contain the # same information if they are present simultaneously. parse_kcl_ip @@ -59,13 +69,13 @@ parse_kcl() { # Bridged the boot interface? grep -wqE 'bridged' /proc/cmdline && declare -g bridged="y" - # backwards compat for old style hostname/dns/domain - for conf in hostname dns domain; do - conf_value="$(getarg ${conf}=)" - if [ -n "$conf_value" ]; then - declare -g "${conf}=${conf_value}" - fi - done + # Sanitize + if [[ $hostname = *.* ]]; then + [ -z "$domain" ] && domain="${hostname#*.}" + hostname="${hostname%%.*}" + echo "Fixed up to '$hostname' and '$domain'" + fi + domain="${domain%% *}" } save_network_config() { @@ -81,7 +91,8 @@ save_network_config() { SLX_PXE_NETIF='$bootif_name' SLX_PXE_DNS='${dns//,/ }' SLX_PXE_HOSTNAME='$hostname' - SLX_PXE_DOMAIN='${search//,/ }' + SLX_PXE_DOMAIN='${domain}' + SLX_PXE_SEARCH='${search//,/ }' SLX_PXE_NTP='${ntpsrv//,/ }' SLX_BRIDGE='${bridged:+${bridge_name}}' SLX_VLAN_ID='$vlan' |