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