3
3
# setupcon -- setup the font and keyboard on the Linux console
4
# Copyright © 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010,2011 Anton Zinoviev
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# If you have not received a copy of the GNU General Public License
17
# along with this program, write to the Free Software Foundation, Inc.,
18
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4
# Copyright (C) 2011 Anton Zinoviev <anton@lml.bas.bg>
6
# Permission is hereby granted, free of charge, to any person
7
# obtaining a copy of this file (the "Program"), to deal in the
8
# Program without restriction, including without limitation the
9
# rights to use, copy, modify, merge, publish, distribute,
10
# sublicense, and/or sell copies of the Program, and to permit
11
# persons to whom the Program is furnished to do so, subject to
12
# the following conditions: The above copyright notice and this
13
# permission notice shall be included in all copies or substantial
14
# portions of the Program.
16
# THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
# FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR
23
# OTHER DEALINGS IN THE PROGRAM.
20
25
###########################################################################
22
do_font=yes # configure font
23
do_kbd=yes # configure keyboard
24
do_save='' # save the required files in /etc/console-setup
25
do_check=yes # test whether we are on the console
26
do_verbose='' # explain what is being doing
27
do_font=yes # configure font
28
do_kbd=yes # configure keyboard
29
do_check=yes # test whether we are on the console
30
do_verbose='' # explain what is being doing
31
do_save='' # save the required files in /etc/console-setup
32
savekbdfile='' # save the keyboard map in $savekbdfile
33
setupdir='' # directory for --setup-dir
28
36
# The same as /usr/bin/which - in order to make "which" available before
658
do_savekbd=${do_save:+$kernel}
659
[ "$XKBMODEL" ] || do_savekbd=''
660
if [ "$do_savekbd" = linux ] && ! which gzip >/dev/null; then
699
[ -z "$savekbdfile" -a -n "$do_save" ] \
700
&& [ ! -f "$cached" \
701
-o "$cached" -ot "$CONFIG" \
702
-o "$cached" -ot "$CONFIG2" ]
704
savekbdfile="$cached"
706
if [ -z "$savekbdfile" -a -n "$setupdir" ]; then
707
mkdir -p "$setupdir"/etc/console-setup
709
linux) savekbdfile="$setupdir"/etc/console-setup/cached.kmap.gz ;;
710
freebsd) savekbdfile="$setupdir"/etc/console-setup/cached.kbd ;;
713
[ "$XKBMODEL" ] || savekbdfile=''
714
if [ "$kernel" = linux ] && ! which gzip >/dev/null; then
662
716
echo gzip is not accessible. Will not save cached keyboard map. >&2
664
[ ! -f "$cached" -o "$cached" -ot "$CONFIG" -o "$cached" -ot "$CONFIG2" ] \
668
720
if [ -n "$KMAP" -a ! -f "$KMAP" ]; then
695
case "$do_savekbd" in
697
$installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
698
$rules_option -model "$XKBMODEL" \
699
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" | gzip -9 >"$cached"
702
$installdir/bin/ckbcomp -freebsd -backspace "$backspace" $acm_option \
703
$rules_option -model "$XKBMODEL" \
704
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >"$cached"
747
if [ "$savekbdfile" ]; then
750
$installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
751
$rules_option -model "$XKBMODEL" \
752
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
753
| gzip -9 >"$savekbdfile"
756
$installdir/bin/ckbcomp -freebsd -backspace "$backspace" \
757
$acm_option $rules_option -model "$XKBMODEL" \
758
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >"$savekbdfile"
709
764
###########################################################################
849
904
freebsd) run plain ECHO kbdcontrol -l "$KMAP" ;;
907
TMPFILE=`mktemp /tmp/tmpkbd.XXXXXX` \
908
|| { echo Can not create temporary file >&2; exit 1; }
852
909
case "$do_kbd" in
854
911
$installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
855
912
$rules_option -model "$XKBMODEL" \
856
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
857
| run plain ECHO loadkeys
913
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE
914
run plain ECHO loadkeys $TMPFILE
860
TMPFILE=`mktemp /tmp/console-setup.XXXXXX` \
861
|| { echo Can not create temporary file >&2; exit 1; }
862
917
$installdir/bin/ckbcomp -freebsd -backspace "$backspace" \
863
918
$acm_option $rules_option -model "$XKBMODEL" \
864
919
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE
865
920
run plain ECHO kbdcontrol -l $TMPFILE
866
921
run plain ECHO kbdcontrol -f 70 "`printf '\033[3~'`"
928
###########################################################################
930
###########################################################################
932
if [ "$setupdir" ]; then
936
*.kmap.gz|*.kbd|/tmp/tmpkbd.*)
937
echo -n "/etc/console-setup/${savekbdfile##*/} "
941
if [ ! -e "$setupdir/etc/console-setup/${1##*/}" ]; then
942
cp -a "$1" "$setupdir/etc/console-setup/${1##*/}"
944
echo -n "/etc/console-setup/${1##*/} "
955
mkdir -p "$setupdir"/bin
957
echo '#!/bin/sh' >"$setupdir"/bin/setupcon
958
echo '# A micro-version of setupcon with static configuration.' >>"$setupdir"/bin/setupcon
959
chmod +x "$setupdir"/bin/setupcon
960
TMPFILE=`mktemp /tmp/console-setup.XXXXXX` \
961
|| { echo Can not create temporary file >&2; exit 1; }
963
while read cmd args; do
966
echo -n printf \'\\\\'033%%G'\'' >'
967
filearg "${args%% *}"
971
echo -n printf \'\\\\'033%%@'\'' >'
972
filearg "${args%% *}"
976
echo kbdcontrol -f 70 \"\`printf \'\\\\033[3~\'\`\"
979
which "$cmd" >>$TMPFILE || true
987
done >>"$setupdir"/bin/setupcon
988
echo exit 0 >>"$setupdir"/bin/setupcon
989
sort $TMPFILE | uniq >"$setupdir"/morefiles