[SeamlessDomainJoin]: Dynamically get network interface name
Some instances do not use 'eth0' as interface name, this change derives the interface name.
cr:
@@ -551,12 +551,13 @@ print_vars() {
# Unable to perform DNS Update. #
#########################################################
configure_hosts_file() {
- fullhost="${COMPUTER_NAME}.${DIRECTORY_NAME}" # ,, means lowercase since bash v4
- ip_address="$(ip -o -4 addr show eth0 | awk '{print $4}' | cut -d/ -f1)"
- cleanup_comment='# Generated by Domain Join SSMDocument'
+ FULLHOST="${COMPUTER_NAME}.${DIRECTORY_NAME}" # ,, means lowercase since bash v4
+ IF_NAME=$(ip route list | grep default | grep -E 'dev (\w+)' -o | awk '{print $2}')
+ IP_ADDRESS="$(ip -o -4 addr show "$IF_NAME" | awk '{print $4}' | cut -d/ -f1)"
+ CLEANUP_COMMENT='# Generated by Domain Join SSMDocument'
sed -i".orig" -r\
- "/^.*${cleanup_comment}/d;\
- /^127.0.0.1\s+localhost\s*/a\\${ip_address} ${fullhost} ${COMPUTER_NAME} ${cleanup_comment}" /etc/hosts
+ "/^.*${CLEANUP_COMMENT}/d;\
+ /^127.0.0.1\s+localhost\s*/a\\${IP_ADDRESS} ${FULLHOST} ${COMPUTER_NAME} ${CLEANUP_COMMENT}" /etc/hosts
}
#########################################################
