1#!/bin/sh - 2# 3# Copyright (c) 2000 The FreeBSD Project 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 (INCLUDING, 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 30# PROVIDE: syscons 31# REQUIRE: LOGIN 32# KEYWORD: nojail 33 34. /etc/rc.subr 35 36name="syscons" 37desc="Configure the system console" 38extra_commands="setkeyboard" 39setkeyboard_cmd="syscons_setkeyboard" 40start_precmd="syscons_precmd" 41start_cmd="syscons_start" 42stop_cmd=":" 43 44# stdin must be redirected because it might be for a serial console 45# 46kbddev=/dev/ttyv0 47viddev=/dev/ttyv0 48 49_sc_config= 50_sc_console= 51_sc_initdone= 52_sc_keymap_msg= 53sc_init() 54{ 55 if [ -z "${_sc_initdone}" ]; then 56 if [ -z "${_sc_console}" ]; then 57 if [ x`sysctl -n kern.vty` = x"vt" ]; then 58 _sc_console="vt" 59 else 60 _sc_console="syscons" 61 fi 62 _sc_config="${_sc_console}" 63 fi 64 echo -n "Configuring ${_sc_config}:" 65 _sc_initdone=yes 66 fi 67} 68 69# syscons to vt migration helper 70lookup_keymap_for_vt() 71{ 72 keymap=`basename $1 .kbd` 73 case $keymap in 74hy.armscii-8) echo am;; 75be.iso.acc) echo be.acc;; 76be.iso) echo be;; 77bg.bds.ctrlcaps) echo bg.bds;; 78bg.phonetic.ctrlcaps) echo bg.phonetic;; 79br275.iso.acc) echo br;; 80br275.*) echo br.noacc;; 81by.*) echo by;; 82fr_CA.iso.acc) echo ca-fr;; 83swissgerman.macbook.acc) echo ch.macbook.acc;; 84swissgerman.iso.acc) echo ch.acc;; 85swissgerman.*) echo ch;; 86swissfrench.iso.acc) echo ch-fr.acc;; 87swissfrench.*) echo ch-fr;; 88ce.iso2) echo centraleuropean.qwerty;; 89colemak.iso15.acc) echo colemak.acc;; 90cs.*|cz.*) echo cz;; 91german.iso.acc) echo de.acc;; 92german.*) echo de;; 93danish.iso.acc) echo dk.acc;; 94danish.iso.macbook) echo dk.macbook;; 95danish.*) echo dk;; 96estonian.*) echo ee;; 97spanish.dvorak) echo es.dvorak;; 98spanish.iso*.acc) echo es.acc;; 99spanish.iso) echo es;; 100finnish.*) echo fi;; 101fr.macbook.acc) echo fr.macbook;; 102fr.iso.acc) echo fr.acc;; 103fr.iso) echo fr;; 104el.iso07) echo gr;; 105gr.us101.acc) echo gr.101.acc;; 106hr.iso) echo hr;; 107hu.iso2.101keys) echo hu.101;; 108hu.iso2.102keys) echo hu.102;; 109iw.iso8) echo il;; 110icelandic.iso.acc) echo is.acc;; 111icelandic.iso) echo is;; 112it.iso) echo it;; 113jp.106x) echo jp.capsctrl;; 114jp.106) echo jp;; 115kk.pt154.io) echo kz.io;; 116kk.pt154.kst) echo kz.kst;; 117latinamerican.iso.acc) echo latinamerican.acc;; 118lt.iso4) echo lt;; 119norwegian.iso) echo no;; 120norwegian.dvorak) echo no.dvorak;; 121dutch.iso.acc) echo nl;; 122eee_nordic) echo nordic.asus-eee;; 123pl_PL.dvorak) echo pl.dvorak;; 124pl_PL.ISO8859-2) echo pl;; 125pt.iso.acc) echo pt.acc;; 126pt.iso) echo pt;; 127ru.koi8-r.shift) echo ru.shift;; 128ru.koi8-r.win) echo ru.win;; 129ru.*) echo ru;; 130swedish.*) echo se;; 131si.iso) echo si;; 132sk.iso2) echo sk;; 133tr.iso9.q) echo tr;; 134ua.koi8-u.shift.alt) echo ua.shift.alt;; 135ua.*) echo ua;; 136uk.*-ctrl) echo uk.capsctrl;; 137uk.dvorak) echo uk.dvorak;; 138uk.*) echo uk;; 139us.iso.acc) echo us.acc;; 140us.pc-ctrl) echo us.ctrl;; 141us.iso) echo us;; 142 esac 143} 144 145kbdcontrol_load_keymap() 146{ 147 errmsg=`kbdcontrol < ${kbddev} -l ${keymap} 2>&1` 148 if [ -n "${errmsg}" -a "${_sc_console}" = "vt" ]; then 149 _sc_keymap_msg="${errmsg}" 150 keymap_vt=`lookup_keymap_for_vt ${keymap}` 151 if [ -n "${keymap_vt}" ]; then 152 errmsg=`kbdcontrol < ${kbddev} -l ${keymap_vt} 2>&1` 153 if [ -z "${errmsg}" ]; then 154 _sc_keymap_msg="New keymap: In /etc/rc.conf replace 'keymap=${keymap}' by 'keymap=${keymap_vt}'" 155 fi 156 else 157 _sc_keymap_msg="No replacement found for keymap '${keymap}'. 158You may try to convert your keymap file using 'convert-keymap.pl', which is 159part of the system sources and located in /usr/src/tools/tools/vt/keymaps/" 160 fi 161 fi 162} 163 164# helper 165syscons_configure_keyboard() 166{ 167 # keymap 168 # 169 case ${keymap} in 170 NO | '') 171 ;; 172 *) 173 sc_init 174 echo -n ' keymap'; kbdcontrol_load_keymap 175 ;; 176 esac 177 178 # keyrate 179 # 180 case ${keyrate} in 181 [Nn][Oo] | '') 182 ;; 183 *) 184 sc_init 185 echo -n ' keyrate'; kbdcontrol < ${kbddev} -r ${keyrate} 186 ;; 187 esac 188 189 # keybell 190 # 191 case ${keybell} in 192 [Nn][Oo] | '') 193 ;; 194 *) 195 sc_init 196 echo -n ' keybell'; kbdcontrol < ${kbddev} -b ${keybell} 197 ;; 198 esac 199 200 # change function keys 201 # 202 case ${keychange} in 203 [Nn][Oo] | '') 204 ;; 205 *) 206 sc_init 207 echo -n ' keychange' 208 set -- ${keychange} 209 while [ $# -gt 0 ]; do 210 kbdcontrol <${kbddev} -f "$1" "$2" 211 shift; shift 212 done 213 ;; 214 esac 215 216 # set this keyboard mode for all virtual terminals 217 # 218 if [ -n "${allscreens_kbdflags}" ]; then 219 sc_init 220 echo -n ' allscreens_kbd' 221 for ttyv in /dev/ttyv*; do 222 kbdcontrol ${allscreens_kbdflags} < ${ttyv} > ${ttyv} 2>&1 223 done 224 fi 225} 226 227syscons_setkeyboard() 228{ 229 kbd=$1 230 231 if [ -z "${kbd}" ]; then 232 return 1 233 fi 234 235 # Check if the kbdmux(4) is the current active keyboard 236 kbdcontrol -i < ${kbddev} | grep kbdmux > /dev/null 2>&1 237 if [ $? -ne 0 ]; then 238 kbdcontrol -k ${kbd} < ${kbddev} > /dev/null 2>&1 239 fi 240 241 _sc_config="keyboard" 242 syscons_configure_keyboard 243 244 # Terminate keyboard configuration line and reset global variables. 245 # 246 if [ -n "${_sc_initdone}" ]; then 247 echo '.' 248 _sc_config="${_sc_console}" 249 _sc_initdone= 250 fi 251} 252 253syscons_precmd() 254{ 255 if [ ! -c $kbddev ] 256 then 257 return 1 258 fi 259 return 0 260} 261 262syscons_start() 263{ 264 # keyboard 265 # 266 if [ -n "${keyboard}" ]; then 267 syscons_setkeyboard ${keyboard} 268 fi 269 270 syscons_configure_keyboard 271 272 # cursor type 273 # 274 case ${cursor} in 275 [Nn][Oo] | '') 276 ;; 277 *) 278 sc_init 279 echo -n ' cursor'; vidcontrol < ${viddev} -c ${cursor} 280 ;; 281 esac 282 283 # screen mapping 284 # 285 case ${scrnmap} in 286 [Nn][Oo] | '') 287 ;; 288 *) 289 sc_init 290 echo -n ' scrnmap'; vidcontrol < ${viddev} -l ${scrnmap} 291 ;; 292 esac 293 294 # font 8x16 295 # 296 case ${font8x16} in 297 [Nn][Oo] | '') 298 ;; 299 *) 300 sc_init 301 echo -n ' font8x16'; vidcontrol < ${viddev} -f 8x16 ${font8x16} 302 ;; 303 esac 304 305 # font 8x14 306 # 307 case ${font8x14} in 308 [Nn][Oo] | '') 309 ;; 310 *) 311 sc_init 312 echo -n ' font8x14'; vidcontrol < ${viddev} -f 8x14 ${font8x14} 313 ;; 314 esac 315 316 # font 8x8 317 # 318 case ${font8x8} in 319 [Nn][Oo] | '') 320 ;; 321 *) 322 sc_init 323 echo -n ' font8x8'; vidcontrol < ${viddev} -f 8x8 ${font8x8} 324 ;; 325 esac 326 327 # blank time 328 # 329 case ${blanktime} in 330 [Nn][Oo] | '') 331 ;; 332 *) 333 sc_init 334 echo -n ' blanktime'; vidcontrol < ${viddev} -t ${blanktime} 335 ;; 336 esac 337 338 # screen saver 339 # 340 case ${saver} in 341 [Nn][Oo] | '') 342 ;; 343 *) 344 sc_init 345 echo -n ' screensaver' 346 for i in `kldstat | awk '$5 ~ "_saver\.ko$" { print $5 }'`; do 347 kldunload ${i} 348 done 349 load_kld -e _saver ${saver}_saver 350 ;; 351 esac 352 353 # set this mode for all virtual screens 354 # 355 if [ -n "${allscreens_flags}" ]; then 356 sc_init 357 echo -n ' allscreens' 358 for ttyv in /dev/ttyv*; do 359 vidcontrol ${allscreens_flags} < ${ttyv} > ${ttyv} 2>&1 360 done 361 fi 362 363 [ -n "${_sc_initdone}" ] && echo '.' 364 if [ -n "${_sc_keymap_msg}" ]; then 365 echo 366 echo "WARNING:" 367 echo "${_sc_keymap_msg}." 368 echo 369 fi 370} 371 372load_rc_config $name 373run_rc_command $* 374 375