WizardKit/.linux_items/include/airootfs/etc/skel/.update_network
2019-05-05 12:53:07 -06:00

22 lines
452 B
Bash
Executable file

#!/bin/env bash
#
## Setup network and update hostname
# Wait for WiFi
sleep 1s
# 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