xref: /illumos-gate/usr/src/cmd/loadkeys/set_keyboard_layout (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
17c478bd9Sstevel@tonic-gate#! /usr/bin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6577f006cSdm89450# Common Development and Distribution License (the "License").
7577f006cSdm89450# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22*c24275a9Sja208388# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2348784e40Sdm89450# Use is subject to license terms.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
26fb620828Sqz150045# get the valid layout name from the eeprom and set it into kernel.
27fb620828Sqz150045# check space and tab to make sure that the kbd -s interaction mode
28fb620828Sqz150045# doesn't run here.
29e4603304Sqz150045KBD_LAYOUT_NVRAM_EXIST="`/usr/sbin/eeprom | grep keyboard-layout`"
30e4603304Sqz150045
31e4603304Sqz150045if test -n "$KBD_LAYOUT_NVRAM_EXIST"
32e4603304Sqz150045then
33fe539fb3Sqz150045	KBD_LAYOUT_NAME="`/usr/sbin/eeprom keyboard-layout |\
34fe539fb3Sqz150045			/usr/bin/sed -n 's/keyboard-layout=//g; s/[ |	]*//p'`"
35e4603304Sqz150045else
36e4603304Sqz150045	exit 0
37e4603304Sqz150045fi
387c478bd9Sstevel@tonic-gate
39*c24275a9Sja208388# The firmware on the keyboard may report "Taiwanese" and so
40*c24275a9Sja208388# translate it to the new "Traditional-Chinese" name as this is
41*c24275a9Sja208388# the preferred name to use.
42*c24275a9Sja208388if [ "$KBD_LAYOUT_NAME" = "Taiwanese" ]
43*c24275a9Sja208388then
44*c24275a9Sja208388       KBD_LAYOUT_NAME="Traditional-Chinese"
45*c24275a9Sja208388fi
46*c24275a9Sja208388
47fb620828Sqz150045if test -n "$KBD_LAYOUT_NAME"
48fb620828Sqz150045then
49fe539fb3Sqz150045	KBD_LAYOUT_NAME_STRING="^$KBD_LAYOUT_NAME="
50fe539fb3Sqz150045	LAYOUT_NAME_VALID="`cat /usr/share/lib/keytables/type_6/kbd_layouts | \
51e4603304Sqz150045                   	grep "$KBD_LAYOUT_NAME_STRING"`"
52fe539fb3Sqz150045else
53fe539fb3Sqz150045	exit 0
54fe539fb3Sqz150045fi
55fe539fb3Sqz150045
56fe539fb3Sqz150045if test -n "$LAYOUT_NAME_VALID"
57fe539fb3Sqz150045then
58fb620828Sqz150045	# Set the keyboard layout
597db6e34eSqz150045	/usr/bin/kbd -s $KBD_LAYOUT_NAME
60fb620828Sqz150045fi
61