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