3 # Copyright (c) 2011 Nathan Whitehorn
4 # Copyright (c) 2013-2015 Devin Teske
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ############################################################ INCLUDES
32 BSDCFG_SHARE="/usr/share/bsdconfig"
33 . $BSDCFG_SHARE/common.subr || exit 1
34 f_dprintf "%s: loading includes..." "$0"
35 f_include $BSDCFG_SHARE/dialog.subr
36 f_include $BSDCFG_SHARE/keymap.subr
37 f_include $BSDCFG_SHARE/sysrc.subr
39 ############################################################ CONFIGURATION
42 # Default file to store keymap selection in
44 : ${KEYMAPFILE:=$BSDINSTALL_TMPETC/rc.conf.keymap}
47 # Default path to keymap INDEX containing descriptions
49 : ${MAPDESCFILE:=/usr/share/syscons/keymaps/INDEX.keymaps}
51 ############################################################ GLOBALS
54 # Strings that should be moved to an i18n file and loaded with f_include_lang()
56 hline_arrows_tab_enter="Press arrows, TAB or ENTER"
57 msg_continue_with_keymap="Continue with %s keymap"
60 msg_freebsd_installer="FreeBSD Installer"
61 msg_keymap_menu_text="The system console driver for FreeBSD defaults to standard \"US\"\nkeyboard map. Other keymaps can be chosen below."
62 msg_keymap_selection="Keymap Selection"
65 msg_test_keymap="Test %s keymap"
66 msg_test_the_currently_selected_keymap="Test the currently selected keymap"
67 msg_test_the_keymap_by_typing="Test the keymap by typing letters, numbers, and symbols. Characters\nshould match labels on the keyboard keys. Press Enter to stop testing."
69 ############################################################ FUNCTIONS
71 # dialog_keymap_test $keymap
73 # Activate $keymap and display an input box (without cancel button) for the
74 # user to test keyboard input and return. Always returns success.
79 local title= # Calculated below
80 local btitle= # Calculated below
81 local prompt="$msg_test_the_keymap_by_typing"
84 # Attempt to activate the keymap
87 err=$( f_keymap_kbdcontrol "$keym" 2>&1 > /dev/null )
89 f_dialog_title "$msg_error"
90 f_dialog_msgbox "$err"
91 f_dialog_title_restore
96 f_dialog_title "$( printf "$msg_test_keymap" "${keym:-$msg_default}" )"
98 btitle="$DIALOG_BACKTITLE"
99 f_dialog_title_restore
102 f_dialog_inputbox_size height width \
103 "$title" "$btitle" "$prompt" "" "$hline"
107 --backtitle "$btitle" \
109 --ok-label "$msg_ok" \
111 --inputbox "$prompt" \
113 2>/dev/null >&$DIALOG_TERMINAL_PASSTHRU_FD
118 ############################################################ MAIN
123 f_dialog_title "$msg_keymap_selection"
124 f_dialog_backtitle "$msg_freebsd_installer"
127 # Die immediately if we can't dump the current keyboard map
129 #error=$( kbdcontrol -d 2>&1 > /dev/null ) || f_die $FAILURE "%s" "$error"
131 # Capture Ctrl-C for clean-up
132 trap 'rm -f $KEYMAPFILE; exit $FAILURE' SIGINT
134 # Get a value from rc.conf(5) as initial value (if not being scripted)
135 f_getvar $VAR_KEYMAP keymap
136 if [ ! "$keymap" ]; then
137 keymap=$( f_sysrc_get keymap )
138 case "$keymap" in [Nn][Oo]) keymap="";; esac
142 # Loop until the user has finalized their selection (by clicking the
143 # [relabeled] Cancel button).
145 width=67 first_pass=1 back_from_testing=
146 [ "$USE_XDIALOG" ] && width=70
147 prompt="$msg_keymap_menu_text"
148 hline="$hline_arrows_tab_enter"
151 # Re/Build list of keymaps
153 cont_msg=$( printf "$msg_continue_with_keymap" \
154 "${keymap:-$msg_default}" )
155 test_msg=$( printf "$msg_test_keymap" "${keymap:-$msg_default}" )
157 '>>> $cont_msg' '' '$msg_continue_with_current_keymap'
158 '->- $test_msg' '' '$msg_test_the_currently_selected_keymap'
160 if [ "$first_pass" ]; then
164 defaultitem="->- $test_msg"
166 for k in $KEYMAPS; do
167 keymap_$k get keym keym
168 keymap_$k get desc desc
170 if [ "$keym" = "$keymap" ]; then
172 if [ "$back_from_testing" ]; then
173 defaultitem="(*) $desc"
177 f_shell_escape "$desc" desc
178 menu_list="$menu_list
179 '($radio) $desc' '' '$keym: $desc'
185 # Display keymap configuration menu
187 eval f_dialog_menu_with_help_size height \"\" rows \
189 \"\$DIALOG_BACKTITLE\" \
193 menu_choice=$( eval $DIALOG \
194 --title \"\$DIALOG_TITLE\" \
195 --backtitle \"\$DIALOG_BACKTITLE\" \
196 --hline \"\$hline\" \
199 --ok-label \"\$msg_select\" \
200 --cancel-label \"\$msg_cancel\" \
201 --default-item \"\$defaultitem\" \
202 --menu \"\$prompt\" \
203 $height $width $rows \
205 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
207 f_quietly rm -f "$KEYMAPFILE"
208 exit $FAILURE # Exit with an error so bsdinstall restarts
210 f_dialog_data_sanitize menu_choice
212 case "$menu_choice" in
213 ">>> "*) # Continue with keymap
215 "->-"*) # Test keymap
216 dialog_keymap_test "$keymap"
221 # Turn the user's choice into a number
222 n=$( eval f_dialog_menutag2index_with_help \
223 \"\$menu_choice\" $menu_list )
225 # Turn that number ithe name of the keymap struct
226 k=$( set -- $KEYMAPS; eval echo \"\${$(( $n - 2))}\" )
228 # Get actual keymap setting while we update $keymap and $KEYMAPFILE
229 keymap_$k get keym keymap
230 echo "keymap=\"$keymap\"" > "$KEYMAPFILE"
233 f_quietly f_keymap_kbdcontrol "$keymap"
236 ################################################################################
238 ################################################################################