File check-hostname.sh of Package kolab-scripts

#!/bin/bash
# KPS_CHECK_ORDER: 20

# (c) 2013-2016 Aeneas Jaissle <aj@ajaissle.de>
# (c) 2013 Richard Bos

PATH=/usr/bin:/bin
echo -n "Checking for FQDN... "

# The FQDN must be known in the network stack to be able to install
# kolab with kolab-setup.
# See /usr/share/doc/packages/kolab/why-your-system-should-have-proper-fqdn
# for more information about this topic.
#
# Guide the user through the FQDN configuration.  The check used to
# start with the command 'hostname -f', but when the FQDN is not
# configured (for whatever reason) in /etc/hosts or the somewhere else
# in the network stack, the following error was (is) returned:
#   "hostname: unknown name of service"
# This seems to imply that the hostname binary is not present, which
# is confusing as the binary is available.  To prevent this the
# FQDN setting is verified step by step in the code below.

# A FQDN should consist of at least 3 parts (hostname, domain and
# a toplevel domain (tld).
DOMAIN_PARTS=$(hostname -f | awk -F. '{print NF}')

if [[ $DOMAIN_PARTS -ge 3 ]]; then

  # The name is locally known, but is it known in the network stack?
  if grep -q $(hostname) /etc/hosts; then
    echo "OK ($(hostname))"
    CHECK=OK
    ADVICE=
  else
    HOSTNAME=$(hostname --fqdn 2>/dev/null)
    if [[ -n "$HOSTNAME" ]]; then
      echo "OK ($HOSTNAME)"
      CHECK=OK
      ADVICE=
    else
      echo
      echo "  The FQDN is not found, not in /etc/hosts nor in the network"
      echo "  stack (DNS).  Use for example 'hostname -f' to verify."
    fi
  fi 
  
else

  # (/bin/)hostname does not always provide an FQDN, even if an FQDN has been
  # configured.  This is often the case after changes have been made to the
  # network configuration with yast.  Hence, do an additional check.
  if [[ -f /etc/HOSTNAME ]]; then
    DOMAIN_PARTS=$(awk -F. '{print NF}' /etc/HOSTNAME)
    if [[ $DOMAIN_PARTS -ge 3 ]]; then
      echo OK
      CHECK=OK
      ADVICE=boot
    fi
  fi

  if [[ "$CHECK" != "OK" ]]; then
    echo
    echo "  error: no fully qualified domain name: $(hostname)"
    echo "    There should at least be 3 domain parts.  Without this Kolab might not work"
    echo "    correctly, as explained in the following article:"
    echo "    /usr/share/doc/packages/kolab/why-your-system-should-have-proper-fqdn"
    echo "  Run 'yast2 lan' -> tab 'Hostname/DNS' to configure the domain name."
  
    read -p "  Do you want to run 'yast2 lan' now? [Y/n] " ANSWER
    if [[ "$ANSWER" != "n" ]]; then
      /sbin/yast2 lan
      ADVICE=boot
    fi
  fi

  if [[ "$ADVICE" == "boot" ]]; then
    echo
    echo "NOTE: due to the current network configuration, it is strongly adviced"
    echo "      to reboot the system.  After the reboot; run kolab-pre-setup once"
    echo "      more, this note should not be displayed anymore."
    echo
  fi
fi

openSUSE Build Service is sponsored by