Skip to content

Commit 0afef82

Browse files
committed
Import grml-lang, grml-setlang from grml-scripts
Unmodified. Preparation for grml/grml#232. grml-scripts removal side is PR grml/grml-scripts#25. Part of the discussion in grml/grml#225.
1 parent a6f973b commit 0afef82

File tree

4 files changed

+411
-0
lines changed

4 files changed

+411
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/bash
2+
# Filename: grml-lang
3+
# Purpose: load specific keyboard layout settings
4+
# Authors: grml-team (grml.org), (c) Michael Prokop <[email protected]>
5+
# Bug-Reports: see http://grml.org/bugs/
6+
# License: This file is licensed under the GPL v2.
7+
################################################################################
8+
9+
CONFFILE=/etc/default/keyboard
10+
PN="$(basename "$0")"
11+
12+
usage(){
13+
echo "Usage: ${PN} <language>"
14+
echo "supported values: at, ch, de, dvorak, es, fr, it, jp, uk, us"
15+
}
16+
17+
setvalue(){
18+
[ -n "$2" ] || return 1
19+
sudo sed -i "s#^${1}=.*#${1}=\"${2}\"#" "${CONFFILE}"
20+
}
21+
22+
if [ $# -lt "1" ] ; then
23+
usage >&2
24+
exit 1
25+
fi
26+
27+
LANGUAGE="$1"
28+
29+
# shellcheck disable=SC1091
30+
. /etc/grml/language-functions
31+
32+
if [ -n "$XKEYBOARD" ] ; then
33+
setvalue XKBLAYOUT "$XKEYBOARD"
34+
fi
35+
36+
if [ -z "$DISPLAY" ] ;then
37+
if [ "$1" = "de" ] ; then
38+
echo "Loading keymap for Germany..."
39+
sudo loadkeys i386/qwertz/de-latin1-nodeadkeys.kmap.gz
40+
echo -e "\nDone."
41+
elif [ "$1" = "at" ] ; then
42+
echo "Loading keymap for Austria..."
43+
sudo loadkeys i386/qwertz/de-latin1-nodeadkeys.kmap.gz
44+
echo -e "\nDone."
45+
elif [ "$1" = "ch" ] ; then
46+
echo "Loading keymap for Switzerland..."
47+
sudo loadkeys i386/qwertz/sg-latin1.kmap.gz
48+
echo -e "\nDone."
49+
elif [ "$1" = "it" ] ; then
50+
echo "Loading keymap for Italy..."
51+
sudo loadkeys i386/qwerty/it.kmap.gz
52+
echo -e "\nDone."
53+
elif [ "$1" = "us" ] ; then
54+
echo 'Loading keymap us...'
55+
sudo loadkeys i386/qwerty/us-latin1.kmap.gz
56+
echo -e "\nDone."
57+
elif [ "$1" = "dvorak" ] ; then
58+
echo 'Loading keymap dvorak...'
59+
sudo loadkeys dvorak
60+
echo -e "\nDone."
61+
elif [ "$1" = "jp" ] ; then
62+
echo 'Loading keymap jp...'
63+
sudo loadkeys i386/qwerty/jp106.kmap.gz
64+
echo -e "\nDone."
65+
elif [ "$1" = "es" ] ; then
66+
echo 'Loading keymap es...'
67+
sudo loadkeys i386/qwerty/es.kmap.gz
68+
echo -e "\nDone."
69+
elif [ "$1" = "fr" ] ; then
70+
echo 'Loading keymap fr...'
71+
sudo loadkeys i386/azerty/fr.kmap.gz
72+
echo -e "\nDone."
73+
elif [ "$1" = "uk" ] ; then
74+
echo 'Loading keymap uk...'
75+
sudo loadkeys i386/qwerty/uk.kmap.gz
76+
echo -e "\nDone."
77+
else echo "No valid parameter given.
78+
79+
Notice: Use loadkeys on console and setxkbmap when running X for
80+
modifying keyboard layout. Adjust \$LANG and \$LC_ALL for setting locales." ; exit 1
81+
fi
82+
# switch to unicode mode on console
83+
case $LANG in *UTF-8) kbd_mode -u ; ;; esac
84+
else
85+
if [ $# = 0 ] ; then
86+
usage
87+
else
88+
if [ "$1" = "de" ] ; then
89+
echo "Loading keymap for Germany..."
90+
if [ -r "${HOME}"/.Xmodmap.german ] ; then
91+
xmodmap "${HOME}"/.Xmodmap.german || setxkbmap de
92+
else
93+
setxkbmap de
94+
fi
95+
echo -e "\nDone."
96+
elif [ "$1" = "at" ] ; then
97+
echo "Loading keymap for Austria..."
98+
setxkbmap de
99+
echo -e "\nDone."
100+
elif [ "$1" = "ch" ] ; then
101+
echo "Loading keymap for Switzerland..."
102+
setxkbmap ch
103+
echo -e "\nDone."
104+
elif [ "$1" = "it" ] ; then
105+
echo "Loading keymap for Italy..."
106+
setxkbmap it
107+
echo -e "\nDone."
108+
elif [ "$1" = "jp" ] ; then
109+
echo "Loading keymap for Japan..."
110+
setxkbmap -model jp106 -layout jp
111+
echo -e "\nDone."
112+
elif [ "$1" = "dvorak" ] ; then
113+
echo "Loading keymap dvorak..."
114+
setxkbmap dvorak
115+
echo -e "\nDone."
116+
elif [ "$1" = "us" ] ; then
117+
echo 'Loading keymap us...'
118+
if [ -r "${HOME}"/.Xmodmap ] ; then
119+
xmodmap "${HOME}"/.Xmodmap || setxkbmap us
120+
else
121+
setxkbmap us
122+
fi
123+
echo -e "\nDone."
124+
elif [ "$1" = "es" ] ; then
125+
echo "Loading keymap es..."
126+
setxkbmap es
127+
echo -e "\nDone."
128+
elif [ "$1" = "fr" ] ; then
129+
echo "Loading keymap fr..."
130+
setxkbmap fr
131+
echo -e "\nDone."
132+
elif [ "$1" = "uk" ] ; then
133+
echo "Loading keymap gb for uk..."
134+
setxkbmap gb
135+
echo -e "\nDone."
136+
else
137+
echo "No valid parameter given."
138+
echo
139+
usage
140+
echo
141+
echo "Notice: Use loadkeys on console and setxkbmap when running X for
142+
modifying keyboard layout. Adjust \$LANG and \$LC_ALL for setting locales." ; exit 1
143+
fi
144+
fi
145+
fi
146+
147+
## END OF FILE #################################################################
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
#!/bin/sh
2+
# Filename: grml-setlang
3+
# Purpose: set language system-wide on grml system
4+
# Authors: grml-team (grml.org), (c) Michael Prokop <[email protected]>
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+
LANGFUNC=/etc/grml/language-functions
12+
13+
# notice: Debian's locales.postinst has been modified to write
14+
# locale variables into /etc/default/locale instead of
15+
# /etc/environment; the latter file is a PAM configuration file,
16+
# so modifying it was a policy violation.
17+
CONFFILE=/etc/default/locale
18+
19+
# shellcheck disable=SC1091
20+
{
21+
. /etc/grml/script-functions
22+
. /etc/grml/lsb-functions
23+
}
24+
25+
check4root || exit 100
26+
27+
eindent # as we are running inside grml boot sequence as well make sure we integrate fine
28+
29+
# allow writing $CONFFILE non-interactive via "grml-setlang $LANGUAGE"
30+
if [ -n "$1" ] ; then
31+
NONINTERACTIVE=1
32+
else
33+
NONINTERACTIVE=''
34+
fi
35+
36+
if ! [ -r "$LANGFUNC" ] ; then
37+
echo "$LANGFUNC could not be read. Make sure you have package grml-autoconfig installed." >&2
38+
exit 1
39+
fi
40+
41+
setvalue(){
42+
[ -n "$2" ] || return 1
43+
# already present in conffile?
44+
if grep -q "^${1}" "$CONFFILE" ; then
45+
sed -i "s#^${1}.*#${1}${2}#" $CONFFILE
46+
# is the new Debian style /etc/default/locale present?
47+
elif grep -q "^# ${1}$" "$CONFFILE" ; then
48+
# shellcheck disable=SC1117
49+
sed -i "s#^\# ${1}#${1}${2}#" $CONFFILE
50+
else
51+
echo "$1${2}" >> $CONFFILE
52+
fi
53+
}
54+
55+
# grml-small does not provide any further locales
56+
if grep -q small /etc/grml_version 2>/dev/null ; then
57+
if [ -z "$NONINTERACTIVE" ] ; then
58+
LANG=C $DIALOG --stdout --msgbox "Notice: grml-small does not provide a full language setup.
59+
60+
You have to make sure the appropriate packages are installed." 0 0
61+
exit 1
62+
else
63+
esyslog user.notice "$PN" 'grml-small does not provide a full language setup.'
64+
fi
65+
fi
66+
67+
# shellcheck disable=SC1091
68+
{
69+
[ -r /etc/environment ] && . /etc/environment
70+
[ -r /etc/default/locale ] && . /etc/default/locale
71+
}
72+
[ -n "$LANGUAGE" ] && DEFAULT_LANGUAGE="$LANGUAGE"
73+
74+
if [ -z "$DEFAULT_LANGUAGE" ] ; then
75+
DEFAULT_LANGUAGE=en
76+
fi
77+
78+
if [ -z "$NONINTERACTIVE" ] ; then
79+
# shellcheck disable=SC1010
80+
{
81+
LANGUAGE=$(LANG=C $DIALOG --stdout --title "$PN" --default-item $DEFAULT_LANGUAGE --radiolist \
82+
"Which language do you want to use?
83+
84+
This will affect \$LANG, \$LANGUAGE and \$LC_MESSAGES.
85+
86+
Notice: if you want to adjust /etc/locale.gen (defines
87+
which locales should be generated by locale-gen)
88+
please run 'dpkg-reconfigure locales' manually.
89+
90+
Configuration will be written to $CONFFILE" 0 0 0 \
91+
at 'austria (unicode version)' off \
92+
at-iso 'austrian (iso version)' off \
93+
au 'austrial (unicode version)' off \
94+
au-iso 'australian (iso version)' off \
95+
be 'belgian (unicode version)' off \
96+
be-iso 'belgian (iso version)' off \
97+
bg 'bulgarian (unicode version)' off \
98+
bg-iso 'bulgarian (iso version)' off \
99+
br 'brazilian (unicode version)' off \
100+
br-iso 'brazilian (iso version)' off \
101+
ch 'swiss (unicode version)' off \
102+
ch-iso 'swiss (iso version)' off \
103+
cf 'french canadian' off \
104+
cn 'chinese (unicode version)' off \
105+
cn-iso 'chinese (iso version)' off \
106+
cs 'czech (unicode version)' off \
107+
cs-iso 'czech (iso version)' off \
108+
cz 'czech (unicode version)' off \
109+
cz-iso 'czech (iso version)' off \
110+
de 'german (unicode version)' off \
111+
de-iso 'german (iso version)' off \
112+
dk 'dansk (unicode version)' off \
113+
dk-iso 'dansk (iso version)' off \
114+
da 'dansk (unicode version)' off \
115+
da-iso 'dansk (iso version)' off \
116+
el 'greek (unicode version)' off \
117+
el-iso 'greek (iso version)' off \
118+
en 'english [us] (unicode version, grml default)' on \
119+
en-iso 'english [us] (iso version)' off \
120+
es 'spanish (unicode version)' off \
121+
es-iso 'spanish (iso version)' off \
122+
fi 'finnish (unicode version)' off \
123+
fi-iso 'finnish (iso version)' off \
124+
fr 'frensh (unicode version)' off \
125+
fr-iso 'frensh (iso version)' off \
126+
ga 'irish gaeilge (unicode version)' off \
127+
ga-iso 'irish gaeilge (iso version)' off \
128+
he 'hebrew (unicode version)' off \
129+
he-iso 'hebrew (iso version)' off \
130+
il 'hebrew (unicode version)' off \
131+
il-iso 'hebrew (iso version)' off \
132+
ie 'irish (unicode version)' off \
133+
ie-iso 'irish (iso version)' off \
134+
it 'italian (unicode version)' off \
135+
it-iso 'italian (iso version)' off \
136+
ja 'japanese (unicode version)' off \
137+
ja-iso 'japanese (iso version)' off \
138+
nl 'dutch (unicode version)' off \
139+
nl-iso 'dutch (iso version)' off \
140+
pl 'polish (unicode version)' off \
141+
pl-iso 'polisch (iso version)' off \
142+
pt 'portuguese (unicode version)' off \
143+
pt-iso 'portuguese (iso version)' off \
144+
ru 'russian (unicode version)' off \
145+
ru-iso 'russian (iso version)' off \
146+
sk 'slovak (unicode version)' off \
147+
sk-iso 'slovak (iso version)' off \
148+
sl 'slovenian (unicode version)' off \
149+
sl-iso 'slovenian (iso version)' off \
150+
tr 'turkish (unicode version)' off \
151+
tr-iso 'turkish (iso version)' off \
152+
tw 'chinese (traditional) (unicode version)' off \
153+
tw-iso 'chinese (traditional) (iso version)' off \
154+
uk 'british (unicode version)' off \
155+
uk-iso 'british (iso version)' off \
156+
us 'american (unicode version)' off \
157+
us-iso 'american (iso version)' off \
158+
)
159+
}
160+
161+
retval=$?
162+
case $retval in
163+
(0) # everything ok
164+
;;
165+
(1) echo "Cancel pressed." ; exit 1 ;;
166+
(255) echo "ESC pressed." ; exit 1 ;;
167+
esac
168+
169+
else # non-interactive
170+
LANGUAGE="$1"
171+
fi
172+
173+
if ! grep -qe "${LANGUAGE})" -qe "${LANGUAGE}|" $LANGFUNC ; then
174+
ewarn "Language ${LANGUAGE} not supported, using default." ; eend 0
175+
fi
176+
177+
# fallback to C if using an ISO system (which is latin1 for LC_CTYPE);
178+
# this should prevent users from broken ctype settings if the set
179+
# locale isn't available on a remote system
180+
if echo "$LANGUAGE" | grep -q -- '-iso' ; then
181+
LC_CTYPE=C
182+
fi
183+
184+
# read in the file where all the $LANGUAGE stuff is defined
185+
# shellcheck disable=SC1090
186+
. $LANGFUNC
187+
188+
# make sure the file exists
189+
if ! [ -r $CONFFILE ] ; then
190+
cat > $CONFFILE <<EOF
191+
# File generated by $PN on $(date)
192+
LANG=$LANG
193+
# LC_CTYPE=$LC_CTYPE
194+
# LANGUAGE=$LANGUAGE
195+
# TZ=$TZ
196+
# other environment variables you might want to set:
197+
# LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY
198+
# LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS
199+
# LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION
200+
#
201+
# Note: set LC_ALL to overwrite all LC_* variables
202+
# LC_ALL > LC_* > LANG
203+
# LANGUAGE is glibc only and binds stronger than LC_ALL
204+
EOF
205+
fi
206+
207+
setvalue 'LANG=' "$LANG"
208+
209+
retval=$?
210+
case $retval in
211+
(0)
212+
if [ -z "$NONINTERACTIVE" ] ; then
213+
LANG=C $DIALOG --stdout --msgbox "Writing language settings ($LANGUAGE) to $CONFFILE was successful." 0 0
214+
else
215+
einfo "Writing language settings ($LANGUAGE) to $CONFFILE was successful."
216+
esyslog user.notice "$PN" "Writing language settings ($LANGUAGE) to $CONFFILE was successful." ; eend 0
217+
fi
218+
;;
219+
*)
220+
if [ -z "$NONINTERACTIVE" ] ; then
221+
LANG=C $DIALOG --stdout --msgbox "Error writing settings for $LANGUAGE to $CONFFILE." 0 0
222+
else
223+
eerror "Error writing settings for $LANGUAGE to $CONFFILE." ; eend 1
224+
esyslog user.notice "$PN" "Error writing settings for $LANGUAGE to $CONFFILE."
225+
fi
226+
;;
227+
esac
228+
229+
eoutdent
230+
231+
## END OF FILE #################################################################

0 commit comments

Comments
 (0)