#!/bin/bash

build() {
    # subshell to avoid namespace pollution
    (
        for cfg in /etc/{rc,vconsole}.conf; do
            [[ -s $cfg ]] && . "$cfg"
        done

        [[ $FONT ]] && CONSOLEFONT=$FONT

        if [[ $CONSOLEFONT ]]; then
            for file in "/usr/share/kbd/consolefonts/$CONSOLEFONT".@(fnt|psf?(u))?(.gz); do
                if [[ -e $file ]]; then
                    [[ $file =~ (\.(fnt|psfu?))(\.gz)?$ ]] && ext=${BASH_REMATCH[2]}
                    if [[ $file = *.gz ]]; then
                        gzip -cd "$file" > "$BUILDROOT/consolefont.$ext"
                    else
                        add_file "$file" "/consolefont.$ext"
                    fi
                    exit 0
                fi
            done
            error "consolefont: requested font not found: \`%s'" "$CONSOLEFONT"
            exit 1
        else
            warning "consolefont: no font found in configuration"
            exit 1
        fi
    ) && add_runscript
}

help() {
    cat <<HELPEOF
This hook loads consolefont specified in locale.conf or rc.conf during early
userspace.
HELPEOF
}

# vim: set ft=sh ts=4 sw=4 et: