[main]
@type = oneshot
@version = @vers@
@description = "Set hostname"
@user = ( root )
@options = ( !log )

[start]
@execute =
(
	if { 66-yeller -cdp system-hostname -1 /dev/console starts... }

	# 1. Load envfile; if HOSTNAME is not empty, call s6-hostname to set the
	#    value of that variable as the new hostname
	#
	# 2. Otherwise, if /etc/hostname is present, feed the first line from
	#    that file to s6-hostname
	#
	# 3. If both fail, default to the value of def_hostname, which is set to
	#    "artixlinux" by default
	#
	if -nt {

        	execl-envfile ${conf_file}
		importas -D "" HOSTNAME HOSTNAME
		ifelse { [ -n "${HOSTNAME}" ] }
		{
			s6-hostname ${HOSTNAME}
		}
		ifelse { [ -f /etc/hostname ] }
		{
			pipeline { sed 1q /etc/hostname }
			withstdinas -E hostname s6-hostname "${hostname}"
		}
		s6-hostname ${def_hostname}

	}
	66-yeller -Wcdp system-hostname -1 /dev/console failed! -- check hostname
)

[environment]
conf_file=!@bootconf@
def_hostname=!artixlinux
