22 lines
452 B
Bash
Executable file
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
|
|
|