print_usage_and_exit() {
    echo "Usage: $0 [HOSTNAME]"
    echo "HOSTNAME must be in FQDN as for example portus.suse.example.com"
    echo "If HOSTNAME is not specified, we will use the one form /etc/HOSTNAME"
    exit 0
}


if [ $# == 1 ];then
  if [ $1 == "help" ];then
    print_usage_and_exit
  fi
  if [ $1 == "-h" ];then
    print_usage_and_exit
  fi
  if [ $1 == "--help" ];then
    print_usage_and_exit
  fi
  HOSTNAME=$1
  echo "Setting hostname to $HOSTNAME"
  hostnamectl set-hostname $HOSTNAME
else
  HOSTNAME=$(hostnamectl --static status)
fi

# Write hostname to configuration files
sed -e "s/__HOSTNAME__/$HOSTNAME/g" /srv/Portus/public/landing.html.in > /srv/www/htdocs/index.html
cp /srv/Portus/public/landing.css /srv/www/htdocs/

systemctl start mysql
mysqladmin -u root password "portus"

portusctl setup --db-username=root --local-registry

if [ -e /portus-firstboot ]; then
  echo "Disabling firstboot"
  mv /portus-firstboot /portus-firstboot.disabled
fi
