|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +## Copyright (c) 2019 - 2025 ENCRYPTED SUPPORT LLC <[email protected]> |
| 4 | +## See the file COPYING for copying conditions. |
| 5 | + |
| 6 | +#set -x |
| 7 | + |
| 8 | +true "usability-misc $0: START" |
| 9 | + |
| 10 | +set -e |
| 11 | + |
| 12 | +if ! [ -d /boot/grub/kb_layouts ]; then |
| 13 | + exit 0 |
| 14 | +fi |
| 15 | + |
| 16 | +printf '%s\n' "\ |
| 17 | +function load_kb_layout { |
| 18 | + kb_layout_name=\"\$1\" |
| 19 | +
|
| 20 | + if [ x\$kb_layout_name = x ]; then |
| 21 | + echo \"No keyboard layout specified! Press 'Enter' to continue.\" |
| 22 | + read |
| 23 | + return 1 |
| 24 | + fi |
| 25 | +
|
| 26 | + if ! [ -f \"\${prefix}/kb_layouts/\${kb_layout_name}.gkb\" ]; then |
| 27 | + echo \"Keyboard layout '\$kb_layout_name' does not exist! Press 'Enter' to continue.\" |
| 28 | + read |
| 29 | + return 1 |
| 30 | + fi |
| 31 | +
|
| 32 | + echo \"Switching keyboard layouts may cause the keyboard to malfunction or\" |
| 33 | + echo \"become unresponsive. If this occurs, force-reboot the machine to\" |
| 34 | + echo \"fix this.\" |
| 35 | + echo |
| 36 | + if ! terminal_input at_keyboard; then |
| 37 | + echo \"Could not enable at_keyboard driver! Press 'Enter' to continue.\" |
| 38 | + read |
| 39 | + return 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + if ! keymap \"\${prefix}/kb_layouts/\${kb_layout_name}.gkb\"; then |
| 43 | + echo \"Could not load keyboard layout '\$kb_layout_name'! Press 'Enter' to continue.\" |
| 44 | + read |
| 45 | + return 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + echo \"Keyboard layout '\$kb_layout_name' loaded. Press 'Enter' to continue.\" |
| 49 | + read |
| 50 | + return 0 |
| 51 | +} |
| 52 | +
|
| 53 | +submenu 'Keyboard layout options' \$menuentry_id_option 'kb-layout-options' {" |
| 54 | + |
| 55 | +if [ -f /boot/grub/kb_layouts/user-layout.gkb ]; then |
| 56 | + if [ -f /boot/grub/kb_layouts/user-layout.name ]; then |
| 57 | + user_layout_name="$(cat /boot/grub/kb_layouts/user-layout.name)" || { user_layout_name='unknown'; true; } |
| 58 | + else |
| 59 | + user_layout_name='unknown' |
| 60 | + fi |
| 61 | + |
| 62 | + printf '%s\n' "\ |
| 63 | + menuentry \"SWITCH to user-defined keyboard layout '$user_layout_name'\" \$menuentry_id_option 'switch-kb-layout-user-defined' { |
| 64 | + load_kb_layout 'user-layout' |
| 65 | + }" |
| 66 | +fi |
| 67 | + |
| 68 | +for layout_file in /boot/grub/kb_layouts/*.gkb; do |
| 69 | + if ! [ -f "$layout_file" ]; then |
| 70 | + continue |
| 71 | + fi |
| 72 | + if [ "$layout_file" = '/boot/grub/kb_layouts/user-layout.gkb' ]; then |
| 73 | + continue |
| 74 | + fi |
| 75 | + layout_name="$(basename "$layout_file" | sed 's/\..*//')" |
| 76 | + printf '%s\n' "\ |
| 77 | + menuentry \"SWITCH to layout '$layout_name'\" \$menuentry_id_option 'switch-kb-layout-$layout_name' { |
| 78 | + load_kb_layout '$layout_name' |
| 79 | + }" |
| 80 | +done |
| 81 | + |
| 82 | +printf '%s\n' "\ |
| 83 | +} |
| 84 | +" |
| 85 | + |
| 86 | +true "usability-misc $0: END" |
0 commit comments