#!/bin/sh -euC

# Disable service, if /dev/hvc{N} does not exist. See #914788.
if ! test -c /dev/hvc0 ; then
	rm /etc/service/getty-hvc0
	exit 0
fi

if [ -x /usr/bin/fuser ] && fuser -v /dev/hvc0; then
	echo "already another process on /dev/hvc0: stopping getty-hvc0"
	exec sv d .
fi

! type fgetty >/dev/null 2>&1 || exec chpst -P fgetty hvc0
exec chpst -P getty 38400 hvc0 linux
