Drop grml-postfix
[grml-scripts.git] / usr_sbin / grml-setkeyboard
1 #!/bin/sh
2 # Filename:      grml-setkeyboard
3 # Purpose:       set keyboard layout system-wide on grml system
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 PN="$(basename $0)"
10 DIALOG=dialog
11 CMDLINE=/proc/cmdline
12
13 . /etc/grml/script-functions
14
15 check4root || exit 1
16
17 setvalue(){
18   [ -n "$2" ] || return 1
19   # already present in conffile?
20   if grep -q ${1} $CONFFILE ; then
21      sed -i "s#^${1}.*#${1}=${2}#"   $CONFFILE
22   else
23      echo "$1=${2}" >> $CONFFILE
24   fi
25 }
26
27 # same for strings
28 stringinstring(){
29   case "$2" in *$1*) return 0;; esac
30   return 1
31 }
32
33 # Reread boot command line; echo last parameter's argument or return false.
34 getbootparam(){
35   stringinstring " $1=" "$CMDLINE" || return 1
36   result="${CMDLINE##*$1=}"
37   result="${result%%[   ]*}"
38   echo "$result"
39   return 0
40 }
41
42 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
43
44 [ -n "$KEYTABLE" ] && DEFAULT_KEYBOARD="$KEYTABLE"
45 if [ -z "$DEFAULT_KEYBOARD" ] ; then
46   DEFAULT_KEYBOARD="$(getbootparam lang 2>/dev/null)"
47   if [ -z "$DEFAULT_KEYBOARD" ] ; then
48     DEFAULT_KEYBOARD=en
49   fi
50 fi
51
52 LANGUAGE=$(LANG=C $DIALOG --stdout --title "$PN" --default-item $DEFAULT_KEYBOARD --radiolist \
53 "Which keyboard layout do you want to use?
54
55 Please notice that this will not really affect your currently running system.
56 If you want to change keyboard settings temporarly please use grml-lang instead.
57
58 Configuration will be written to /etc/sysconfig/keyboard" 0 0 0 \
59  at  austrian off \
60  be  belgian off \
61  bg  bulgarian off \
62  cf  "french canadian" off \
63  ch  swiss off \
64  cn  chinese off \
65  cs  czech off \
66  cz  czech off \
67  da  da off \
68  de  german   off \
69  dk  dansk off \
70  en  "english [us] (default)" on \
71  es  spanish off \
72  fi  finnish off \
73  fr  french off \
74  he  hebrew off \
75  ie  irish off \
76  il  hebrew off \
77  it  italian off \
78  ja  japanese off \
79  nl  dutch off \
80  pl  polish off \
81  ru  russian off \
82  sk  slovak off \
83  sl  slovenian off \
84  tr  turkish off \
85  tw  "chinese (traditional)" off \
86  uk  british off \
87 )
88
89 retval=$?
90 case $retval in
91     (0)
92           # everything ok
93           ;;
94     (1)   echo "Cancel pressed." ; exit 1 ;;
95     (255) echo "ESC pressed."    ; exit 1 ;;
96 esac
97
98 # read in the file where all the $LANGUAGE stuff is defined
99   . /etc/grml/language-functions
100
101 cat > /etc/sysconfig/keyboard <<EOF
102 # File generated by $PN on $(date)
103 KEYTABLE="$KEYTABLE"
104 XKEYBOARD="$XKEYBOARD"
105 KDEKEYBOARD="$KDEKEYBOARD"
106 KDEKEYBOARDS="$KDEKEYBOARD"
107 EOF
108
109 retval=$?
110 case $retval in
111     (0)
112           # everything ok
113           LANG=C $DIALOG --stdout --msgbox "Writing keyboard settings ($KEYTABLE) to /etc/sysconfig/keyboard was successful." 0 0
114           ;;
115     *)
116           LANG=C $DIALOG --stdout --msgbox "Error writing settings for $KEYTABLE to /etc/sysconfig/keyboard." 0 0
117           ;;
118 esac
119
120 ## END OF FILE #################################################################