summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/klibc-kbd/keymap_install
blob: e61577efd4a247c63fe6bc38594ab22bbec930d4 (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
69
70
71
72
73
74
75
76
# vim: set ft=sh:

# this is needed because kbd utilities compiled with klibc cannot use gunzip
add_ucfile ()
{
    temp=$(mktemp ${TMPDIR}/kbd.XXXX)
    dest=$(echo "${1}" | sed 's|/usr||' | sed 's|.gz||')
    name=$(echo "${1}" | sed 's|.*/||')

    if [ $(echo "${1}" | grep '.gz$') ]; then
        gunzip -c ${1} > ${temp}
        add_file ${temp} ${dest}
    else
        add_file ${1} ${dest}
    fi
}

add_includes()
{
    for i in $(zgrep -e '^include ".*"' ${1} | cut -d '"' -f 2); do
        for j in $(find /usr/share/kbd/keymaps -name "${i}" -o -name "${i}.*"); do
            add_ucfile ${j}
            add_includes ${j}
        done
    done
}

install ()
{
    MODULES=""
    BINARIES=""
    FILES=""
    SCRIPT="keymap"
    KEYMAP_FILE="$(mktemp ${TMPDIR}/keymap.XXXXXX)"
    add_file /lib/initcpio/kbd/loadkeys /bin/loadkeys
    add_file /lib/initcpio/kbd/kbd_mode /bin/kbd_mode
    add_file /lib/initcpio/kbd/setfont /bin/setfont
    eval "$(grep -e "^LOCALE=" -e "^KEYMAP=" -e "^CONSOLEFONT=" -e "^CONSOLEMAP=" /etc/rc.conf)"
    echo "KEYMAP='${KEYMAP}'" >> ${KEYMAP_FILE}
    echo "CONSOLEFONT='${CONSOLEFONT}'" >> ${KEYMAP_FILE}
    echo "CONSOLEMAP='${CONSOLEMAP}'" >> ${KEYMAP_FILE}
    if [ -n "$(echo ${LOCALE} | grep -i utf)" ]; then
        echo "UTF8='yes'" >> ${KEYMAP_FILE}
    fi
    . ${KEYMAP_FILE}
    add_file ${KEYMAP_FILE} /keymap
    if [ -n "${KEYMAP}" ]; then
        for i in $(echo ${KEYMAP}); do
            for j in $(find /usr/share/kbd/keymaps -name "${i}.map.gz"); do
                add_ucfile ${j}
                add_includes ${j}
            done
        done
    fi
    if [ -n "${CONSOLEFONT}" ]; then
        for i in $(find /usr/share/kbd/consolefonts -name "${CONSOLEFONT}.*gz"); do
            add_ucfile ${i}
        done
    fi
    if [ -n "${CONSOLEMAP}" ]; then
        for i in $(find /usr/share/kbd/unimaps -name "${CONSOLEMAP}.uni"); do
            add_ucfile ${i}
        done
        for i in $(find /usr/share/kbd/consoletrans -name "${CONSOLEMAP}.trans" -o -name "${CONSOLEMAP}"); do
            add_ucfile ${i}
        done
    fi
}

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