## .update_network ## #!/bin/env bash # ## Connect to network and update hostname # Connect connect-to-network sleep 2s IP="$(ip a show scope global \ | grep inet \ | head -1 \ | sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')" HOSTNAME="$(dig +noall +answer +short -x "$IP" \ | grep -v ';' \ | head -1 \ | sed 's/\.$//')" # Set hostname if [[ "${HOSTNAME:+x}" ]]; then sudo hostnamectl set-hostname "${HOSTNAME}" fi