diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-12 09:23:57 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-12 09:25:13 +0200 |
commit | 15289e8046de24df84f66fbe016722aecba5ecc2 (patch) | |
tree | 3b3f2e1df7345670dc55a3f731a55086c728f09e /setup-keymap.in | |
parent | 3a283f2fa4c2e95ad7ca75db7fde522347e17fd1 (diff) | |
download | alpine-conf-15289e8046de24df84f66fbe016722aecba5ecc2.zip |
setup-keymap: add help text. make script testable
Diffstat (limited to 'setup-keymap.in')
-rw-r--r-- | setup-keymap.in | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/setup-keymap.in b/setup-keymap.in index ae54b16..54982e8 100644 --- a/setup-keymap.in +++ b/setup-keymap.in @@ -1,7 +1,8 @@ #!/bin/sh PREFIX=@PREFIX@ -. $PREFIX/lib/libalpine.sh +: ${LIBDIR=$PREFIX/lib} +. "$LIBDIR/libalpine.sh" MAPDIR="$ROOT/usr/share/bkeymaps" @@ -11,6 +12,20 @@ if [ -f "$ROOT/etc/conf.d/loadkmap" ]; then variant="${variant%%.*}" fi +usage() { + cat <<-__EOF__ + usage: setup-keymap [-h] [LAYOUT [VARIANT]] + + Sets the system keymap layout and variant. + + options: + -h Show this help + + Sets keymap to LAYOUT (and VARIANT) or prompt if unspecified. + __EOF__ + exit $1 +} + show_layouts() { local owpd; owpd="$PWD" @@ -56,8 +71,8 @@ setup_mapfile() { [ -f "$conf" ] && sed -i '/^KEYMAP=/d' "$conf" echo "KEYMAP=/etc/keymap/$name" >> "$conf" # we actually load the keymap now - rc-service loadkmap restart - rc-update -q add loadkmap boot + $MOCK rc-service loadkmap restart + $MOCK rc-update -q add loadkmap boot goodbye 0 fi } @@ -81,12 +96,19 @@ select_variant() { } goodbye() { - apk del --quiet --no-progress .setup-keymap-deps + $MOCK apk del --quiet --no-progress .setup-keymap-deps exit $1 } +while getopts "h" opt; do + case $opt in + h) usage 0;; + esac +done +shift $(( $OPTIND - 1 )) + trap 'goodbye 1' INT -apk add --quiet --virtual .setup-keymap-deps kbd-bkeymaps +$MOCK apk add --quiet --virtual .setup-keymap-deps kbd-bkeymaps deflayout="$1" defvariant="$2" |