Release new version 2.13.0
[grml-scripts.git] / usr_sbin / grml-setlang
index f8cb28b..4a15d5c 100755 (executable)
@@ -4,12 +4,10 @@
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Mit Sep 05 18:33:23 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
 
@@ -44,6 +45,7 @@ setvalue(){
      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
@@ -62,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
@@ -71,6 +76,8 @@ if [ -z "$DEFAULT_LANGUAGE" ] ; then
 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?
 
@@ -149,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
@@ -166,29 +174,37 @@ 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 <<EOF
 # File generated by $PN on $(date)
-LANGUAGE=$LANGUAGE
 LANG=$LANG
-LC_MESSAGES=$LANG
+# LC_CTYPE=$LC_CTYPE
+# LANGUAGE=$LANGUAGE
 # TZ=$TZ
 # other environment variables you might want to set:
-# LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY
-# LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE
-# LC_MEASUREMENT LC_IDENTIFICATION
-# Notice: set LC_ALL to overwrite all LC_* variables
+# 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 'LANGUAGE='    $LANGUAGE
-setvalue 'LANG='        $LANG
-setvalue 'LC_MESSAGES=' $LANG
-# setvalue 'TZ='          $TZ
+setvalue 'LANG='     "$LANG"
 
 retval=$?
 case $retval in