#!/bin/sh
### BEGIN INIT INFO
# Provides:          console-screen
# Required-Start:    $local_fs $remote_fs
# Default-Start:     S
# Short-Description: Set console font and keymap
### END INIT INFO

set -e

test -f /bin/setupcon || exit 0

if [ -f /lib/lsb/init-functions ]; then
    . /lib/lsb/init-functions
else
    log_action_begin_msg () {
	echo -n "$@... "
    }

    log_action_end_msg () {
	if [ "$1" -eq 0 ]; then 
	    echo done.
	else
	    echo failed.
	fi
    }
fi

case "$1" in
    stop)
        # console-setup isn't a daemon
        ;;
    start|force-reload|restart|reload)
	case `readlink /proc/self/fd/2` in
	    /dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
	        log_action_begin_msg "Setting up console font and keymap"
		if setupcon; then
		    log_action_end_msg 0
		else
		    log_action_end_msg $?
		fi
		;;
	    *)
		exit 0 
		;;
	esac
	;;
    *)
        echo 'Usage: /etc/init.d/console-setup {start|reload|restart|force-reload|stop}'
        exit 1
        ;;
esac

