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$ 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 size 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 size=$( eval f_dialog_menu_size \ 114 \"\$DIALOG_TITLE\" \ 115 \"\$DIALOG_BACKTITLE\" \ 116 \"\$prompt\" \ 117 \"\$hline\" \ 118 $menu_list ) 119 120 case "$( f_sysrc_get keymap )" in 121 be.iso) defaultitem="$msg_belgian";; 122 br275.cp850) defaultitem="$msg_brazil_cp850";; 123 br275.iso) defaultitem="$msg_brazil_iso";; 124 br275.iso.acc) defaultitem="$msg_brazil_iso_accent";; 125 bg.bds.ctrlcaps) defaultitem="$msg_bulgarian_bds";; 126 bg.phonetic.ctrlcaps) defaultitem="$msg_bulgarian_phonetic";; 127 ce.iso2) defaultitem="$msg_central_european_iso";; 128 hr.iso) defaultitem="$msg_croatian_iso";; 129 cs.latin2.qwertz) defaultitem="$msg_czech_iso_accent";; 130 danish.cp865) defaultitem="$msg_danish_cp865";; 131 danish.iso) defaultitem="$msg_danish_iso";; 132 estonian.cp850) defaultitem="$msg_estonian_cp850";; 133 estonian.iso) defaultitem="$msg_estonian_iso";; 134 estonian.iso15) defaultitem="$msg_estonian_iso_15";; 135 finnish.cp850) defaultitem="$msg_finnish_cp850";; 136 finnish.iso) defaultitem="$msg_finnish_iso";; 137 fr.iso) defaultitem="$msg_french_iso";; 138 fr.iso.acc) defaultitem="$msg_french_iso_accent";; 139 fr.macbook.acc) defaultitem="$msg_french_iso_macbook";; 140 german.cp850) defaultitem="$msg_german_cp850";; 141 german.iso) defaultitem="$msg_german_iso";; 142 gr.us101.acc) defaultitem="$msg_greek_101";; 143 el.iso07) defaultitem="$msg_greek_104";; 144 gr.elot.acc) defaultitem="$msg_greek_elot";; 145 hu.iso2.101keys) defaultitem="$msg_hungarian_101";; 146 hu.iso2.102keys) defaultitem="$msg_hungarian_102";; 147 icelandic.iso) defaultitem="$msg_icelandic";; 148 icelandic.iso.acc) defaultitem="$msg_icelandic_accent";; 149 it.iso) defaultitem="$msg_italian";; 150 jp.106) defaultitem="$msg_japanese_106";; 151 latinamerican) defaultitem="$msg_latin_american";; 152 latinamerican.iso.acc) defaultitem="$msg_latin_american_accent";; 153 norwegian.iso) defaultitem="$msg_norway_iso";; 154 pl_PL.ISO8859-2) defaultitem="$msg_polish_iso";; 155 pt.iso) defaultitem="$msg_portuguese";; 156 pt.iso.acc) defaultitem="$msg_portuguese_accent";; 157 ru.koi8-r) defaultitem="$msg_russia_koi8_r";; 158 sk.iso2) defaultitem="$msg_slovak";; 159 si.iso) defaultitem="$msg_slovenian";; 160 spanish.iso) defaultitem="$msg_spanish";; 161 spanish.iso.acc) defaultitem="$msg_spanish_accent";; 162 swedish.cp850) defaultitem="$msg_swedish_cp850";; 163 swedish.iso) defaultitem="$msg_swedish_iso";; 164 swissfrench.cp850) defaultitem="$msg_swiss_french_cp850";; 165 swissfrench.iso) defaultitem="$msg_swiss_french_iso";; 166 swissfrench.iso.acc) defaultitem="$msg_swiss_french_iso_accent";; 167 swissgerman.cp850) defaultitem="$msg_swiss_german_cp850";; 168 swissgerman.iso) defaultitem="$msg_swiss_german_iso";; 169 swissgerman.iso.acc) defaultitem="$msg_swiss_german_iso_accent";; 170 uk.cp850) defaultitem="$msg_uk_cp850";; 171 uk.iso) defaultitem="$msg_uk_iso";; 172 ua.koi8-u) defaultitem="$msg_ukrainian_koi8_u";; 173 ua.koi8-u.shift.alt) defaultitem="$msg_ukrainian_koi8_u_koi8_r";; 174 us.pc-ctrl) defaultitem="$msg_usa_capslock_ctrl";; 175 us.dvorak) defaultitem="$msg_usa_dvorak";; 176 us.dvorakl) defaultitem="$msg_usa_dvorak_left";; 177 us.dvorakr) defaultitem="$msg_usa_dvorak_right";; 178 us.emacs) defaultitem="$msg_usa_emacs";; 179 us.iso) defaultitem="$msg_usa_iso";; 180 us.unix) defaultitem="$msg_usa_unix";; 181 esac 182 183 # The defaultitem may have to be indented to match the menu_list 184 if [ "$defaultitem" ]; then 185 ( eval set -- $menu_list 186 while [ $# -gt 0 ]; do 187 [ "$defaultitem" = "$1" ] && break 188 [ " $defaultitem" = "$1" ] && exit 0 189 shift 2 # tag/item 190 done 191 exit 1 # No modification needed 192 ) && defaultitem=" $defaultitem" 193 fi 194 195 local dialog_menu 196 dialog_menu=$( eval $DIALOG \ 197 --title \"\$DIALOG_TITLE\" \ 198 --backtitle \"\$DIALOG_BACKTITLE\" \ 199 --hline \"\$hline\" \ 200 --ok-label \"\$msg_ok\" \ 201 --cancel-label \"\$msg_cancel\" \ 202 --default-item \"\$defaultitem\" \ 203 --menu \"\$prompt\" $size \ 204 $menu_list \ 205 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 206 ) 207 local retval=$? 208 setvar DIALOG_MENU_$$ "$dialog_menu" 209 return $retval 210} 211 212############################################################ MAIN 213 214# Incorporate rc-file if it exists 215[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 216 217# 218# Process command-line arguments 219# 220while getopts dD:hSX flag; do 221 case "$flag" in 222 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 223 esac 224done 225shift $(( $OPTIND - 1 )) 226 227# 228# Initialize 229# 230f_dialog_title "$msg_system_console_keymap" 231f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 232f_mustberoot_init 233 234# 235# Launch application main menu 236# 237while :; do 238 dialog_menu_main 239 retval=$? 240 mtag=$( f_dialog_menutag ) 241 242 [ $retval -eq 0 ] || f_die 243 244 # 245 # Reverse the users choice into the variable name 246 # 247 keymap_name= 248 mtag="${mtag# }" # remove single leading-space if-present 249 for name in $KEYMAP_NAMES; do 250 if [ "$( eval echo \"\$msg_$name\" )" = "$mtag" ]; then 251 keymap_name="$name" 252 break 253 fi 254 done 255 256 [ "$keymap_name" ] || continue 257 258 case "$keymap_name" in 259 belgian) 260 f_sysrc_set keymap "be.iso" || f_die 261 break ;; 262 brazil_cp850) 263 f_sysrc_set keymap "br275.cp850" || f_die 264 break ;; 265 brazil_iso) 266 f_sysrc_set keymap "br275.iso" || f_die 267 break ;; 268 brazil_iso_accent) 269 f_sysrc_set keymap "br275.iso.acc" || f_die 270 break ;; 271 bulgarian_bds) 272 f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die 273 break ;; 274 bulgarian_phonetic) 275 f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die 276 break ;; 277 central_european_iso) 278 f_sysrc_set keymap "ce.iso2" || f_die 279 break ;; 280 croatian_iso) 281 f_sysrc_set keymap "hr.iso" || f_die 282 break ;; 283 czech_iso_accent) 284 f_sysrc_set keymap "cs.latin2.qwertz" || f_die 285 break ;; 286 danish_cp865) 287 f_sysrc_set keymap "danish.cp865" || f_die 288 break ;; 289 danish_iso) 290 f_sysrc_set keymap "danish.iso" || f_die 291 break ;; 292 estonian_cp850) 293 f_sysrc_set keymap "estonian.cp850" || f_die 294 break ;; 295 estonian_iso) 296 f_sysrc_set keymap "estonian.iso" || f_die 297 break ;; 298 estonian_iso_15) 299 f_sysrc_set keymap "estonian.iso15" || f_die 300 break ;; 301 finnish_cp850) 302 f_sysrc_set keymap "finnish.cp850" || f_die 303 break ;; 304 finnish_iso) 305 f_sysrc_set keymap "finnish.iso" || f_die 306 break ;; 307 french_iso) 308 f_sysrc_set keymap "fr.iso" || f_die 309 break ;; 310 french_iso_accent) 311 f_sysrc_set keymap "fr.iso.acc" || f_die 312 break ;; 313 french_iso_macbook) 314 f_sysrc_set keymap "fr.macbook.acc" || f_die 315 break ;; 316 german_cp850) 317 f_sysrc_set keymap "german.cp850" || f_die 318 break ;; 319 german_iso) 320 f_sysrc_set keymap "german.iso" || f_die 321 break ;; 322 greek_101) 323 f_sysrc_set keymap "gr.us101.acc" || f_die 324 break ;; 325 greek_104) 326 f_sysrc_set keymap "el.iso07" || f_die 327 break ;; 328 greek_elot) 329 f_sysrc_set keymap "gr.elot.acc" || f_die 330 break ;; 331 hungarian_101) 332 f_sysrc_set keymap "hu.iso2.101keys" || f_die 333 break ;; 334 hungarian_102) 335 f_sysrc_set keymap "hu.iso2.102keys" || f_die 336 break ;; 337 icelandic) 338 f_sysrc_set keymap "icelandic.iso" || f_die 339 break ;; 340 icelandic_accent) 341 f_sysrc_set keymap "icelandic.iso.acc" || f_die 342 break ;; 343 italian) 344 f_sysrc_set keymap "it.iso" || f_die 345 break ;; 346 japanese_106) 347 f_sysrc_set keymap "jp.106" || f_die 348 break ;; 349 latin_american) 350 f_sysrc_set keymap "latinamerican" || f_die 351 break ;; 352 latin_american_accent) 353 f_sysrc_set keymap "latinamerican.iso.acc" || f_die 354 break ;; 355 norway_iso) 356 f_sysrc_set keymap "norwegian.iso" || f_die 357 break ;; 358 polish_iso) 359 f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die 360 break ;; 361 portuguese) 362 f_sysrc_set keymap "pt.iso" || f_die 363 break ;; 364 portuguese_accent) 365 f_sysrc_set keymap "pt.iso.acc" || f_die 366 break ;; 367 russia_koi8_r) 368 f_sysrc_set keymap "ru.koi8-r" || f_die 369 break ;; 370 slovak) 371 f_sysrc_set keymap "sk.iso2" || f_die 372 break ;; 373 slovenian) 374 f_sysrc_set keymap "si.iso" || f_die 375 break ;; 376 spanish) 377 f_sysrc_set keymap "spanish.iso" || f_die 378 break ;; 379 spanish_accent) 380 f_sysrc_set keymap "spanish.iso.acc" || f_die 381 break ;; 382 swedish_cp850) 383 f_sysrc_set keymap "swedish.cp850" || f_die 384 break ;; 385 swedish_iso) 386 f_sysrc_set keymap "swedish.iso" || f_die 387 break ;; 388 swiss_french_cp850) 389 f_sysrc_set keymap "swissfrench.cp850" || f_die 390 break ;; 391 swiss_french_iso) 392 f_sysrc_set keymap "swissfrench.iso" || f_die 393 break ;; 394 swiss_french_iso_accent) 395 f_sysrc_set keymap "swissfrench.iso.acc" || f_die 396 break ;; 397 swiss_german_cp850) 398 f_sysrc_set keymap "swissgerman.cp850" || f_die 399 break ;; 400 swiss_german_iso) 401 f_sysrc_set keymap "swissgerman.iso" || f_die 402 break ;; 403 swiss_german_iso_accent) 404 f_sysrc_set keymap "swissgerman.iso.acc" || f_die 405 break ;; 406 uk_cp850) 407 f_sysrc_set keymap "uk.cp850" || f_die 408 break ;; 409 uk_iso) 410 f_sysrc_set keymap "uk.iso" || f_die 411 break ;; 412 ukrainian_koi8_u) 413 f_sysrc_set keymap "ua.koi8-u" || f_die 414 break ;; 415 ukrainian_koi8_u_koi8_r) 416 f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die 417 break ;; 418 usa_capslock_ctrl) 419 f_sysrc_set keymap "us.pc-ctrl" || f_die 420 break ;; 421 usa_dvorak) 422 f_sysrc_set keymap "us.dvorak" || f_die 423 break ;; 424 usa_dvorak_left) 425 f_sysrc_set keymap "us.dvorakl" || f_die 426 break ;; 427 usa_dvorak_right) 428 f_sysrc_set keymap "us.dvorakr" || f_die 429 break ;; 430 usa_emacs) 431 f_sysrc_set keymap "us.emacs" || f_die 432 break ;; 433 usa_iso) 434 f_sysrc_set keymap "us.iso" || f_die 435 break ;; 436 usa_unix) 437 f_sysrc_set keymap "us.unix" || f_die 438 break ;; 439 esac 440done 441 442exit $SUCCESS 443 444################################################################################ 445# END 446################################################################################ 447