#!/bin/sh -euC

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

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

NOCLEAR=
DEBKERN=linux
GETTY=${PWD##*-}
#Hurd?
if [ $(uname -s) = 'GNU' ]; then DEBKERN= ; fi
if [ "$GETTY" = 'tty1' ]; then NOCLEAR=--noclear ; fi

! type fgetty >/dev/null 2>&1 || exec chpst -P fgetty tty5
exec chpst -P getty ${NOCLEAR:-} 38400 tty5 ${DEBKERN:-}
