add option to get IF_NAME from default route

This commit is contained in:
Jesse D. McDonald 2020-05-03 03:57:40 -05:00
parent da31662b92
commit 1022b72d08
1 changed files with 8 additions and 0 deletions

View File

@ -508,6 +508,14 @@ while getopts ":i:u:d:b:f:q:c:C:p:xV" OPT; do
esac
done
if [[ "${IF_NAME}" = "DEFAULT" ]]; then
IF_NAME="$(ip -j route | jq -r 'map(select(.dst=="default"))[0].dev' 2>&1)"
if [[ "$?" -ne 0 ]]; then
>&2 echo "ERROR: failed to determine the interface name for the default route"
exit 1
fi
fi
if [[ -z ${IF_NAME} ]]; then
print_usage
exit 1