#!/bin/sh
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf

# Override the variables if defined in cmdline, mimic systemd's behavior.
if [ -r /proc/cmdline ]; then
    for x in $(cat /proc/cmdline); do
        case "$x" in
            vconsole.keymap=*)      KEYMAP="${x#*=}"      ;;
            vconsole.font=*)        FONT="${x#*=}"        ;;
            vconsole.font_map=*)    FONT_MAP="${x#*=}"    ;;
            vconsole.font_unimap=*) FONT_UNIMAP="${x#*=}" ;;
        esac
    done
fi

case "$1" in
    "keyboard") [ -n "$KEYMAP" ] && loadkeys -q -u "${KEYMAP}" || : ;;
    "console")
        TTYS=${TTYS:-6}
        _index=0
        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
    ;;
esac
