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}
46 ############################################################ GLOBALS
49 # Strings that should be moved to an i18n file and loaded with f_include_lang()
51 hline_arrows_tab_enter="Press arrows, TAB or ENTER"
52 msg_continue_with_keymap="Continue with %s keymap"
55 msg_freebsd_installer="FreeBSD Installer"
56 msg_keymap_menu_text="The system console driver for FreeBSD defaults to standard \"US\"\nkeyboard map. Other keymaps can be chosen below."
57 msg_keymap_selection="Keymap Selection"
60 msg_test_keymap="Test %s keymap"
61 msg_test_the_currently_selected_keymap="Test the currently selected keymap"
62 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."
64 ############################################################ FUNCTIONS
66 # dialog_keymap_test $keymap
68 # Activate $keymap and display an input box (without cancel button) for the
69 # user to test keyboard input and return. Always returns success.
74 local title= # Calculated below
75 local btitle= # Calculated below
76 local prompt="$msg_test_the_keymap_by_typing"
79 # Attempt to activate the keymap
82 err=$( f_keymap_kbdcontrol "$keym" 2>&1 > /dev/null )
84 f_dialog_title "$msg_error"
85 f_dialog_msgbox "$err"
86 f_dialog_title_restore
91 f_dialog_title "$( printf "$msg_test_keymap" "${keym:-$msg_default}" )"
93 btitle="$DIALOG_BACKTITLE"
94 f_dialog_title_restore
97 f_dialog_inputbox_size height width \
98 "$title" "$btitle" "$prompt" "" "$hline"
102 --backtitle "$btitle" \
104 --ok-label "$msg_ok" \
106 --inputbox "$prompt" \
108 2>/dev/null >&$DIALOG_TERMINAL_PASSTHRU_FD
113 ############################################################ MAIN
118 f_dialog_title "$msg_keymap_selection"
119 f_dialog_backtitle "$msg_freebsd_installer"
122 # Die immediately if we can't dump the current keyboard map
124 #error=$( kbdcontrol -d 2>&1 > /dev/null ) || f_die $FAILURE "%s" "$error"
126 # Capture Ctrl-C for clean-up
127 trap 'rm -f $KEYMAPFILE; exit $FAILURE' SIGINT
129 # Get a value from rc.conf(5) as initial value (if not being scripted)
130 f_getvar $VAR_KEYMAP keymap
131 if [ ! "$keymap" ]; then
132 keymap=$( f_sysrc_get keymap )
133 case "$keymap" in [Nn][Oo]) keymap="";; esac
137 # Loop until the user has finalized their selection (by clicking the
138 # [relabeled] Cancel button).
140 width=67 first_pass=1 back_from_testing=
141 [ "$USE_XDIALOG" ] && width=70
142 prompt="$msg_keymap_menu_text"
143 hline="$hline_arrows_tab_enter"
146 # Re/Build list of keymaps
148 cont_msg=$( printf "$msg_continue_with_keymap" \
149 "${keymap:-$msg_default}" )
150 test_msg=$( printf "$msg_test_keymap" "${keymap:-$msg_default}" )
152 '>>> $cont_msg' '' '$msg_continue_with_current_keymap'
153 '->- $test_msg' '' '$msg_test_the_currently_selected_keymap'
155 if [ "$first_pass" ]; then
159 defaultitem="->- $test_msg"
161 for k in $KEYMAPS; do
162 keymap_$k get keym keym
163 keymap_$k get desc desc
165 if [ "$keym" = "$keymap" ]; then
167 if [ "$back_from_testing" ]; then
168 defaultitem="(*) $desc"
172 f_shell_escape "$desc" desc
173 menu_list="$menu_list
174 '($radio) $desc' '' '$keym: $desc'
180 # Display keymap configuration menu
182 eval f_dialog_menu_with_help_size height \"\" rows \
184 \"\$DIALOG_BACKTITLE\" \
188 menu_choice=$( eval $DIALOG \
189 --title \"\$DIALOG_TITLE\" \
190 --backtitle \"\$DIALOG_BACKTITLE\" \
191 --hline \"\$hline\" \
194 --ok-label \"\$msg_select\" \
195 --cancel-label \"\$msg_cancel\" \
196 --default-item \"\$defaultitem\" \
197 --menu \"\$prompt\" \
198 $height $width $rows \
200 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
202 f_quietly rm -f "$KEYMAPFILE"
203 exit $FAILURE # Exit with an error so bsdinstall restarts
205 f_dialog_data_sanitize menu_choice
207 case "$menu_choice" in
208 ">>> "*) # Continue with keymap
210 "->-"*) # Test keymap
211 dialog_keymap_test "$keymap"
216 # Turn the user's choice into a number
217 n=$( eval f_dialog_menutag2index_with_help \
218 \"\$menu_choice\" $menu_list )
220 # Turn that number ithe name of the keymap struct
221 k=$( set -- $KEYMAPS; eval echo \"\${$(( $n - 2))}\" )
223 # Get actual keymap setting while we update $keymap and $KEYMAPFILE
224 keymap_$k get keym keymap
225 echo "keymap=\"$keymap\"" > "$KEYMAPFILE"
228 f_quietly f_keymap_kbdcontrol "$keymap"
231 ################################################################################
233 ################################################################################