#!/usr/bin/env bash
set -euo pipefail

network_device="eth0"
gateway_host="main-ai"
gateway_port=22
nc_timeout=2
nc_wait=2

echo Disable Network Manager...
sudo stop network-manager || true

echo Disable "$network_device"...
sudo ifdown "$network_device"

echo Enable "$network_device"...
sudo ifup "$network_device"

echo Wait for response on "$gateway_host:$gateway_port"...
until nc -vzw "$nc_timeout" "$gateway_host" "$gateway_port"; do
  sleep "$nc_wait"
done
