| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # This program is used to replace the command "dpkg-reconfigure console-data" because console-data is in the process of being obsoleted by console-setup. For more info, check: |
| 5 | # http://bugs.debian.org/570223 |
| 6 | |
| 7 | # |
| 8 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 9 | |
| 10 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 11 | [ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf |
| 12 | [ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions |
| 13 | |
| 14 | # Loading settings |
| 15 | [ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf |
| 16 | |
| 17 | # Settings: |
| 18 | # Before we used "console_data", however, there are some issues sometimes: |
| 19 | # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=570223 |
| 20 | # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=893612 |
| 21 | # 2018/03/21 we switch to "keyboard_configuration" which is actively developed. |
| 22 | preferred_configure="keyboard_configuration" |
| 23 | |
| 24 | # |
| 25 | run_config_from_keyboard_configuration() { |
| 26 | ask_and_load_lang_set |
| 27 | TMP="$(mktemp /tmp/keymap_mode.XXXXXX)" |
| 28 | ASK_KEYMAP=1 |
| 29 | while [ "$ASK_KEYMAP" -ne 0 ]; do |
| 30 | $DIA --nocancel --backtitle "$msg_nchc_free_software_labs" --title \ |
| 31 | "$msg_keyboard_configuration" --menu "$msg_change_keyboard_layout?" \ |
| 32 | 0 0 0 \ |
| 33 | Keep "$msg_keep_the_default_US_keymap" \ |
| 34 | Change "$msg_change_keyboard_layout" \ |
| 35 | 2> $TMP |
| 36 | keymap_mode="$(cat $TMP)" |
| 37 | if [ -z "$keymap_mode" ]; then |
| 38 | ASK_KEYMAP=1 |
| 39 | else |
| 40 | ASK_KEYMAP=0 |
| 41 | fi |
| 42 | done |
| 43 | [ -f "$TMP" ] && rm -f $TMP |
| 44 | |
| 45 | # |
| 46 | if [ "$keymap_mode" = "Change" ]; then |
| 47 | dpkg-reconfigure keyboard-configuration |
| 48 | rc=$? |
| 49 | if [ "$rc" -eq 0 ]; then |
| 50 | service keyboard-setup restart |
| 51 | setupcon -k |
| 52 | # Read the settings. Its ccontents are like: |
| 53 | # XKBMODEL="pc105" |
| 54 | # XKBLAYOUT="us" |
| 55 | # XKBVARIANT="" |
| 56 | # XKBOPTIONS="ctrl:nocaps" |
| 57 | # BACKSPACE="bs" |
| 58 | . /etc/default/keyboard |
| 59 | # Put the keyboard layout setting so that later program can reuse |
| 60 | if [ -z "$(grep -E "^[[:space:]]*live_keyboard_layouts=" /etc/ocs/ocs-live.conf 2>/dev/null)" ]; then |
| 61 | # Append it |
| 62 | echo "live_keyboard_layouts=$XKBLAYOUT" >> /etc/ocs/ocs-live.conf |
| 63 | else |
| 64 | # Modify it |
| 65 | perl -pi -e "s|^[[:space:]]*live_keyboard_layouts=.*|live_keyboard_layouts=\"$XKBLAYOUT\"|g" /etc/ocs/ocs-live.conf |
| 66 | fi |
| 67 | fi |
| 68 | fi |
| 69 | } # end of run_config_from_keyboard_configuration |
| 70 | |
| 71 | # |
| 72 | run_config_from_console_data() { |
| 73 | dpkg-reconfigure console-data |
| 74 | } # end of run_config_from_console_data |
| 75 | |
| 76 | # |
| 77 | case $preferred_configure in |
| 78 | "console_data") run_config_from_console_data ;; |
| 79 | "keyboard_configuration") run_config_from_keyboard_configuration ;; |
| 80 | esac |