syscons revision 156782
170856Sjhb#!/bin/sh -
270856Sjhb#
370856Sjhb# Copyright (c) 2000  The FreeBSD Project
470856Sjhb# All rights reserved.
570856Sjhb#
670856Sjhb# Redistribution and use in source and binary forms, with or without
770856Sjhb# modification, are permitted provided that the following conditions
870856Sjhb# are met:
970856Sjhb# 1. Redistributions of source code must retain the above copyright
1070856Sjhb#    notice, this list of conditions and the following disclaimer.
1170856Sjhb# 2. Redistributions in binary form must reproduce the above copyright
1270856Sjhb#    notice, this list of conditions and the following disclaimer in the
1370856Sjhb#    documentation and/or other materials provided with the distribution.
1470856Sjhb#
1570856Sjhb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1670856Sjhb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1770856Sjhb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1870856Sjhb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1970856Sjhb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2070856Sjhb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2170856Sjhb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2270856Sjhb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2370856Sjhb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2470856Sjhb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2570856Sjhb# SUCH DAMAGE.
2670856Sjhb#
2770856Sjhb# $FreeBSD: head/etc/rc.d/syscons 156782 2006-03-16 17:42:28Z emax $
2870856Sjhb#
2970856Sjhb
30100280Sgordon# PROVIDE: syscons
31153430Siedowse# REQUIRE: LOGIN
32136224Smtm# KEYWORD: nojail
33100280Sgordon
34100280Sgordon. /etc/rc.subr
35100280Sgordon
36100280Sgordonname="syscons"
37156331Semaxextra_commands="setkeyboard"
38156331Semaxsetkeyboard_cmd="syscons_setkeyboard"
39102993Sfennerstart_precmd="syscons_precmd"
40102993Sfennerstart_cmd="syscons_start"
41100280Sgordon
4270856Sjhb# stdin must be redirected because it might be for a serial console
4370856Sjhb#
4470856Sjhbkbddev=/dev/ttyv0
4570856Sjhbviddev=/dev/ttyv0
4670856Sjhb
47156782Semax# helper
48156782Semaxsyscons_configure_keyboard()
49156331Semax{
50102993Sfenner	# keymap
51102993Sfenner	#
52102993Sfenner	case ${keymap} in
53102993Sfenner	[Nn][Oo] | '')
54102993Sfenner		;;
55102993Sfenner	*)
56102993Sfenner		echo -n ' keymap';	kbdcontrol < ${kbddev} -l ${keymap}
57102993Sfenner		;;
58102993Sfenner	esac
5970856Sjhb
60102993Sfenner	# keyrate
61102993Sfenner	#
62102993Sfenner	case ${keyrate} in
63102993Sfenner	[Nn][Oo] | '')
64102993Sfenner		;;
65102993Sfenner	*)
66102993Sfenner		echo -n ' keyrate';	kbdcontrol < ${kbddev} -r ${keyrate}
67102993Sfenner		;;
68102993Sfenner	esac
6970856Sjhb
70102993Sfenner	# keybell
71102993Sfenner	#
72102993Sfenner	case ${keybell} in
73102993Sfenner	[Nn][Oo] | '')
74102993Sfenner		;;
75102993Sfenner	*)
76102993Sfenner		echo -n ' keybell';	kbdcontrol < ${kbddev} -b ${keybell}
77102993Sfenner		;;
78102993Sfenner	esac
7970856Sjhb
80102993Sfenner	# change function keys
81102993Sfenner	#
82102993Sfenner	case ${keychange} in
83102993Sfenner	[Nn][Oo] | '')
84102993Sfenner		;;
85102993Sfenner	*)
86102993Sfenner		echo -n ' keychange'
87102993Sfenner		set - ${keychange}
88102993Sfenner		while [ $# -gt 0 ]; do
89102993Sfenner			kbdcontrol <${kbddev} -f "$1" "$2"
90102993Sfenner			shift; shift
91102993Sfenner		done
92102993Sfenner		;;
93102993Sfenner	esac
9470856Sjhb
95156782Semax	# set this keyboard mode for all virtual terminals
96156782Semax	#
97156782Semax	if [ -n "${allscreens_kbdflags}" ]; then
98156782Semax		echo -n ' allscreens_kbd'
99156782Semax		for ttyv in /dev/ttyv*; do
100156782Semax			kbdcontrol ${allscreens_kbdflags} < ${ttyv} > ${ttyv} 2>&1
101156782Semax		done
102156782Semax	fi
103156782Semax}
104156782Semax
105156782Semaxsyscons_setkeyboard()
106156782Semax{
107156782Semax	kbd=$1
108156782Semax                
109156782Semax	if [ -z "${kbd}" ]; then
110156782Semax		return 1
111156782Semax	fi
112156782Semax
113156782Semax	# Check if the kbdmux(4) is the current active keyboard
114156782Semax	kbdcontrol -i < ${kbddev} | grep kbdmux > /dev/null 2>&1
115156782Semax	if [ $? != 0 ]; then
116156782Semax		kbdcontrol -k ${kbd} < ${kbddev} > /dev/null 2>&1
117156782Semax	fi
118156782Semax
119156782Semax	echo -n 'Configuring keyboard:'
120156782Semax	syscons_configure_keyboard
121156782Semax	echo '.'
122156782Semax}
123156782Semax
124156782Semaxsyscons_precmd()
125156782Semax{
126156782Semax	if [ ! -c $kbddev ]
127156782Semax	then
128156782Semax		return 1
129156782Semax	fi
130156782Semax	if [ -x /usr/sbin/ispcvt ] && /usr/sbin/ispcvt
131156782Semax	then
132156782Semax		return 1
133156782Semax	fi
134156782Semax	return 0
135156782Semax}
136156782Semax
137156782Semaxsyscons_start()
138156782Semax{
139156782Semax	echo -n 'Configuring syscons:'
140156782Semax
141156782Semax	# keyboard
142156782Semax	#
143156782Semax	if [ -n "${keyboard}" ]; then
144156782Semax		echo -n ' keyboard';	syscons_setkeyboard ${keyboard}
145156782Semax	fi
146156782Semax
147156782Semax	syscons_configure_keyboard
148156782Semax
149102993Sfenner	# cursor type
150102993Sfenner	#
151102993Sfenner	case ${cursor} in
152102993Sfenner	[Nn][Oo] | '')
153102993Sfenner		;;
154102993Sfenner	*)
155102993Sfenner		echo -n ' cursor';	vidcontrol < ${viddev} -c ${cursor}
156102993Sfenner		;;
157102993Sfenner	esac
15870856Sjhb
159102993Sfenner	# screen mapping
160102993Sfenner	#
161102993Sfenner	case ${scrnmap} in
162102993Sfenner	[Nn][Oo] | '')
163102993Sfenner		;;
164102993Sfenner	*)
165102993Sfenner		echo -n ' scrnmap';	vidcontrol < ${viddev} -l ${scrnmap}
166102993Sfenner		;;
167102993Sfenner	esac
16870856Sjhb
169102993Sfenner	# font 8x16
170102993Sfenner	#
171102993Sfenner	case ${font8x16} in
172102993Sfenner	[Nn][Oo] | '')
173102993Sfenner		;;
174102993Sfenner	*)
175102993Sfenner		echo -n ' font8x16';	vidcontrol < ${viddev} -f 8x16 ${font8x16}
176102993Sfenner		;;
177102993Sfenner	esac
17870856Sjhb
179102993Sfenner	# font 8x14
180102993Sfenner	#
181102993Sfenner	case ${font8x14} in
182102993Sfenner	[Nn][Oo] | '')
183102993Sfenner		;;
184102993Sfenner	*)
185102993Sfenner		echo -n ' font8x14';	vidcontrol < ${viddev} -f 8x14 ${font8x14}
186102993Sfenner		;;
187102993Sfenner	esac
18870856Sjhb
189102993Sfenner	# font 8x8
190102993Sfenner	#
191102993Sfenner	case ${font8x8} in
192102993Sfenner	[Nn][Oo] | '')
193102993Sfenner		;;
194102993Sfenner	*)
195102993Sfenner		echo -n ' font8x8';	vidcontrol < ${viddev} -f 8x8 ${font8x8}
196102993Sfenner		;;
197102993Sfenner	esac
19870856Sjhb
199102993Sfenner	# blank time
200102993Sfenner	#
201102993Sfenner	case ${blanktime} in
202102993Sfenner	[Nn][Oo] | '')
203102993Sfenner		;;
204102993Sfenner	*)
205102993Sfenner		echo -n ' blanktime';	vidcontrol < ${viddev} -t ${blanktime}
206102993Sfenner		;;
207102993Sfenner	esac
20870856Sjhb
209102993Sfenner	# screen saver
210102993Sfenner	#
211102993Sfenner	case ${saver} in
212102993Sfenner	[Nn][Oo] | '')
213102993Sfenner		;;
214102993Sfenner	*)
215102993Sfenner		echo -n ' screensaver'
216102993Sfenner		for i in `kldstat | awk '$5 ~ "^splash_.*$" { print $5 }'`; do
217102993Sfenner			kldunload ${i}
218102993Sfenner		done
219102993Sfenner		kldstat -v | grep -q _saver || kldload ${saver}_saver
220102993Sfenner		;;
221102993Sfenner	esac
22270856Sjhb
223102993Sfenner	# set this mode for all virtual screens
224102993Sfenner	#
225102993Sfenner	if [ -n "${allscreens_flags}" ]; then
226102993Sfenner		echo -n ' allscreens'
227102993Sfenner		for ttyv in /dev/ttyv*; do
228102993Sfenner			vidcontrol ${allscreens_flags} < ${ttyv} > ${ttyv} 2>&1
229102993Sfenner		done
230102993Sfenner	fi
231100284Sdougb
232102993Sfenner	echo '.'
233102993Sfenner}
234103161Sgordon
235103161Sgordonload_rc_config $name
236156331Semaxrun_rc_command $*
237156331Semax
238