X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml-setlang;h=4a15d5cf86249eaa3247ae3eb91ff4e97c1c69d3;hb=3b7f948896440f41092f14347b17ce114072c569;hp=c74447bd57738b15d900527963183e3832537266;hpb=e720deae78f1eda5e6f62629606c194f16796762;p=grml-scripts.git diff --git a/usr_sbin/grml-setlang b/usr_sbin/grml-setlang index c74447b..4a15d5c 100755 --- a/usr_sbin/grml-setlang +++ b/usr_sbin/grml-setlang @@ -4,12 +4,10 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Mit Okt 04 11:54:45 CEST 2006 [mika] ################################################################################ -PN="$(basename $0)" +PN="$(basename "$0")" DIALOG=dialog -CMDLINE=/proc/cmdline LANGFUNC=/etc/grml/language-functions # notice: Debian's locales.postinst has been modified to write @@ -18,8 +16,11 @@ LANGFUNC=/etc/grml/language-functions # 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 @@ -40,8 +41,12 @@ fi setvalue(){ [ -n "$2" ] || return 1 # already present in conffile? - if grep -q ${1} $CONFFILE ; then - sed -i "s#^${1}.*#${1}${2}#" $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 @@ -50,7 +55,7 @@ setvalue(){ # grml-small does not provide any further locales if grep -q small /etc/grml_version 2>/dev/null ; then if [ -z "$NONINTERACTIVE" ] ; then - $DIALOG --stdout --msgbox "Notice: grml-small does not provide a full language setup. + 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 @@ -59,8 +64,11 @@ You have to make sure the appropriate packages are installed." 0 0 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 @@ -68,82 +76,87 @@ if [ -z "$DEFAULT_LANGUAGE" ] ; then fi if [ -z "$NONINTERACTIVE" ] ; then - LANGUAGE=$($DIALOG --stdout --title "$PN" --default-item $DEFAULT_LANGUAGE --radiolist \ +# 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, \$LC_MESSAGES and \$TZ. +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 locale' manually. +please run 'dpkg-reconfigure locales' manually. Configuration will be written to $CONFFILE" 0 0 0 \ - at austrian off \ - at-utf8 'austria (unicode version)' off \ - au australian off \ - au-utf8 'austrial (unicode version)' off \ - be belgian off \ - be-utf8 'belgian (unicode version)' off \ - bg bulgarian off \ - bg-utf8 'bulgarian (unicode version)' off \ - br brazilian off \ - br-utf8 'brazilian (unicode version)' off \ - ch swiss off \ - ch-utf8 'swiss (unicode version)' off \ + 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 off \ - cn-utf8 'chinese (unicode version)' off \ - cs czech off \ - cs-utf8 'czech (unicode version)' off \ - cz czech off \ - cz-utf8 'czech (unicode version)' off \ - de german off \ - de-utf8 'german (unicode version)' off \ - dk dansk off \ - dk-utf8 'dansk (unicode version)' off \ - da dansk off \ - da-utf8 'dansk (unicode version)' off \ - el greek off \ - el-utf8 'greek (unicode version)' off \ - en 'english [us] (default)' on \ - es spanish off \ - es-utf8 'spanish (unicode version)' off \ - fi finnish off \ - fi-utf8 'finnish (unicode version)' off \ - fr frensh off \ - fr-utf8 'frensh (unicode version)' off \ - ga 'irish gaeilge' off \ - ga-utf8 'irish gaeilge (unicode version)' off \ - he hebrew off \ - he-utf8 'hebrew (unicode version)' off \ - il hebrew off \ - il-utf8 'hebrew (unicode version)' off \ - ie irish off \ - ie-utf8 'irish (unicode version)' off \ - it italian off \ - it-utf8 'italian (unicode version)' off \ - ja japanese off \ - ja-utf8 'japanese (unicode version)' off \ - nl dutch off \ - nl-utf8 'dutch (unicode version)' off \ - pl off polish \ - pl-utf8 'polish (unicode version)' off \ - pt portuguese off \ - pt-utf8 'portuguese (unicode version)' off \ - ru russian off \ - ru-utf8 'russian (unicode version)' off \ - sk slovak off \ - sk-utf8 'slovak (unicode version)' off \ - sl slovenian off \ - sl-utf8 'slovenian (unicode version)' off \ - tr turkish off \ - tr-utf8 'turkish (unicode version)' off \ - tw 'chinese (traditional)' off \ - tw-utf8 'chinese (traditional) (unicode version)' off \ - uk british off \ - uk-utf8 'british (unicode version)' off \ - us-utf8 'american (unicode version)' 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 @@ -157,39 +170,47 @@ else # non-interactive LANGUAGE="$1" fi -if ! grep -q "${LANGUAGE})" $LANGFUNC ; then +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 - source $LANGFUNC +# shellcheck disable=SC1090 +. $LANGFUNC # make sure the file exists if ! [ -r $CONFFILE ] ; then cat > $CONFFILE < LC_* > LANG +# LANGUAGE is glibc only and binds stronger than LC_ALL EOF fi -setvalue 'LANGUAGE=' $LANGUAGE -setvalue 'LANG=' $LANG -setvalue 'LC_MESSAGES=' $LANG -setvalue 'TZ=' $TZ +setvalue 'LANG=' "$LANG" retval=$? case $retval in (0) if [ -z "$NONINTERACTIVE" ] ; then - $DIALOG --stdout --msgbox "Writing language settings ($LANGUAGE) to $CONFFILE was successful." 0 0 + 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 @@ -197,7 +218,7 @@ case $retval in ;; *) if [ -z "$NONINTERACTIVE" ] ; then - $DIALOG --stdout --msgbox "Error writing settings for $LANGUAGE to $CONFFILE." 0 0 + 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."