#!/bin/bash # Copyright (C) 2009, 2010 Matias Fonzo, Santiago del Estero, AR # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Localización: TEXTDOMAINDIR=/usr/local/share/locale TEXTDOMAIN=keyconfig # Directorio temporal: TMP=${TMP:-/tmp} [[ ! -d $TMP ]] && mkdir -p "$TMP" TEMPFILE=${TMP}/keyconfig-reply$$ # Busca/actualiza los mapas de teclado: # Directorio por defecto: MAP_DIR=${MAP_DIR:-/usr/share/keymaps/i386} # Chequeo de sanidad: if [[ ! -d $MAP_DIR ]]; then echo "${MAP_DIR}:" $"No such file or directory." exit 1; fi # Búsqueda: # # Necesitamos testear si el arreglo no está vacío, # cuando el script es nuevamente ejecutado: for test in "${arr[@]}"; do [[ $test ]] && { ARR=one ; break; } done if [[ -z $ARR ]]; then for map in ${MAP_DIR}/*/*.gz ; do # Excluimos 2 directorios: dir_exclude=${map%/*} dir_exclude=${dir_exclude##*/} [[ $dir_exclude =~ ^(fgGIod|include) ]] && continue; if [[ -f $map ]]; then item+=( $map ) fi done fi # Item por defecto según el lenguaje: if [[ -z $DEF_ITEM ]]; then case "${LANG%_*}" in es|gl) DEF_ITEM=qwerty/es.map.gz;; it) DEF_ITEM=qwerty/it.map.gz;; *) DEF_ITEM=qwerty/us.map.gz; esac fi # Muestra el menú: unset x ; i=0 for file in "${item[@]}"; do file_name=${file##*/} dir_name=${file%/*} dir_name=${dir_name##*/} file=${dir_name}/$file_name x[i++]=$file x[i++]="" done dialog \ --backtitle $"Keyboard configuration tool" \ --title $"KEYBOARD MAP" \ --default-item "$DEF_ITEM" \ --menu \ $"Welcome to keyconfig.\n\n\ Select the keyboard map that you use:" 20 50 11 "${x[@]}" \ 2> $TEMPFILE RETCODE=$? if (( $RETCODE != 0 )); then rm -f $TEMPFILE exit $RETCODE; fi ANSWER=$(cut -f 1 -d ' ' $TEMPFILE) # Carga el mapa de teclado: if [[ -x /bin/loadkeys ]]; then /bin/loadkeys "$ANSWER" 1> /dev/null 2>&1 fi # Prueba el mapa de teclado: dialog \ --backtitle $"Keyboard configuration tool" \ --title $"TESTING FOR KEYBOARD" \ --inputbox $"Write or type something to test your keyboard map:" 0 0 RETCODE=$?; (( $RETCODE != 0 )) && "$0" && RETCODE=0; dialog --clear # Crea el archivo de configuración: if (( $RETCODE == 0 )); then mkdir -p /etc/sysconfig printf "%s\n" \ "#" \ "# keymap: File configuration for the keymap." \ "#" \ "" \ "KEYMAP=$ANSWER" \ "" > /etc/sysconfig/keymap # Creamos el archivo para el inicio: mkdir -p /etc/rc.d printf "%s\n" \ "#!/bin/bash" \ "#" \ "# rc.keymap: Load the keyboard map." \ "#" \ "# Generated by keyconfig." \ "" \ ". /etc/sysconfig/keymap || exit 1" \ "" \ "# Load the keymap:" \ "if [[ -x /bin/loadkeys ]]; then" \ " /bin/loadkeys \$KEYMAP" \ "fi" \ "" > /etc/rc.d/rc.keymap chmod 755 /etc/rc.d/rc.keymap fi rm -f $TEMPFILE exit $RETCODE