#!/bin/sh

## live-debconfig(7) - System Configuration Scripts
## Copyright (C) 2006-2013 Daniel Baumann <daniel@debian.org>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


set -e

DEBCONF_SYSTEMRC="/var/lib/live/debconfig/systemrc"
export DEBCONF_SYSTEMRC

. /usr/share/debconf/confmodule

Defaults ()
{
	if [ -z "${_HOSTNAME}" ]
	then
		if [ -n "$(cat /etc/hostname 2> /dev/null)" ]
		then
			_HOSTNAME="$(cat /etc/hostname)"
		elif [ -e /etc/os-release ]
		then
			. /etc/os-release
			_HOSTNAME="${ID:-debian}"
		elif [ -x /usr/bin/lsb_release ]
		then
			_HOSTNAME="$(lsb_release -is | tr [A-Z] [a-z])"
		elif [ -e /etc/progress-linux_version ]
		then
			_HOSTNAME="progress-linux"
		else
			_HOSTNAME="debian"
		fi
	fi
}

db_get live-debconfig/hostname/hostname
_HOSTNAME="${RET}" # string (w/o empty)

Defaults

db_set live-debconfig/hostname/hostname "${_HOSTNAME}"
db_fset live-debconfig/hostname/hostname seen false

db_settitle live-debconfig/title
db_input high live-debconfig/hostname/hostname || true
db_go

db_get live-debconfig/hostname/hostname
_HOSTNAME="${RET}" # string (w/o empty)

Defaults

db_stop

# Set the hostname
echo "${_HOSTNAME}" > /etc/hostname.tmp
mv /etc/hostname.tmp /etc/hostname
