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
This commit is contained in:
parent
d113d710a7
commit
c3ebdee5d0
1 changed files with 5 additions and 7 deletions
|
|
@ -1,25 +1,23 @@
|
|||
## .update_network ##
|
||||
#!/bin/env bash
|
||||
#
|
||||
## Connect to network and update hostname
|
||||
## 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
|
||||
HOSTNAME="$(dig +noall +answer +short -x "$IP" \
|
||||
NEW_HOSTNAME="$(dig +noall +answer +short -x "$IP" \
|
||||
| grep -v ';' \
|
||||
| head -1 \
|
||||
| sed 's/\.$//')"
|
||||
fi
|
||||
|
||||
# Set hostname
|
||||
if [[ "${HOSTNAME:+x}" ]]; then
|
||||
sudo hostnamectl set-hostname "${HOSTNAME}"
|
||||
if [[ "${NEW_HOSTNAME:+x}" ]]; then
|
||||
sudo hostnamectl set-hostname "${NEW_HOSTNAME}"
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue