summaryrefslogtreecommitdiff
path: root/kbd.init
blob: 00c15f8c20d83ed589c95a74556bafb426b150ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/sh

# console	Loads console font and keyboard table
#
# chkconfig:	2345 70 30
#
# description:	Loads the console font, the application-charset map \
#		and the keyboard table.

# This must be executed *after* /usr is mounted.
# This means, if /usr is NFS-mounted it needs to
# be run after networking and NFS mounts are up.

[ -f /etc/sysconfig/console ] || exit 0

[ -f /bin/loadkeys -o -f /usr/bin/loadkeys ] || exit 0
[ -f /bin/setfont -o -f /usr/bin/setfont ] || exit 0

# Source function library
. /etc/rc.d/init.d/functions

if is_yes "$VSERVER"; then
	exit 0
fi

[ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
. /etc/sysconfig/console

start() {
	# Checking if we have framebuffer enabled
	if [ -f /proc/fb ]; then
		# /proc shows as files with size=0, this is workaround
		if cat /proc/fb | grep -q "."; then FB=yes; fi
	fi

	if [ -n "$SVGATEXTMODE" ]; then
		run_cmd "Setting Text Mode $SVGATEXTMODE" SVGATextMode $SVGATEXTMODE
	fi

	# Check for devfs (workaround: -a option doesn't work at all)
	local devpath tty cons
	if [ -d /dev/vc ]; then
		devpath="/dev/vc/"
	else
		devpath="/dev/tty"
	fi
	# save old tty number
	tty=$(/usr/bin/tty)
	if [ "$?" -ne 0 -o "$tty" = "/dev/console" ]; then
		tty=1
	else
		tty=${tty#$devpath}
	fi

	if [ -n "$CONSOLEFONT" -a -x /sbin/setsysfont ]; then
		show "Loading console font and map"
		busy

		# don't initialize on multiple terminals if we use fbset
		# (assume that, in this case fb is loaded as a module)
		if [ ! -z "$FB" ]; then
			if [ -z "$SET_FONT_TERMINALS" ]; then
				# check if devfs (workaround: -a option doesn't work at all)
				if [ -d /dev/vc ]; then
					SET_FONT_TERMINALS=$(ls /dev/vc/)
				else
					SET_FONT_TERMINALS=$(awk -F: '/^[0-9]*:/{print $1}' /etc/inittab)
				fi
			fi

			for cons in $SET_FONT_TERMINALS; do
				/usr/bin/open -c $cons -s -w -- /sbin/setsysfont
				if [ "$NUM_LOCK" ]; then
					if [ $NUM_LOCK = "on" ]; then
						/usr/bin/open -c $cons -s -w -- /usr/bin/setleds -D +num
					else
						/usr/bin/open -c $cons -s -w -- /usr/bin/setleds -D -num
					fi
				fi
			done

			if [[ "$tty" = [0-9]* ]]; then
				/usr/bin/switchto $tty
			fi
		else
			for cons in $SET_FONT_TERMINALS; do
				/usr/bin/open -c $cons -s -w -- /sbin/setsysfont
			done
		fi
		ok
	fi

	if [ -n "$KEYTABLE" ]; then
		if [ "$(LANG="$LANG" locale charmap)" = "UTF-8" ]; then
			run_cmd "Loading keyboard table" loadkeys -u $KEYTABLE < /dev/tty0 > /dev/tty0
		else
			run_cmd "Loading keyboard table" loadkeys $KEYTABLE < /dev/tty0 > /dev/tty0
		fi
	fi
	run_cmd "Enabling SAK sequence" /bin/sh -c "echo Control Alt keycode 101 = SAK | loadkeys"

	power_option=""
	if ! is_no "$POWER_SAVE"; then
		if [ "$BLANK_TIME" ]; then
			power_option="-blank $BLANK_TIME";
		fi
		if [ "$POWERDOWN_TIME" ]; then
			power_option="-powerdown $POWERDOWN_TIME $power_option";
		fi
	else
		power_option="-blank 0 -powerdown 0 -powersave off";
	fi
	setterm_option="$power_option"
	if [ "$FOREGROUND_COLOUR" ]; then
		setterm_option="$setterm_option -foreground $FOREGROUND_COLOUR"
	fi
	if [ "$BACKGROUND_COLOUR" ]; then
		setterm_option="$setterm_option -background $BACKGROUND_COLOUR"
	fi
	if [ "$BEEP_LENGTH" ]; then
		setterm_option="$setterm_option -blength $BEEP_LENGTH"
	fi
	if [ "$BEEP_FREQ" ]; then
		setterm_option="$setterm_option -bfreq $BEEP_FREQ"
	fi
	setterm_option="$setterm_option -store"

	for cons in $SET_FONT_TERMINALS; do
		/usr/bin/open -c $cons -s -w -- /usr/bin/setterm $setterm_option
	done
	if [[ "$tty" = [0-9]* ]]; then
		/usr/bin/switchto $tty
	fi

	touch /var/lock/subsys/console
}

RETVAL=0
case "$1" in
  start)
	if [ ! -f /var/lock/subsys/console ]; then
		start
	fi
	;;
  restart)
	start
	;;
  try-restart)
	if [ -f /var/lock/subsys/console ]; then
		start
	fi
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/console ]; then
		start
	else
		RETVAL=7
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/console ]; then
		run_cmd "Setting terminals to default values" /usr/bin/setterm -default
		rm -f /var/lock/subsys/console
	fi
	;;
  status)
	/usr/bin/setleds
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL