Skip to content

Commit 496e385

Browse files
committed
Add a hostname check for alpine and use /bin/hostname
1 parent 09f393a commit 496e385

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Diff for: lib/hostname.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ hostname () {
3434

3535
[[ $DEBUG ]] && echo "inside hostname()" >&2
3636

37+
OSTYP=$(awk -F= '/^ID=/ {print $2}' /etc/os-release | sed 's/"//g')
38+
3739
# Use standard function if Proxmox machine (Detect if running on Proxmox hypervisor by looking for /etc/pve)
3840

39-
if [ -d /etc/pve ]; then
41+
if [[ -d /etc/pve ]]; then
4042
/usr/bin/hostname "$@"
41-
elif [[ -f /etc/os-release ]] && [[ $(awk -F= '/^ID=/ {print $2}' /etc/os-release | sed 's/"//g') == openwrt ]]; then
42-
43-
# OpenWrt implementation uses uci to get to host and domain values.
44-
43+
elif [[ $OSTYP == openwrt ]]; then
4544
local _host=$($SUDO uci get system.@system[0].hostname)
4645
local _wan=$(ip route | grep default | awk '{print $9}')
4746

@@ -58,14 +57,15 @@ hostname () {
5857
fi
5958
fi
6059
fi
60+
elif [[ $OSTYP == alpine ]]; then
61+
/bin/hostname "$@"
6162
else
62-
# SystemD implementation using systemd-resolved.
6363
if [[ -z $1 ]]; then
6464
uname -n
6565
elif [[ $1 == "-f" ]]; then
6666
get_fqdn
6767
else
68-
/usr/bin/hostname "$@" # Pass other arguments to the system hostname command
68+
/usr/bin/hostname "$@"
6969
fi
7070
fi
7171
}

0 commit comments

Comments
 (0)