From fbf22f153f415b1dfed1f01879c22b15ac030652 Mon Sep 17 00:00:00 2001 From: Don Penney Date: Mon, 10 Feb 2020 20:00:19 -0500 Subject: [PATCH] Add support for IPv6 and https to anaconda-preexec The anaconda-preexec script runs ahead of Anaconda to cache the IP address of the network boot server in the /etc/hosts file, to avoid further DNS queries during installation. This update extends the checks to add support for IPv6 and to allow for https network access. Signed-off-by: Don Penney --- scripts/anaconda-preexec | 69 +++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/scripts/anaconda-preexec b/scripts/anaconda-preexec index d491173..22e6833 100644 --- a/scripts/anaconda-preexec +++ b/scripts/anaconda-preexec @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (c) 2017 Wind River Systems, Inc. +# Copyright (c) 2017-2019 Wind River Systems, Inc. # SPDX-License-Identifier: Apache-2.0 # # @@ -14,36 +14,57 @@ set -x function get_ip() { local host=$1 + local host_ip= # Try the DNS query - host -t A $host | awk '{print $4}' | grep '^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' | head -1 + host_ip=$(host -t A $host | awk '{print $4}' | grep '^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' | head -1) + + if [ -z "${host_ip}" ]; then + # Check for IPv6 + host_ip=$(host -t AAAA $host | grep 'has IPv6 address' | awk '{print $5}') + fi + + echo -n ${host_ip} +} + +function get_server() +{ + # Check for http/https first + cat /proc/cmdline | grep -q 'inst\.ks=http' + if [ $? -ne 0 ]; then + return + fi + + local server_and_port= + server_and_port=$(cat /proc/cmdline | sed -r 's#.*inst\.ks=https*://([^/]*)/.*#\1#') + + echo "${server_and_port}" | grep -q '^\[' + if [ $? -eq 0 ]; then + echo "${server_and_port}" | sed -r 's#.*\[(.*)\].*#\1#' + else + echo "${server_and_port}" | sed -r 's#([^/:]*)(:[^/]*)?#\1#' + fi } # If the kickstart is net-based, wait for connectivity to server -cat /proc/cmdline | grep -q 'inst\.ks=http://' -if [ $? -eq 0 ] +server=$(get_server) +if [ -n "$server" ] then - server=$(cat /proc/cmdline | sed -r 's#.*inst\.ks=http://([^/:]*)(:[^/]*)?/.*#\1#') - if [ -n "$server" ] - then - echo "Testing connectivity to server: $server" - let -i ping_count=0 - ping -c 1 -w 60 $server - while [ $? -ne 0 -a $ping_count -lt 600 ] - do - echo "Waiting for connectivity to server: $server" - sleep 1 - let -i ping_count++ - ping -c 1 -w 60 $server - done - - # Cache the host IP - ipaddr=$(get_ip $server) - if [ -n "$ipaddr" -a "$ipaddr" != "$server" ] - then - echo "$ipaddr $server" >> /etc/hosts - fi + echo "Testing connectivity to server: $server" + let -i TIMEOUT=${SECONDS}+600 + ping -c 1 -w 60 $server || ping6 -c 1 -w 60 $server + while [ $? -ne 0 -a ${SECONDS} -lt ${TIMEOUT} ] + do + echo "Waiting for connectivity to server: $server" + sleep 1 + ping -c 1 -w 60 $server || ping6 -c 1 -w 60 $server + done + # Cache the host IP + ipaddr=$(get_ip $server) + if [ -n "$ipaddr" -a "$ipaddr" != "$server" ] + then + echo "$ipaddr $server" >> /etc/hosts fi fi -- 1.8.3.1