rename err to bash-bear
[automated-distro-installer] / myfai-chboot-local
index 8ab5a92117a568ec3bf259e333fc0c4b121952c8..c631d5699d073e6e27d9ccae8d8454cce7c2b8e5 100755 (executable)
@@ -34,6 +34,10 @@ while [[ $1 == -* ]]; do
       bond=true
       shift
       ;;
+    --no-r)
+      fai_reboot_arg=
+      shift
+      ;;
   esac
 done
 
@@ -44,18 +48,35 @@ err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
 
 host=$1
 
+
 rm -f /srv/tftp/fai/pxelinux.cfg/*
 if [[ ! $1 ]]; then
   echo "$0: clearing pxe config and exiting"
   exit 0
 fi
 
-# assuming ipv4, or else we might need to deal with multiple addresses
-# in an ipv4 + ipv6 network.
-my_ip=$(ip -4 route get 8.8.8.8 | sed -nr 's,^.*src\s+(\S+).*,\1,p')
-if [[ ! $my_ip || $my_ip =~ [[:space:]] ]]; then
-  echo "$0: error: failed to get \$my_ip, got: $my_ip"
-  exit 1
+# somewhat duplicated in brc hostip()
+case $host in
+  default) : ;;
+  [0-9:])
+    hostip=$host
+    ;;
+  *)
+    hostip=$(getent ahostsv4 "$host" | awk '{ print $1 }' | head -n1)
+    ;;
+esac
+
+if [[ $hostip ]]; then
+
+  # assuming ipv4, or else we might need to deal with multiple addresses
+  # in an ipv4 + ipv6 network.
+  my_ip=$(ip -4 route get $hostip | sed -nr 's,^.*src\s+(\S+).*,\1,p')
+  if [[ ! $my_ip || $my_ip =~ [[:space:]] ]]; then
+    echo "$0: error: failed to get \$my_ip, got: $my_ip"
+    exit 1
+  fi
+else
+  my_ip=$(ip r show default | sed -r 's/.*via ([^ ]*).*/\1/' | head -n1)
 fi
 
 if [[ $host == default ]]; then