blob: ebcd29c5572cfd11ac66c047e2f7f47fa8583ae5 (
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#!/bin/sh
PREFIX=
. $PREFIX/lib/libalpine.sh
MAPDIR="$ROOT/usr/share/bkeymaps"
if [ -f "$ROOT/etc/conf.d/keymaps" ]; then
. "$ROOT/etc/conf.d/keymaps"
variant=$(basename "KEYMAP")
variant="${variant%%.*}"
fi
show_layouts() {
local owpd; owpd="$PWD"
cd "$MAPDIR"
ls --color=never
cd "$owpd"
}
show_variants() {
local i; for i in "$MAPDIR/$1"/* ; do
i="$(basename "$i")"
printf "%s " "${i%%.*}"
done
echo
}
select_layout() {
while true; do
if [ -z "$layout" ]; then
layout=none
fi
echo "Available keyboard layouts:"
show_layouts
echon "Select keyboard layout [$layout]: "
default_read layout "$layout"
if [ "$layout" = "abort" ] || [ "$layout" = "none" ] ; then
goodbye 0
fi
set -- $layout
if [ $# -eq 2 ]; then
layout="$1"
variant="$2"
fi
if [ -d "$MAPDIR/$layout" ] ; then
return 0
fi
done
}
setup_mapfile() {
local name=$(basename "$1")
local conf="$ROOT/etc/conf.d/keymaps"
mkdir -p "$ROOT/etc/keymap"
mkdir -p "$ROOT/etc/conf.d/"
if cp "$1" "$ROOT/etc/keymap/$name" ; then
[ -f "$conf" ] && sed -i '/^KEYMAP=/d' "$conf"
echo "KEYMAP=/etc/keymap/$name" >> "$conf"
# we actually load the keymap now
rc-service keymaps restart
rc-update -q add keymaps boot
goodbye 0
fi
}
select_variant() {
while true; do
echon "Available variants: "
show_variants "$layout"
if [ ! -f "$MAPDIR/$layout/$variant.bmap" ] ; then
variant=""
fi
echon "Select variant [$variant]: "
default_read variant "$variant"
if [ "$variant" = "abort" ] || [ "$variant" = "none" ]; then
break;
fi
if [ -f "$MAPDIR/$layout/$variant.bmap"* ]; then
setup_mapfile "$MAPDIR/$layout/$variant.bmap"*
fi
done
}
goodbye() {
apk del --quiet --no-progress .setup-keymap-deps
exit $1
}
trap 'goodbye 1' INT
apk add --quiet --virtual .setup-keymap-deps kbd-bkeymaps
deflayout="$1"
defvariant="$2"
while true; do
if [ -n "$deflayout" ]; then
layout="$deflayout"
unset deflayout
else
select_layout
fi
if [ -n "$defvariant" ]; then
variant="$defvariant"
fi
# if variant is defined, this could match, otherwise we'll have to choose a variant
if [ -f "$MAPDIR/$layout/$variant.bmap"* ]; then
setup_mapfile "$MAPDIR/$layout/$variant.bmap"*
else
# if there is only one variant, just pick it
count=$(ls "$MAPDIR"/"$layout" | wc -l)
if [ $count -eq 1 ]; then
setup_mapfile "$MAPDIR/$layout/"*
continue
fi
select_variant
fi
done
|