WizardKit/.linux_items/include/airootfs/etc/skel/.update_network
2Shirt c3ebdee5d0
Only update hostname when necessary
* If $IP was empty then HOSTNAME would remain set to the current HOSTNAME
  * This allowed the redundant set-hostname call
2019-04-11 21:14:32 -07:00

23 lines
520 B
Bash
Executable file

#!/bin/env bash
#
## Setup network and update hostname
# Add saved networks to NetworkManager
sudo setup-wifi
sudo systemctl restart NetworkManager
# Set hostname
IP="$(ip a show scope global \
| grep inet \
| head -1 \
| sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')"
if [[ "${IP:+x}" ]]; then
NEW_HOSTNAME="$(dig +noall +answer +short -x "$IP" \
| grep -v ';' \
| head -1 \
| sed 's/\.$//')"
fi
if [[ "${NEW_HOSTNAME:+x}" ]]; then
sudo hostnamectl set-hostname "${NEW_HOSTNAME}"
fi