X-Git-Url: https://iankelling.org/git/?p=automated-distro-installer;a=blobdiff_plain;f=myfai-chboot-local;fp=myfai-chboot-local;h=c631d5699d073e6e27d9ccae8d8454cce7c2b8e5;hp=cef41c4347ea32939de34d1146808860417876be;hb=ceeb4e46d3bb326d01fcc7ed98d94ab0b580eda3;hpb=79cd04733bf570db299ef09195c498a63f3f3fd5 diff --git a/myfai-chboot-local b/myfai-chboot-local index cef41c4..c631d56 100755 --- a/myfai-chboot-local +++ b/myfai-chboot-local @@ -56,22 +56,27 @@ if [[ ! $1 ]]; then fi # somewhat duplicated in brc hostip() - case $host in - [0-9:]) - hostip=$host - ;; - *) - hostip=$(getent ahostsv4 "$host" | awk '{ print $1 }' | head -n1) - ;; - esac - - -# 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 +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