#!/bin/bash

# sourcing our current rc.conf requires this to be a bash script
. /usr/lib/rc/functions

config(){
    [ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
    TTYS=${TTYS:-6}
    _index=0
    ck_verbose && [ -n "$FONT" ] && substat "Setting font to ${FONT}"
    while [ ${_index} -le $TTYS ]; do
        if [ -n "$FONT" ]; then
            setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
                    $FONT -C "/dev/tty${_index}"
        fi
        printf "\033%s" "%G" >/dev/tty${_index}
        _index=$((_index + 1))
    done
    if [ -n "$KEYMAP" ]; then
        ck_verbose && substat "Setting keymap to ${KEYMAP}"
        loadkeys -q -u ${KEYMAP}
    fi
}

case "$1" in
    start)
        stat_busy "Starting console-setup"
        config
        add_daemon console-setup
        stat_done
        ;;
    *)
        echo "usage: $0 {start}"
        exit 1
        ;;
esac
