]> git.pld-linux.org Git - packages/kbd.git/blob - kbd.init
- upstart hook
[packages/kbd.git] / kbd.init
1 #!/bin/sh
2
3 # console       Loads console font and keyboard table
4 #
5 # chkconfig:    2345 70 30
6 #
7 # description:  Loads the console font, the application-charset map \
8 #               and the keyboard table.
9
10 # This must be executed *after* /usr is mounted.
11 # This means, if /usr is NFS-mounted it needs to
12 # be run after networking and NFS mounts are up.
13
14 [ -f /etc/sysconfig/console ] || exit 0
15
16 [ -f /bin/loadkeys -o -f /usr/bin/loadkeys ] || exit 0
17 [ -f /bin/setfont -o -f /usr/bin/setfont ] || exit 0
18
19 # Source function library
20 . /etc/rc.d/init.d/functions
21
22 if is_yes "$VSERVER"; then
23         exit 0
24 fi
25
26 upstart_controlled
27
28 [ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
29 . /etc/sysconfig/console
30
31 start() {
32         # Checking if we have framebuffer enabled
33         if [ -f /proc/fb ]; then
34                 # /proc shows as files with size=0, this is workaround
35                 if cat /proc/fb | grep -q "."; then FB=yes; fi
36         fi
37
38         if [ -n "$SVGATEXTMODE" ]; then
39                 run_cmd "Setting Text Mode $SVGATEXTMODE" SVGATextMode $SVGATEXTMODE
40         fi
41
42         # Check for devfs (workaround: -a option doesn't work at all)
43         local devpath tty cons
44         if [ -d /dev/vc ]; then
45                 devpath="/dev/vc/"
46         else
47                 devpath="/dev/tty"
48         fi
49         # save old tty number
50         tty=$(/usr/bin/tty)
51         tty=${tty#$devpath}
52         if [ "$tty" = "/dev/console" ]; then
53                 tty=1
54         fi
55
56         if [ -n "$CONSOLEFONT" -a -x /sbin/setsysfont ]; then
57                 show "Loading console font and map"
58                 busy
59
60                 # don't initialize on multiple terminals if we use fbset
61                 # (assume that, in this case fb is loaded as a module)
62                 if [ ! -z "$FB" ]; then
63                         if [ -z "$SET_FONT_TERMINALS" ]; then
64                                 # check if devfs (workaround: -a option doesn't work at all)
65                                 if [ -d /dev/vc ]; then
66                                         SET_FONT_TERMINALS=$(ls /dev/vc/)
67                                 else
68                                         SET_FONT_TERMINALS=$(awk -F: '/^[0-9]*:/{print $1}' /etc/inittab)
69                                 fi
70                         fi
71
72                         for cons in $SET_FONT_TERMINALS; do
73                                 /usr/bin/open -c $cons -s -w -- /sbin/setsysfont
74                                 if [ "$NUM_LOCK" ]; then
75                                         if [ $NUM_LOCK = "on" ]; then
76                                                 /usr/bin/open -c $cons -s -w -- /usr/bin/setleds -D +num
77                                         else
78                                                 /usr/bin/open -c $cons -s -w -- /usr/bin/setleds -D -num
79                                         fi
80                                 fi
81                         done
82
83                         if [[ "$tty" = [0-9]* ]]; then
84                                 /usr/bin/switchto $tty
85                         fi
86                 else
87                         for cons in $SET_FONT_TERMINALS; do
88                                 /usr/bin/open -c $cons -s -w -- /sbin/setsysfont
89                         done
90                 fi
91                 ok
92         fi
93
94         if [ -n "$KEYTABLE" ]; then
95                 if [ "$(LANG="$LANG" locale charmap)" = "UTF-8" ]; then
96                         run_cmd "Loading keyboard table" loadkeys -u $KEYTABLE < /dev/tty0 > /dev/tty0
97                 else
98                         run_cmd "Loading keyboard table" loadkeys $KEYTABLE < /dev/tty0 > /dev/tty0
99                 fi
100         fi
101         run_cmd "Enabling SAK sequence" /bin/sh -c "echo Control Alt keycode 101 = SAK | loadkeys"
102
103         power_option=""
104         if ! is_no "$POWER_SAVE"; then
105                 if [ "$BLANK_TIME" ]; then
106                         power_option="-blank $BLANK_TIME";
107                 fi
108                 if [ "$POWERDOWN_TIME" ]; then
109                         power_option="-powerdown $POWERDOWN_TIME $power_option";
110                 fi
111         else
112                 power_option="-blank 0 -powerdown 0 -powersave off";
113         fi
114         setterm_option="$power_option"
115         if [ "$FOREGROUND_COLOUR" ]; then
116                 setterm_option="$setterm_option -foreground $FOREGROUND_COLOUR"
117         fi
118         if [ "$BACKGROUND_COLOUR" ]; then
119                 setterm_option="$setterm_option -background $BACKGROUND_COLOUR"
120         fi
121         if [ "$BEEP_LENGTH" ]; then
122                 setterm_option="$setterm_option -blength $BEEP_LENGTH"
123         fi
124         if [ "$BEEP_FREQ" ]; then
125                 setterm_option="$setterm_option -bfreq $BEEP_FREQ"
126         fi
127         setterm_option="$setterm_option -store"
128
129         for cons in $SET_FONT_TERMINALS; do
130                 /usr/bin/open -c $cons -s -w -- /usr/bin/setterm $setterm_option
131         done
132         if [[ "$tty" = [0-9]* ]]; then
133                 /usr/bin/switchto $tty
134         fi
135
136         touch /var/lock/subsys/console
137 }
138
139 RETVAL=0
140 case "$1" in
141   start)
142         if [ ! -f /var/lock/subsys/console ]; then
143                 start
144         fi
145         ;;
146   restart)
147         start
148         ;;
149   try-restart)
150         if [ -f /var/lock/subsys/console ]; then
151                 start
152         fi
153         ;;
154   reload|force-reload)
155         if [ -f /var/lock/subsys/console ]; then
156                 start
157         else
158                 RETVAL=7
159         fi
160         ;;
161   stop)
162         if [ -f /var/lock/subsys/console ]; then
163                 run_cmd "Setting terminals to default values" /usr/bin/setterm -default
164                 rm -f /var/lock/subsys/console
165         fi
166         ;;
167   status)
168         /usr/bin/setleds
169         ;;
170   *)
171         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
172         exit 3
173 esac
174
175 exit $RETVAL
This page took 0.063644 seconds and 4 git commands to generate.