#!/usr/bin/env sh

# stupid wrapper in shell to do 
# https://github.com/gentoo/gentoo-functions/blob/master/consoletype.c
# in a more portable way such as
# ftp://distro.ibiblio.org/pub/linux/distributions/rootlinux/rootlinux-ports/base/kbd/consoletype.c
# but without the devnode approach

TERMINAL=`tty`
OS=`uname`

ret=0
case "$OS:$TERMINAL" in
	SunOS:/dev/pts*|Linux:/dev/pts*|Linux:/dev/ttyp*)
		echo pty
		ret=2
		;;
	Dawin:/dev/cu.*|SunOS:/dev/cua*|Linux/dev/cuaa*)
		echo serial
		ret=1
		;;
	*:/dev/tty*)
		echo vt
		ret=0
		;;
	*)
		echo unknown
		ret=-1
		;;
esac
test "$1" = "stdout" && ret=0
exit $ret
