Skip to content

Commit

Permalink
Allow active network interface to be overriden
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna committed Sep 13, 2023
1 parent 0499672 commit 8a83b62
Showing 1 changed file with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,33 +151,36 @@ env_and_envsubst '$EKSD_NAME' \
# directory containing the kickstart config
if [ "$IMAGE_FORMAT" = "ova" ] && \
( [ "$IMAGE_OS" = "redhat" ] || ( [ "$IMAGE_OS" = "ubuntu" ] && [ "$IMAGE_OS_VERSION" != "2004" ] ) ); then
echo "Finding correct interface for packer temporary http server"
ACTIVE_INTERFACE=""
if [ "$(uname -s)" = "Linux" ]; then
INTERFACES=($(ls /sys/class/net))
for interface in "${INTERFACES[@]}"; do
if [ "$interface" = "eth0" ] || [ "$interface" = "en0" ] || [ "$interface" = "eno1" ]; then
ACTIVE_INTERFACE=$interface
echo "Found interface: $interface"
break
echo "Finding correct interface for Packer temporary HTTP server"
PACKER_HTTP_SERVER_IP=${PACKER_HTTP_SERVER_IP:-}
if [ -z $PACKER_HTTP_SERVER_IP ]; then
PACKER_ACTIVE_INTERFACE="${PACKER_ACTIVE_INTERFACE:-}"
if [ -z $PACKER_ACTIVE_INTERFACE ]; then
if [ "$(uname -s)" = "Linux" ]; then
INTERFACES=($(ls /sys/class/net))
for interface in "${INTERFACES[@]}"; do
if [ "$interface" = "eth0" ] || [ "$interface" = "en0" ] || [ "$interface" = "eno1" ]; then
PACKER_ACTIVE_INTERFACE=$interface
echo "Found interface: $interface"
break
fi
done
elif [ "$(uname -s)" = "Darwin" ]; then
PACKER_ACTIVE_INTERFACE="en0"
fi
done
HTTP_SERVER_IP=$(ip a l $ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
elif [ "$(uname -s)" = "Darwin" ]; then
ACTIVE_INTERFACE="en0"
HTTP_SERVER_IP=$(ifconfig $ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
fi

if [ -z $ACTIVE_INTERFACE ]; then
echo "ACTIVE_INTERFACE cannot be an empty string. Please check your network configuration
and set an appropriate value for ACTIVE_INTERFACE"
exit 1
fi
fi

PACKER_HTTP_SERVER_IP=${PACKER_HTTP_SERVER_IP:-$HTTP_SERVER_IP}
if [ -z $PACKER_HTTP_SERVER_IP ]; then
echo "PACKER_HTTP_SERVER_IP cannot be automatically determined. Please export PACKER_HTTP_SERVER_IP=<Current Host's IP>"
exit 1
if [ -z $PACKER_ACTIVE_INTERFACE ]; then
echo "PACKER_ACTIVE_INTERFACE cannot be automatically determined. Please export PACKER_ACTIVE_INTERFACE=<Primary network interface of host>"
exit 1
fi

if [ "$(uname -s)" = "Linux" ]; then
PACKER_HTTP_SERVER_IP=$(ip a l $PACKER_ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
elif
[ "$(uname -s)" = "Darwin" ]; then
PACKER_HTTP_SERVER_IP=$(ifconfig $PACKER_ACTIVE_INTERFACE | awk '/inet / {print $2}' | cut -d/ -f1)
fi
fi

SED=sed
Expand Down

0 comments on commit 8a83b62

Please sign in to comment.