| 1 |
#!/bin/sh
|
| 2 |
|
| 3 |
# setupcon -- setup the font and keyboard on the Linux console
|
| 4 |
# Copyright © 1999,2000,2001,2002,2003,2006 Anton Zinoviev
|
| 5 |
|
| 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.
|
| 10 |
|
| 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.
|
| 15 |
|
| 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
|
| 19 |
|
| 20 |
while [ "$1" ]; do
|
| 21 |
case "$1" in
|
| 22 |
-k|--keyboard-only)
|
| 23 |
keyboard_only=true
|
| 24 |
;;
|
| 25 |
-f|--font-only)
|
| 26 |
font_only=true
|
| 27 |
;;
|
| 28 |
-v|--verbose)
|
| 29 |
verbose_option=yes
|
| 30 |
;;
|
| 31 |
--save)
|
| 32 |
save=yes
|
| 33 |
;;
|
| 34 |
-h|--help)
|
| 35 |
cat >&2 <<EOF
|
| 36 |
Usage: setupcon [OPTION] [VARIANT]
|
| 37 |
Sets up the font and the keyboard on Linux console.
|
| 38 |
|
| 39 |
-k, --keyboard-only setup the keyboard only, do not setup the font
|
| 40 |
-f, --font-only setup the font only, do not setup the keyboard
|
| 41 |
-v, --verbose explain what is being doing, try it if s.t. goes wrong
|
| 42 |
--save copy the font and the ACM in /etc/console-setup,
|
| 43 |
update /etc/console-setup/boottime.kmap.gz
|
| 44 |
-h, --help display this help and exit
|
| 45 |
|
| 46 |
If VARIANT is not specified setupcon looks for the configuration files
|
| 47 |
(in this order) ~/.console-setup and /etc/default/console-setup. When
|
| 48 |
a VARIANT is specified then setupcon looks for the configuration files
|
| 49 |
~/.console-setup.VARIANT and /etc/default/console-setup.VARIANT.
|
| 50 |
EOF
|
| 51 |
exit 0
|
| 52 |
;;
|
| 53 |
-*)
|
| 54 |
echo "setupcon: Unrecognised option $1" >&2
|
| 55 |
exit 1
|
| 56 |
;;
|
| 57 |
*)
|
| 58 |
if [ -z "$VARIANT" ]; then
|
| 59 |
VARIANT="$1"
|
| 60 |
else
|
| 61 |
echo "setupcon: Two variants specified: $VARIANT and $1" >&2
|
| 62 |
exit 1
|
| 63 |
fi
|
| 64 |
;;
|
| 65 |
esac
|
| 66 |
shift
|
| 67 |
done
|
| 68 |
|
| 69 |
if [ "$VARIANT" ]; then
|
| 70 |
USER_CONFIG=${HOME}/.console-setup."$VARIANT"
|
| 71 |
MAIN_CONFIG=/etc/default/console-setup."$VARIANT"
|
| 72 |
else
|
| 73 |
USER_CONFIG=${HOME}/.console-setup
|
| 74 |
MAIN_CONFIG=/etc/default/console-setup
|
| 75 |
fi
|
| 76 |
|
| 77 |
if [ -f "$USER_CONFIG" ]; then
|
| 78 |
CONFIG="$USER_CONFIG"
|
| 79 |
elif [ -f "$MAIN_CONFIG" ]; then
|
| 80 |
CONFIG="$MAIN_CONFIG"
|
| 81 |
else
|
| 82 |
echo "setupcon: None of $MAIN_CONFIG nor $USER_CONFIG exists." >&2
|
| 83 |
exit 1
|
| 84 |
fi
|
| 85 |
|
| 86 |
. "$CONFIG"
|
| 87 |
|
| 88 |
if [ "$verbose_option" = yes ]; then
|
| 89 |
VERBOSE_OUTPUT=yes
|
| 90 |
fi
|
| 91 |
if [ "$VERBOSE_OUTPUT" = yes ]; then
|
| 92 |
verbose=''
|
| 93 |
else
|
| 94 |
verbose='>/dev/null 2>&1'
|
| 95 |
fi
|
| 96 |
|
| 97 |
case `readlink /proc/self/fd/0` in
|
| 98 |
/dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
|
| 99 |
;;
|
| 100 |
*)
|
| 101 |
if [ "$VERBOSE_OUTPUT" = yes ]; then
|
| 102 |
echo We are not on the Linux console, exiting.
|
| 103 |
fi
|
| 104 |
exit 0
|
| 105 |
;;
|
| 106 |
esac
|
| 107 |
|
| 108 |
#-----------------------#
|
| 109 |
# OUTPUT #
|
| 110 |
#-----------------------#
|
| 111 |
|
| 112 |
if [ "$keyboard_only" != yes ] && [ "$ACTIVE_CONSOLES" ]; then
|
| 113 |
for console in $ACTIVE_CONSOLES; do
|
| 114 |
[ -w $console ] || continue
|
| 115 |
# Setup unicode/non-unicode mode
|
| 116 |
if [ "$CHARMAP" = UTF-8 ] || [ -z "$ACM" ]; then
|
| 117 |
/bin/echo -n -e '\033%G' >$console
|
| 118 |
else
|
| 119 |
/bin/echo -n -e '\033%@' >$console
|
| 120 |
fi
|
| 121 |
|
| 122 |
# Load the font
|
| 123 |
if [ ! -f "$FONT" ]; then
|
| 124 |
for dir in \
|
| 125 |
/etc/console-setup \
|
| 126 |
/usr/local/share/consolefonts \
|
| 127 |
/usr/share/consolefonts
|
| 128 |
do
|
| 129 |
if [ -f "$dir/$CODESET-$FONTFACE$FONTSIZE.psf.gz" ]; then
|
| 130 |
FONT="$dir/$CODESET-$FONTFACE$FONTSIZE.psf.gz"
|
| 131 |
break
|
| 132 |
fi
|
| 133 |
done
|
| 134 |
fi
|
| 135 |
if [ -f "$FONT" ]; then
|
| 136 |
if \
|
| 137 |
[ "$save" = yes ] \
|
| 138 |
&& [ "${FONT%/*}" != /etc/console-setup ]
|
| 139 |
then
|
| 140 |
cp "$FONT" /etc/console-setup/
|
| 141 |
fi
|
| 142 |
else
|
| 143 |
FONT="$CODESET-$FONTFACE$FONTSIZE.psf.gz"
|
| 144 |
fi
|
| 145 |
if which consolechars >/dev/null; then
|
| 146 |
eval consolechars -v --tty=$console -f "$FONT" $verbose
|
| 147 |
elif which setfont >/dev/null; then
|
| 148 |
eval setfont -v -C $console "$FONT" $verbose
|
| 149 |
fi
|
| 150 |
|
| 151 |
# Load the ACM
|
| 152 |
if [ ! -f "$ACM" ]; then
|
| 153 |
for dir in \
|
| 154 |
/etc/console-setup \
|
| 155 |
/usr/local/share/consoletrans \
|
| 156 |
/usr/share/consoletrans
|
| 157 |
do
|
| 158 |
if [ -f "$dir/$CHARMAP.acm.gz" ]; then
|
| 159 |
ACM="$dir/$CHARMAP.acm.gz"
|
| 160 |
break
|
| 161 |
fi
|
| 162 |
done
|
| 163 |
fi
|
| 164 |
if [ -f "$ACM" ]; then
|
| 165 |
if \
|
| 166 |
[ "$save" = yes ] \
|
| 167 |
&& [ "${ACM%/*}" != /etc/console-setup ]
|
| 168 |
then
|
| 169 |
cp "$ACM" /etc/console-setup/
|
| 170 |
fi
|
| 171 |
else
|
| 172 |
ACM="$CHARMAP.acm.gz"
|
| 173 |
fi
|
| 174 |
if [ "$CHARMAP" != UTF-8 ]; then
|
| 175 |
if which consolechars >/dev/null; then
|
| 176 |
eval consolechars -v --tty=$console --acm "$ACM" $verbose
|
| 177 |
elif which setfont >/dev/null; then
|
| 178 |
eval setfont -v -C -m "$ACM" $verbose
|
| 179 |
fi
|
| 180 |
fi
|
| 181 |
done
|
| 182 |
fi
|
| 183 |
|
| 184 |
#-----------------------#
|
| 185 |
# INPUT #
|
| 186 |
#-----------------------#
|
| 187 |
|
| 188 |
if [ "$font_only" != yes ]; then
|
| 189 |
# On Mac PPC machines, we may need to set kernel vars first. We need
|
| 190 |
# to mount /proc to do that, but we need it set up before sulogin may
|
| 191 |
# be run in checkroot, which will need the keyboard to log in...
|
| 192 |
# This code was borrowed from the keymap.sh script of console-common
|
| 193 |
# Copyright © 2001 Yann Dirson
|
| 194 |
# Copyright © 2001 Alcove http://www.alcove.fr/
|
| 195 |
if [ -x /sbin/sysctl ] && [ -r /etc/sysctl.conf ]; then
|
| 196 |
if grep -v '^\#' /etc/sysctl.conf | grep -q keycodes ; then
|
| 197 |
grep keycodes /etc/sysctl.conf | grep -v "^#" \
|
| 198 |
| while read d ; do
|
| 199 |
/sbin/sysctl -w $d 2> /dev/null || true
|
| 200 |
done
|
| 201 |
fi
|
| 202 |
fi
|
| 203 |
|
| 204 |
if which kbd_mode >/dev/null; then
|
| 205 |
if [ "$CHARMAP" = UTF-8 ] || [ -z "$ACM" ]; then
|
| 206 |
kbd_mode -u
|
| 207 |
else
|
| 208 |
kbd_mode -a
|
| 209 |
fi
|
| 210 |
fi
|
| 211 |
|
| 212 |
if which loadkeys >/dev/null; then
|
| 213 |
if which ckbcomp >/dev/null; then
|
| 214 |
if [ "$CHARMAP" != UTF-8 ]; then
|
| 215 |
acm_option="-charmap $CHARMAP"
|
| 216 |
else
|
| 217 |
acm_option=''
|
| 218 |
fi
|
| 219 |
ckbcomp $acm_option -model "$XKBMODEL" \
|
| 220 |
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
|
| 221 |
| eval loadkeys $verbose
|
| 222 |
if which gzip >/dev/null && [ "$save" = yes ]; then
|
| 223 |
ckbcomp $acm_option -model "$XKBMODEL" \
|
| 224 |
"$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
|
| 225 |
| gzip -9 >/etc/console-setup/boottime.kmap.gz
|
| 226 |
fi
|
| 227 |
elif [ -f /etc/console-setup/boottime.kmap.gz ]; then
|
| 228 |
eval loadkeys /etc/console-setup/boottime.kmap.gz $verbose
|
| 229 |
fi
|
| 230 |
fi
|
| 231 |
fi
|
| 232 |
|