X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml-setlang;h=4a15d5cf86249eaa3247ae3eb91ff4e97c1c69d3;hb=3b7f948896440f41092f14347b17ce114072c569;hp=df45be8468f2eca68e2d7435dba224aeaf5fbaf3;hpb=211befef6763c7cc998989345022348861c3bbf0;p=grml-scripts.git diff --git a/usr_sbin/grml-setlang b/usr_sbin/grml-setlang index df45be8..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: Sam Apr 28 17:38:28 CEST 2007 [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,7 +76,9 @@ 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 and \$LC_MESSAGES. @@ -146,6 +156,7 @@ Configuration will be written to $CONFFILE" 0 0 0 \ us 'american (unicode version)' off \ us-iso 'american (iso version)' off \ ) +} retval=$? case $retval in @@ -163,35 +174,43 @@ 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 @@ -199,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."