keymap revision 251190
1#!/bin/sh 2#- 3# Copyright (c) 2012-2013 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD: head/usr.sbin/bsdconfig/console/keymap 251190 2013-05-31 19:07:17Z dteske $ 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." "$0" 34f_include $BSDCFG_SHARE/dialog.subr 35f_include $BSDCFG_SHARE/mustberoot.subr 36f_include $BSDCFG_SHARE/sysrc.subr 37 38BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" 39f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40 41ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 42[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 43 44############################################################ CONFIGURATION 45 46# 47# List of keymap names 48# 49KEYMAP_NAMES=" 50 belgian brazil_cp850 brazil_iso 51 brazil_iso_accent bulgarian_bds bulgarian_phonetic 52 central_european_iso croatian_iso czech_iso_accent 53 danish_cp865 danish_iso estonian_cp850 54 estonian_iso estonian_iso_15 finnish_cp850 55 finnish_iso french_iso french_iso_accent 56 french_iso_macbook german_cp850 german_iso 57 greek_101 greek_104 greek_elot 58 hungarian_101 hungarian_102 icelandic 59 icelandic_accent italian japanese_106 60 latin_american latin_american_accent norway_iso 61 polish_iso portuguese portuguese_accent 62 russia_koi8_r slovak slovenian 63 spanish spanish_accent swedish_cp850 64 swedish_iso swiss_french_cp850 swiss_french_iso 65 swiss_french_iso_accent swiss_german_cp850 swiss_german_iso 66 swiss_german_iso_accent uk_cp850 uk_iso 67 ukrainian_koi8_u ukrainian_koi8_u_koi8_r usa_capslock_ctrl 68 usa_dvorak usa_dvorak_left usa_dvorak_right 69 usa_emacs usa_iso usa_unix 70" # END-QUOTE 71 72############################################################ FUNCTIONS 73 74# dialog_menu_main 75# 76# Display the dialog(1)-based application main menu. 77# 78dialog_menu_main() 79{ 80 local menu_list defaultitem= 81 local hline="$hline_choose_a_keyboard_map" 82 local prompt="$msg_keymap_menu_text" 83 84 # 85 # Export variables for awk(1) ENVIRON visibility 86 # 87 local name 88 for name in $KEYMAP_NAMES; do 89 export msg_$name msg_${name}_desc 90 done 91 92 # 93 # Generate a sorted list of keymaps. If the first letter of the keymap 94 # name is unique (case-insensitive) then it is used as the tag to allow 95 # the user to jump to that entry. 96 # 97 menu_list=$( 98 for name in $KEYMAP_NAMES; do 99 eval echo \"\$msg_$name\" msg_$name 100 done | sort | awk 'BEGIN { prefix = "" } 101 { 102 cur_prefix = tolower(substr(ENVIRON[$NF], 1, 1)) 103 printf "'\''" 104 if ( prefix != cur_prefix ) 105 prefix = cur_prefix 106 else 107 printf " " 108 printf "%s'\'' '\''%s'\''\n", 109 ENVIRON[$NF], ENVIRON[$NF"_desc"] 110 }' 111 ) 112 113 local height width rows 114 eval f_dialog_menu_size height width rows \ 115 \"\$DIALOG_TITLE\" \ 116 \"\$DIALOG_BACKTITLE\" \ 117 \"\$prompt\" \ 118 \"\$hline\" \ 119 $menu_list 120 121 case "$( f_sysrc_get keymap )" in 122 be.iso) defaultitem="$msg_belgian";; 123 br275.cp850) defaultitem="$msg_brazil_cp850";; 124 br275.iso) defaultitem="$msg_brazil_iso";; 125 br275.iso.acc) defaultitem="$msg_brazil_iso_accent";; 126 bg.bds.ctrlcaps) defaultitem="$msg_bulgarian_bds";; 127 bg.phonetic.ctrlcaps) defaultitem="$msg_bulgarian_phonetic";; 128 ce.iso2) defaultitem="$msg_central_european_iso";; 129 hr.iso) defaultitem="$msg_croatian_iso";; 130 cs.latin2.qwertz) defaultitem="$msg_czech_iso_accent";; 131 danish.cp865) defaultitem="$msg_danish_cp865";; 132 danish.iso) defaultitem="$msg_danish_iso";; 133 estonian.cp850) defaultitem="$msg_estonian_cp850";; 134 estonian.iso) defaultitem="$msg_estonian_iso";; 135 estonian.iso15) defaultitem="$msg_estonian_iso_15";; 136 finnish.cp850) defaultitem="$msg_finnish_cp850";; 137 finnish.iso) defaultitem="$msg_finnish_iso";; 138 fr.iso) defaultitem="$msg_french_iso";; 139 fr.iso.acc) defaultitem="$msg_french_iso_accent";; 140 fr.macbook.acc) defaultitem="$msg_french_iso_macbook";; 141 german.cp850) defaultitem="$msg_german_cp850";; 142 german.iso) defaultitem="$msg_german_iso";; 143 gr.us101.acc) defaultitem="$msg_greek_101";; 144 el.iso07) defaultitem="$msg_greek_104";; 145 gr.elot.acc) defaultitem="$msg_greek_elot";; 146 hu.iso2.101keys) defaultitem="$msg_hungarian_101";; 147 hu.iso2.102keys) defaultitem="$msg_hungarian_102";; 148 icelandic.iso) defaultitem="$msg_icelandic";; 149 icelandic.iso.acc) defaultitem="$msg_icelandic_accent";; 150 it.iso) defaultitem="$msg_italian";; 151 jp.106) defaultitem="$msg_japanese_106";; 152 latinamerican) defaultitem="$msg_latin_american";; 153 latinamerican.iso.acc) defaultitem="$msg_latin_american_accent";; 154 norwegian.iso) defaultitem="$msg_norway_iso";; 155 pl_PL.ISO8859-2) defaultitem="$msg_polish_iso";; 156 pt.iso) defaultitem="$msg_portuguese";; 157 pt.iso.acc) defaultitem="$msg_portuguese_accent";; 158 ru.koi8-r) defaultitem="$msg_russia_koi8_r";; 159 sk.iso2) defaultitem="$msg_slovak";; 160 si.iso) defaultitem="$msg_slovenian";; 161 spanish.iso) defaultitem="$msg_spanish";; 162 spanish.iso.acc) defaultitem="$msg_spanish_accent";; 163 swedish.cp850) defaultitem="$msg_swedish_cp850";; 164 swedish.iso) defaultitem="$msg_swedish_iso";; 165 swissfrench.cp850) defaultitem="$msg_swiss_french_cp850";; 166 swissfrench.iso) defaultitem="$msg_swiss_french_iso";; 167 swissfrench.iso.acc) defaultitem="$msg_swiss_french_iso_accent";; 168 swissgerman.cp850) defaultitem="$msg_swiss_german_cp850";; 169 swissgerman.iso) defaultitem="$msg_swiss_german_iso";; 170 swissgerman.iso.acc) defaultitem="$msg_swiss_german_iso_accent";; 171 uk.cp850) defaultitem="$msg_uk_cp850";; 172 uk.iso) defaultitem="$msg_uk_iso";; 173 ua.koi8-u) defaultitem="$msg_ukrainian_koi8_u";; 174 ua.koi8-u.shift.alt) defaultitem="$msg_ukrainian_koi8_u_koi8_r";; 175 us.pc-ctrl) defaultitem="$msg_usa_capslock_ctrl";; 176 us.dvorak) defaultitem="$msg_usa_dvorak";; 177 us.dvorakl) defaultitem="$msg_usa_dvorak_left";; 178 us.dvorakr) defaultitem="$msg_usa_dvorak_right";; 179 us.emacs) defaultitem="$msg_usa_emacs";; 180 us.iso) defaultitem="$msg_usa_iso";; 181 us.unix) defaultitem="$msg_usa_unix";; 182 esac 183 184 # The defaultitem may have to be indented to match the menu_list 185 if [ "$defaultitem" ]; then 186 ( eval set -- $menu_list 187 while [ $# -gt 0 ]; do 188 [ "$defaultitem" = "$1" ] && break 189 [ " $defaultitem" = "$1" ] && exit 0 190 shift 2 # tag/item 191 done 192 exit 1 # No modification needed 193 ) && defaultitem=" $defaultitem" 194 fi 195 196 local dialog_menu 197 dialog_menu=$( eval $DIALOG \ 198 --title \"\$DIALOG_TITLE\" \ 199 --backtitle \"\$DIALOG_BACKTITLE\" \ 200 --hline \"\$hline\" \ 201 --ok-label \"\$msg_ok\" \ 202 --cancel-label \"\$msg_cancel\" \ 203 --default-item \"\$defaultitem\" \ 204 --menu \"\$prompt\" \ 205 $height $width $rows \ 206 $menu_list \ 207 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 208 ) 209 local retval=$? 210 setvar DIALOG_MENU_$$ "$dialog_menu" 211 return $retval 212} 213 214############################################################ MAIN 215 216# Incorporate rc-file if it exists 217[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 218 219# 220# Process command-line arguments 221# 222while getopts h$GETOPTS_STDARGS flag; do 223 case "$flag" in 224 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 225 esac 226done 227shift $(( $OPTIND - 1 )) 228 229# 230# Initialize 231# 232f_dialog_title "$msg_system_console_keymap" 233f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 234f_mustberoot_init 235 236# 237# Launch application main menu 238# 239while :; do 240 dialog_menu_main 241 retval=$? 242 mtag=$( f_dialog_menutag ) 243 244 [ $retval -eq 0 ] || f_die 245 246 # 247 # Reverse the users choice into the variable name 248 # 249 keymap_name= 250 mtag="${mtag# }" # remove single leading-space if-present 251 for name in $KEYMAP_NAMES; do 252 if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 253 keymap_name="$name" 254 break 255 fi 256 done 257 258 [ "$keymap_name" ] || continue 259 260 case "$keymap_name" in 261 belgian) 262 f_sysrc_set keymap "be.iso" || f_die 263 break ;; 264 brazil_cp850) 265 f_sysrc_set keymap "br275.cp850" || f_die 266 break ;; 267 brazil_iso) 268 f_sysrc_set keymap "br275.iso" || f_die 269 break ;; 270 brazil_iso_accent) 271 f_sysrc_set keymap "br275.iso.acc" || f_die 272 break ;; 273 bulgarian_bds) 274 f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 275 break ;; 276 bulgarian_phonetic) 277 f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 278 break ;; 279 central_european_iso) 280 f_sysrc_set keymap "ce.iso2" || f_die 281 break ;; 282 croatian_iso) 283 f_sysrc_set keymap "hr.iso" || f_die 284 break ;; 285 czech_iso_accent) 286 f_sysrc_set keymap "cs.latin2.qwertz" || f_die 287 break ;; 288 danish_cp865) 289 f_sysrc_set keymap "danish.cp865" || f_die 290 break ;; 291 danish_iso) 292 f_sysrc_set keymap "danish.iso" || f_die 293 break ;; 294 estonian_cp850) 295 f_sysrc_set keymap "estonian.cp850" || f_die 296 break ;; 297 estonian_iso) 298 f_sysrc_set keymap "estonian.iso" || f_die 299 break ;; 300 estonian_iso_15) 301 f_sysrc_set keymap "estonian.iso15" || f_die 302 break ;; 303 finnish_cp850) 304 f_sysrc_set keymap "finnish.cp850" || f_die 305 break ;; 306 finnish_iso) 307 f_sysrc_set keymap "finnish.iso" || f_die 308 break ;; 309 french_iso) 310 f_sysrc_set keymap "fr.iso" || f_die 311 break ;; 312 french_iso_accent) 313 f_sysrc_set keymap "fr.iso.acc" || f_die 314 break ;; 315 french_iso_macbook) 316 f_sysrc_set keymap "fr.macbook.acc" || f_die 317 break ;; 318 german_cp850) 319 f_sysrc_set keymap "german.cp850" || f_die 320 break ;; 321 german_iso) 322 f_sysrc_set keymap "german.iso" || f_die 323 break ;; 324 greek_101) 325 f_sysrc_set keymap "gr.us101.acc" || f_die 326 break ;; 327 greek_104) 328 f_sysrc_set keymap "el.iso07" || f_die 329 break ;; 330 greek_elot) 331 f_sysrc_set keymap "gr.elot.acc" || f_die 332 break ;; 333 hungarian_101) 334 f_sysrc_set keymap "hu.iso2.101keys" || f_die 335 break ;; 336 hungarian_102) 337 f_sysrc_set keymap "hu.iso2.102keys" || f_die 338 break ;; 339 icelandic) 340 f_sysrc_set keymap "icelandic.iso" || f_die 341 break ;; 342 icelandic_accent) 343 f_sysrc_set keymap "icelandic.iso.acc" || f_die 344 break ;; 345 italian) 346 f_sysrc_set keymap "it.iso" || f_die 347 break ;; 348 japanese_106) 349 f_sysrc_set keymap "jp.106" || f_die 350 break ;; 351 latin_american) 352 f_sysrc_set keymap "latinamerican" || f_die 353 break ;; 354 latin_american_accent) 355 f_sysrc_set keymap "latinamerican.iso.acc" || f_die 356 break ;; 357 norway_iso) 358 f_sysrc_set keymap "norwegian.iso" || f_die 359 break ;; 360 polish_iso) 361 f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 362 break ;; 363 portuguese) 364 f_sysrc_set keymap "pt.iso" || f_die 365 break ;; 366 portuguese_accent) 367 f_sysrc_set keymap "pt.iso.acc" || f_die 368 break ;; 369 russia_koi8_r) 370 f_sysrc_set keymap "ru.koi8-r" || f_die 371 break ;; 372 slovak) 373 f_sysrc_set keymap "sk.iso2" || f_die 374 break ;; 375 slovenian) 376 f_sysrc_set keymap "si.iso" || f_die 377 break ;; 378 spanish) 379 f_sysrc_set keymap "spanish.iso" || f_die 380 break ;; 381 spanish_accent) 382 f_sysrc_set keymap "spanish.iso.acc" || f_die 383 break ;; 384 swedish_cp850) 385 f_sysrc_set keymap "swedish.cp850" || f_die 386 break ;; 387 swedish_iso) 388 f_sysrc_set keymap "swedish.iso" || f_die 389 break ;; 390 swiss_french_cp850) 391 f_sysrc_set keymap "swissfrench.cp850" || f_die 392 break ;; 393 swiss_french_iso) 394 f_sysrc_set keymap "swissfrench.iso" || f_die 395 break ;; 396 swiss_french_iso_accent) 397 f_sysrc_set keymap "swissfrench.iso.acc" || f_die 398 break ;; 399 swiss_german_cp850) 400 f_sysrc_set keymap "swissgerman.cp850" || f_die 401 break ;; 402 swiss_german_iso) 403 f_sysrc_set keymap "swissgerman.iso" || f_die 404 break ;; 405 swiss_german_iso_accent) 406 f_sysrc_set keymap "swissgerman.iso.acc" || f_die 407 break ;; 408 uk_cp850) 409 f_sysrc_set keymap "uk.cp850" || f_die 410 break ;; 411 uk_iso) 412 f_sysrc_set keymap "uk.iso" || f_die 413 break ;; 414 ukrainian_koi8_u) 415 f_sysrc_set keymap "ua.koi8-u" || f_die 416 break ;; 417 ukrainian_koi8_u_koi8_r) 418 f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 419 break ;; 420 usa_capslock_ctrl) 421 f_sysrc_set keymap "us.pc-ctrl" || f_die 422 break ;; 423 usa_dvorak) 424 f_sysrc_set keymap "us.dvorak" || f_die 425 break ;; 426 usa_dvorak_left) 427 f_sysrc_set keymap "us.dvorakl" || f_die 428 break ;; 429 usa_dvorak_right) 430 f_sysrc_set keymap "us.dvorakr" || f_die 431 break ;; 432 usa_emacs) 433 f_sysrc_set keymap "us.emacs" || f_die 434 break ;; 435 usa_iso) 436 f_sysrc_set keymap "us.iso" || f_die 437 break ;; 438 usa_unix) 439 f_sysrc_set keymap "us.unix" || f_die 440 break ;; 441 esac 442done 443 444exit $SUCCESS 445 446################################################################################ 447# END 448################################################################################ 449