summaryrefslogtreecommitdiffstats
path: root/install/sd-vconsole
blob: 011856d0a715ce4a66595291b7a74cdc8dc3de84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash

get_decompressor() {
    case "$1" in
        *.gz)
            cat=zcat
            of=${1%.gz}
            ;;
        *.bz2)
            cat=bzcat
            of=${1%.bz2}
            ;;
        *)
            cat=cat
            of=$1
            ;;
    esac
}

add_keymap_file() {
    local cat cmd rest f of

    while read f; do
        get_decompressor "$f"
        while read -r cmd rest; do
            if [[ $cmd == include ]]; then
                eval set $rest
                add_keymap_file "$1"
            fi
        done < <($cat "$f")
        add_dir "${of%/*}"
        $cat "$f" > "$BUILDROOT/$of"
    done < <(find /usr/share/kbd/keymaps/ -type f -regex ".*/$1\(\.inc\)?\(\.gz\|\.bz2\)?")
}

build() {
    add_systemd_unit systemd-vconsole-setup.service
    add_binary loadkeys
    add_binary setfont
    add_file /etc/vconsole.conf

    # subshell to avoid namespace pollution
    (
        shopt -s nullglob

        [[ -s /etc/vconsole.conf ]] && . /etc/vconsole.conf

        [[ $KEYMAP ]] && add_keymap_file $KEYMAP.map
        [[ $KEYMAP_TOGGLE ]] && add_keymap_file $KEYMAP_TOGGLE.map

        if [[ $FONT ]]; then
            for file in "/usr/share/kbd/consolefonts/$FONT".@(fnt|psf?(u))?(.gz); do
                get_decompressor "$file"
                add_dir "${of%/*}"
                $cat "$file" > "$BUILDROOT/$of"
            done
        fi
    )
}

help() {
    cat <<HELPEOF
This hook adds the keymap(s) and font specified in vconsole.conf to the image and
loads them during early userspace.
HELPEOF
}

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