Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions config/files/GRMLBASE/usr/bin/grml-lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/bin/bash
# Filename: grml-lang
# Purpose: load specific keyboard layout settings
# Authors: grml-team (grml.org), (c) Michael Prokop <[email protected]>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
################################################################################

CONFFILE=/etc/default/keyboard
PN="$(basename "$0")"

usage(){
echo "Usage: ${PN} <language>"
echo "supported values: at, ch, de, dvorak, es, fr, it, jp, uk, us"
}

setvalue(){
[ -n "$2" ] || return 1
sudo sed -i "s#^${1}=.*#${1}=\"${2}\"#" "${CONFFILE}"
}

if [ $# -lt "1" ] ; then
usage >&2
exit 1
fi

LANGUAGE="$1"

# shellcheck disable=SC1091
. /etc/grml/language-functions

if [ -n "$XKEYBOARD" ] ; then
setvalue XKBLAYOUT "$XKEYBOARD"
fi

if [ -z "$DISPLAY" ] ;then
if [ "$1" = "de" ] ; then
echo "Loading keymap for Germany..."
sudo loadkeys i386/qwertz/de-latin1-nodeadkeys.kmap.gz
echo -e "\nDone."
elif [ "$1" = "at" ] ; then
echo "Loading keymap for Austria..."
sudo loadkeys i386/qwertz/de-latin1-nodeadkeys.kmap.gz
echo -e "\nDone."
elif [ "$1" = "ch" ] ; then
echo "Loading keymap for Switzerland..."
sudo loadkeys i386/qwertz/sg-latin1.kmap.gz
echo -e "\nDone."
elif [ "$1" = "it" ] ; then
echo "Loading keymap for Italy..."
sudo loadkeys i386/qwerty/it.kmap.gz
echo -e "\nDone."
elif [ "$1" = "us" ] ; then
echo 'Loading keymap us...'
sudo loadkeys i386/qwerty/us-latin1.kmap.gz
echo -e "\nDone."
elif [ "$1" = "dvorak" ] ; then
echo 'Loading keymap dvorak...'
sudo loadkeys dvorak
echo -e "\nDone."
elif [ "$1" = "jp" ] ; then
echo 'Loading keymap jp...'
sudo loadkeys i386/qwerty/jp106.kmap.gz
echo -e "\nDone."
elif [ "$1" = "es" ] ; then
echo 'Loading keymap es...'
sudo loadkeys i386/qwerty/es.kmap.gz
echo -e "\nDone."
elif [ "$1" = "fr" ] ; then
echo 'Loading keymap fr...'
sudo loadkeys i386/azerty/fr.kmap.gz
echo -e "\nDone."
elif [ "$1" = "uk" ] ; then
echo 'Loading keymap uk...'
sudo loadkeys i386/qwerty/uk.kmap.gz
echo -e "\nDone."
else echo "No valid parameter given.

Notice: Use loadkeys on console and setxkbmap when running X for
modifying keyboard layout. Adjust \$LANG and \$LC_ALL for setting locales." ; exit 1
fi
# switch to unicode mode on console
case $LANG in *UTF-8) kbd_mode -u ; ;; esac
else
if [ $# = 0 ] ; then
usage
else
if [ "$1" = "de" ] ; then
echo "Loading keymap for Germany..."
if [ -r "${HOME}"/.Xmodmap.german ] ; then
xmodmap "${HOME}"/.Xmodmap.german || setxkbmap de
else
setxkbmap de
fi
echo -e "\nDone."
elif [ "$1" = "at" ] ; then
echo "Loading keymap for Austria..."
setxkbmap de
echo -e "\nDone."
elif [ "$1" = "ch" ] ; then
echo "Loading keymap for Switzerland..."
setxkbmap ch
echo -e "\nDone."
elif [ "$1" = "it" ] ; then
echo "Loading keymap for Italy..."
setxkbmap it
echo -e "\nDone."
elif [ "$1" = "jp" ] ; then
echo "Loading keymap for Japan..."
setxkbmap -model jp106 -layout jp
echo -e "\nDone."
elif [ "$1" = "dvorak" ] ; then
echo "Loading keymap dvorak..."
setxkbmap dvorak
echo -e "\nDone."
elif [ "$1" = "us" ] ; then
echo 'Loading keymap us...'
if [ -r "${HOME}"/.Xmodmap ] ; then
xmodmap "${HOME}"/.Xmodmap || setxkbmap us
else
setxkbmap us
fi
echo -e "\nDone."
elif [ "$1" = "es" ] ; then
echo "Loading keymap es..."
setxkbmap es
echo -e "\nDone."
elif [ "$1" = "fr" ] ; then
echo "Loading keymap fr..."
setxkbmap fr
echo -e "\nDone."
elif [ "$1" = "uk" ] ; then
echo "Loading keymap gb for uk..."
setxkbmap gb
echo -e "\nDone."
else
echo "No valid parameter given."
echo
usage
echo
echo "Notice: Use loadkeys on console and setxkbmap when running X for
modifying keyboard layout. Adjust \$LANG and \$LC_ALL for setting locales." ; exit 1
fi
fi
fi

## END OF FILE #################################################################
231 changes: 231 additions & 0 deletions config/files/GRMLBASE/usr/sbin/grml-setlang
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
#!/bin/sh
# Filename: grml-setlang
# Purpose: set language system-wide on grml system
# Authors: grml-team (grml.org), (c) Michael Prokop <[email protected]>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
################################################################################

PN="$(basename "$0")"
DIALOG=dialog
LANGFUNC=/etc/grml/language-functions

# notice: Debian's locales.postinst has been modified to write
# locale variables into /etc/default/locale instead of
# /etc/environment; the latter file is a PAM configuration file,
# so modifying it was a policy violation.
CONFFILE=/etc/default/locale

# shellcheck disable=SC1091
{
. /etc/grml/script-functions
. /etc/grml/lsb-functions
}

check4root || exit 100

eindent # as we are running inside grml boot sequence as well make sure we integrate fine

# allow writing $CONFFILE non-interactive via "grml-setlang $LANGUAGE"
if [ -n "$1" ] ; then
NONINTERACTIVE=1
else
NONINTERACTIVE=''
fi

if ! [ -r "$LANGFUNC" ] ; then
echo "$LANGFUNC could not be read. Make sure you have package grml-autoconfig installed." >&2
exit 1
fi

setvalue(){
[ -n "$2" ] || return 1
# already present in conffile?
if grep -q "^${1}" "$CONFFILE" ; then
sed -i "s#^${1}.*#${1}${2}#" $CONFFILE
# is the new Debian style /etc/default/locale present?
elif grep -q "^# ${1}$" "$CONFFILE" ; then
# shellcheck disable=SC1117
sed -i "s#^\# ${1}#${1}${2}#" $CONFFILE
else
echo "$1${2}" >> $CONFFILE
fi
}

# grml-small does not provide any further locales
if grep -q small /etc/grml_version 2>/dev/null ; then
if [ -z "$NONINTERACTIVE" ] ; then
LANG=C $DIALOG --stdout --msgbox "Notice: grml-small does not provide a full language setup.

You have to make sure the appropriate packages are installed." 0 0
exit 1
else
esyslog user.notice "$PN" 'grml-small does not provide a full language setup.'
fi
fi

# shellcheck disable=SC1091
{
[ -r /etc/environment ] && . /etc/environment
[ -r /etc/default/locale ] && . /etc/default/locale
}
[ -n "$LANGUAGE" ] && DEFAULT_LANGUAGE="$LANGUAGE"

if [ -z "$DEFAULT_LANGUAGE" ] ; then
DEFAULT_LANGUAGE=en
fi

if [ -z "$NONINTERACTIVE" ] ; then
# shellcheck disable=SC1010
{
LANGUAGE=$(LANG=C $DIALOG --stdout --title "$PN" --default-item $DEFAULT_LANGUAGE --radiolist \
"Which language do you want to use?

This will affect \$LANG, \$LANGUAGE and \$LC_MESSAGES.

Notice: if you want to adjust /etc/locale.gen (defines
which locales should be generated by locale-gen)
please run 'dpkg-reconfigure locales' manually.

Configuration will be written to $CONFFILE" 0 0 0 \
at 'austria (unicode version)' off \
at-iso 'austrian (iso version)' off \
au 'austrial (unicode version)' off \
au-iso 'australian (iso version)' off \
be 'belgian (unicode version)' off \
be-iso 'belgian (iso version)' off \
bg 'bulgarian (unicode version)' off \
bg-iso 'bulgarian (iso version)' off \
br 'brazilian (unicode version)' off \
br-iso 'brazilian (iso version)' off \
ch 'swiss (unicode version)' off \
ch-iso 'swiss (iso version)' off \
cf 'french canadian' off \
cn 'chinese (unicode version)' off \
cn-iso 'chinese (iso version)' off \
cs 'czech (unicode version)' off \
cs-iso 'czech (iso version)' off \
cz 'czech (unicode version)' off \
cz-iso 'czech (iso version)' off \
de 'german (unicode version)' off \
de-iso 'german (iso version)' off \
dk 'dansk (unicode version)' off \
dk-iso 'dansk (iso version)' off \
da 'dansk (unicode version)' off \
da-iso 'dansk (iso version)' off \
el 'greek (unicode version)' off \
el-iso 'greek (iso version)' off \
en 'english [us] (unicode version, grml default)' on \
en-iso 'english [us] (iso version)' off \
es 'spanish (unicode version)' off \
es-iso 'spanish (iso version)' off \
fi 'finnish (unicode version)' off \
fi-iso 'finnish (iso version)' off \
fr 'frensh (unicode version)' off \
fr-iso 'frensh (iso version)' off \
ga 'irish gaeilge (unicode version)' off \
ga-iso 'irish gaeilge (iso version)' off \
he 'hebrew (unicode version)' off \
he-iso 'hebrew (iso version)' off \
il 'hebrew (unicode version)' off \
il-iso 'hebrew (iso version)' off \
ie 'irish (unicode version)' off \
ie-iso 'irish (iso version)' off \
it 'italian (unicode version)' off \
it-iso 'italian (iso version)' off \
ja 'japanese (unicode version)' off \
ja-iso 'japanese (iso version)' off \
nl 'dutch (unicode version)' off \
nl-iso 'dutch (iso version)' off \
pl 'polish (unicode version)' off \
pl-iso 'polisch (iso version)' off \
pt 'portuguese (unicode version)' off \
pt-iso 'portuguese (iso version)' off \
ru 'russian (unicode version)' off \
ru-iso 'russian (iso version)' off \
sk 'slovak (unicode version)' off \
sk-iso 'slovak (iso version)' off \
sl 'slovenian (unicode version)' off \
sl-iso 'slovenian (iso version)' off \
tr 'turkish (unicode version)' off \
tr-iso 'turkish (iso version)' off \
tw 'chinese (traditional) (unicode version)' off \
tw-iso 'chinese (traditional) (iso version)' off \
uk 'british (unicode version)' off \
uk-iso 'british (iso version)' off \
us 'american (unicode version)' off \
us-iso 'american (iso version)' off \
)
}

retval=$?
case $retval in
(0) # everything ok
;;
(1) echo "Cancel pressed." ; exit 1 ;;
(255) echo "ESC pressed." ; exit 1 ;;
esac

else # non-interactive
LANGUAGE="$1"
fi

if ! grep -qe "${LANGUAGE})" -qe "${LANGUAGE}|" $LANGFUNC ; then
ewarn "Language ${LANGUAGE} not supported, using default." ; eend 0
fi

# fallback to C if using an ISO system (which is latin1 for LC_CTYPE);
# this should prevent users from broken ctype settings if the set
# locale isn't available on a remote system
if echo "$LANGUAGE" | grep -q -- '-iso' ; then
LC_CTYPE=C
fi

# read in the file where all the $LANGUAGE stuff is defined
# shellcheck disable=SC1090
. $LANGFUNC

# make sure the file exists
if ! [ -r $CONFFILE ] ; then
cat > $CONFFILE <<EOF
# File generated by $PN on $(date)
LANG=$LANG
# LC_CTYPE=$LC_CTYPE
# LANGUAGE=$LANGUAGE
# TZ=$TZ
# other environment variables you might want to set:
# LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY
# LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS
# LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION
#
# Note: set LC_ALL to overwrite all LC_* variables
# LC_ALL > LC_* > LANG
# LANGUAGE is glibc only and binds stronger than LC_ALL
EOF
fi

setvalue 'LANG=' "$LANG"

retval=$?
case $retval in
(0)
if [ -z "$NONINTERACTIVE" ] ; then
LANG=C $DIALOG --stdout --msgbox "Writing language settings ($LANGUAGE) to $CONFFILE was successful." 0 0
else
einfo "Writing language settings ($LANGUAGE) to $CONFFILE was successful."
esyslog user.notice "$PN" "Writing language settings ($LANGUAGE) to $CONFFILE was successful." ; eend 0
fi
;;
*)
if [ -z "$NONINTERACTIVE" ] ; then
LANG=C $DIALOG --stdout --msgbox "Error writing settings for $LANGUAGE to $CONFFILE." 0 0
else
eerror "Error writing settings for $LANGUAGE to $CONFFILE." ; eend 1
esyslog user.notice "$PN" "Error writing settings for $LANGUAGE to $CONFFILE."
fi
;;
esac

eoutdent

## END OF FILE #################################################################
Loading