[__hostname] Support openSUSE and replace printf with echo

This commit is contained in:
Dennis Camera 2019-10-06 21:03:49 +02:00
parent da1d70e16a
commit 064e992a7a
2 changed files with 13 additions and 11 deletions

View file

@ -31,12 +31,9 @@ fi
# Fall back to alternative OS-specific approaches.
case $("$__explorer/os")
in
alpine|archlinux|coreos|debian|devuan|suse|ubuntu)
alpine|archlinux|coreos|debian|devuan|ubuntu)
[ -f /etc/hostname ] && cat /etc/hostname
;;
suse)
[ -f /etc/HOSTNAME ] && cat /etc/HOSTNAME
;;
centos|fedora|redhat|scientific)
[ -f /etc/sysconfig/network ] \
&& (. /etc/sysconfig/network && echo "$HOSTNAME")
@ -44,6 +41,9 @@ in
freebsd)
(. /etc/rc.conf && echo "$hostname")
;;
macosx)
scutil --get HostName 2>/dev/null
;;
netbsd)
if grep -q '^hostname=' /etc/rc.conf
then
@ -57,7 +57,7 @@ in
openbsd)
cat /etc/myname
;;
macosx)
scutil --get HostName 2>/dev/null
suse)
cat /etc/HOSTNAME 2>/dev/null
;;
esac

View file

@ -75,20 +75,22 @@ fi
case $os
in
archlinux|debian|ubuntu|devuan|coreos|alpine)
printf "printf '%%s\\\\n' '$name_should' > /etc/hostname\\n"
echo "printf '%s\\n' '$name_should' > /etc/hostname"
echo "hostname -F /etc/hostname"
;;
centos|fedora|redhat|scientific|freebsd|openbsd)
# NOTE: Writing the hostname to file is done in the manifest.
echo "hostname '$name_should'"
;;
suse)
echo "hostname '$name_should'"
printf "printf '%%s\\\\n' '$name_should' > /etc/HOSTNAME\\n"
;;
macosx)
echo "scutil --set HostName '$name_should'"
;;
suse)
# We write into /etc/HOSTNAME for backwards-compatibility. Modern SuSE
# has hostnamectl anyway and symlinks /etc/HOSTNAME to /etc/hostname.
echo "printf '%s\\n' '$name_should' > /etc/HOSTNAME"
echo 'hostname -F /etc/HOSTNAME'
;;
*)
echo "echo 'Unsupported OS: $os' >&2; exit 1"
;;