From c3ebdee5d008bee97f9e171ed871d336d5848a8a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 11 Apr 2019 21:14:32 -0700 Subject: [PATCH] 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 --- .../include/airootfs/etc/skel/.update_network | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.linux_items/include/airootfs/etc/skel/.update_network b/.linux_items/include/airootfs/etc/skel/.update_network index be604a52..0b66717f 100755 --- a/.linux_items/include/airootfs/etc/skel/.update_network +++ b/.linux_items/include/airootfs/etc/skel/.update_network @@ -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