diff packaging/linux-installer.inc.in @ 795:3a9b0c75f5a6

Added i18n code and german l10n to linux installer.
author Sascha Wilde <wilde@intevation.de>
date Tue, 15 Jul 2014 13:24:26 +0200
parents 2fb539d4b1ff
children 933860224d1e
line wrap: on
line diff
--- a/packaging/linux-installer.inc.in	Tue Jul 15 12:03:45 2014 +0200
+++ b/packaging/linux-installer.inc.in	Tue Jul 15 13:24:26 2014 +0200
@@ -29,6 +29,31 @@
   [PREFIX]=''
 )
 
+declare -A L10N_DE
+###L10N_DE###
+
+getxt()
+{
+  # Poor mans gettext for l10n completely self contained in one shell
+  # script.
+  MSGID="$1"
+  shift
+  case ${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-$LANG}}} in
+    de*)
+      if [ "${L10N_DE[$MSGID]}" ] ; then
+          MSG="${L10N_DE[$MSGID]}"
+      else
+        MSG="$MSGID"
+      fi
+      ;;
+    *)
+      MSG="$MSGID"
+      ;;
+  esac
+
+  printf "$MSG" "$@"
+}
+
 version()
 {
   cat <<EOF
@@ -46,11 +71,11 @@
 
 fatal()
 {
-  echo "$1" >&2
+  getxt "$1" >&2
   if [ $DEINSTALL -eq 1 ] ; then
-      echo "Deinstallation failed." >&2
+      getxt "Deinstallation failed.\n" >&2
   else
-    echo "Installation failed." >&2
+    getxt "Installation failed.\n" >&2
   fi
   exit 1
 }
@@ -87,7 +112,7 @@
         return 1
         ;;
       *)
-        echo >&2 "Answer [Y]es or [N]o: "
+        getxt >&2 "Answer [Y]es or [N]o:\n"
     esac
   done
 }
@@ -161,7 +186,7 @@
 read_oldinstcfg()
 {
   if [ -r "$instcfg_file" ] ; then
-      echo "Reading '$instcfg_file' ..."
+      getxt "Reading '%s' ...\n" "$instcfg_file"
       for key in "${!oldinstcfg[@]}" ; do
         oldinstcfg[$key]=`sed -n "/$key/s/[^=]*=\(.*\)/\1/p" "$instcfg_file"`
       done
@@ -171,7 +196,7 @@
 check_priv()
 {
   if [ $SYSINST -eq 1 -a "$UID" -ne 0 ] ; then
-      fatal "System wide installation requires root privileges!"
+      fatal "System wide installation requires root privileges!\n"
   fi
 }
 
@@ -183,7 +208,7 @@
   # long as they are empty.
   local directory="$1"
   while [ -d "$directory" -a -z "$(ls 2>/dev/null -A "$directory")" ] ; do
-    echo "Deleting empty directory '$directory' ..."
+    getxt "Deleting empty directory '%s' ...\n" "$directory"
     rmdir "$directory"
     directory=`dirname "$directory"`
   done
@@ -193,7 +218,7 @@
 {
   for file in "$@" ; do
     if [ -e "$file" ] ; then
-        echo "Deleting $file ..."
+        getxt "Deleting '%s' ...\n" "$file"
         rm "$file"
     fi
   done
@@ -236,23 +261,23 @@
   local cinst="${oldinstcfg[PREFIX]}/bin/cinst"
   local certlist=`ls 2>/dev/null -1  ${instdata_path}/list-*.txt | sort -nr | head -n 1`
 
-  echo "Uninstalling certificates ..."
+  getxt "Uninstalling certificates ...\n"
 
   if [ "$certlist" ] ; then
-      echo "Using certificate list '$certlist'."
+      getxt "Using certificate list '%s'.\n" "$certlist"
       if [ -x "$cinst" ] ; then
           "$cinst" "list=$certlist" "choices=uninstall"
       else
-        echo >&2 "WARNING: can't execute $cinst for certificate deinstallation."
+        getxt >&2 "WARNING: can't execute %s for certificate deinstallation.\n" "$cinst"
       fi
   else
-    echo "No certificate list found.  Nothing to do."
+    getxt "No certificate list found.  Nothing to do.\n"
   fi
 }
 
 deinstall_etc()
 {
-  echo "Removing cron job ..."
+  getxt "Removing cron job ...\n"
   remove_cronjob
 
   # FIXME: delete all files created by the application.
@@ -260,36 +285,39 @@
                       "${instcfg_path}/trustbridge-tray-starter.cfg"
                       "$instcfg_file" )
 
-  echo "Removing certificate lists from: ${instdata_path}:"
+  getxt "Removing certificate lists from: %s:\n" "$instdata_path"
   rm_files "$instdata_path"/list-*.txt
+
+  getxt "Removing PID file from: %s:\n" "$instdata_path"
+  rm_files "$instdata_path"/*.pid
   rm_empty_dirs "$instdata_path"
 
-  echo "Removing configuration files:"
+  getxt "Removing configuration files:\n"
   rm_files "${tbcfg_files[@]}"
   rm_empty_dirs "$instcfg_path"
 
-  echo "Removing TrustBridge from autostart"
+  getxt "Removing TrustBridge from autostart\n"
   rm_files "${autostart_path}/tustbridge.desktop"
 }
 
 deinstall()
 {
   if [ "${oldinstcfg[PREFIX]}" ] ; then
-      echo "Really deinstall TrustBridge from '${oldinstcfg[PREFIX]}'? [y/n]"
+      getxt "Really deinstall TrustBridge from '%s'? [y/n]\n" "${oldinstcfg[PREFIX]}"
       yorn || exit 0
       deinstall_certs
       local deinstdir="${oldinstcfg[PREFIX]}/bin"
-      echo "Deinstalling from '${oldinstcfg[PREFIX]}'."
+      getxt "Deinstalling from '%s'.\n" "${oldinstcfg[PREFIX]}"
       for file in $BINNAMES ; do
         local path="${deinstdir}/$file"
-        echo "Deleting '$path' ..."
-        rm "$path" || echo >&2 "WARNING: Could not delete: '$path'!"
+        getxt "Deleting '%s' ...\n" "$path"
+        rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
       done
       rm_empty_dirs "$deinstdir"
       deinstall_etc
-      echo "Deinstallation finished."
+      getxt "Deinstallation finished.\n"
   else
-    echo "No current installation found!  No harm done."
+    getxt "No current installation found!  No harm done.\n"
   fi
 }
 
@@ -312,7 +340,7 @@
   # respected with regards to autostart.
   if [ ! -d "${autostart_path}" ]; then
     install -d "${autostart_path}" || \
-      fatal "Failed to create autostart directory: '${autostart_path}'"
+      fatal "Failed to create autostart directory: '%s'\n" "$autostart_path"
   fi
 
   write_autostart "${autostart_path}/tustbridge.desktop"
@@ -345,12 +373,12 @@
 
     if [ "${oldinstcfg[PREFIX]}" ] ; then
         inst_default_prefix="${oldinstcfg[PREFIX]}"
-        echo "An existing installation (v${oldinstcfg[VERSION]}) was detected!"
-        echo "It is HIGHLY RECOMMENDED to accept the default prefix"
-        echo "to update the current installation."
-        echo "For a new prefix you should deinstall first!"
+        getxt "An existing installation (v%s) was detected!\n" "${oldinstcfg[VERSION]}"
+        getxt "It is HIGHLY RECOMMENDED to accept the default prefix\n"
+        getxt "to update the current installation.\n"
+        getxt "For a new prefix you should deinstall first!\n"
     fi
-    echo -n "Select installation prefix for TrustBridge [${inst_default_prefix}]: "
+    getxt "Select installation prefix for TrustBridge [%s]: " "${inst_default_prefix}"
     read -e instcfg[PREFIX]
 
     [ -z "${instcfg[PREFIX]}" ] && instcfg[PREFIX]="${inst_default_prefix}"
@@ -359,18 +387,18 @@
   if [ "${oldinstcfg[PREFIX]}" -a \
        "${instcfg[PREFIX]}" != "${oldinstcfg[PREFIX]}" -a \
        $FORCE -ne 1 ] ; then
-      fatal "Prefix differs from current installation (${oldinstcfg[PREFIX]}).  Aborting!"
+      fatal "Prefix differs from current installation (%s).  Aborting!\n" "${oldinstcfg[PREFIX]}"
   fi
 fi
 
-echo "Installing to '${instcfg[PREFIX]}':"
+getxt "Installing to '%s':\n" "${instcfg[PREFIX]}"
 
 if [ ! -d "${instcfg[PREFIX]}" ] ; then
-    echo "creating installation directory ..."
-    install -d "${instcfg[PREFIX]}" || fatal "Could not create '${instcfg[PREFIX]}'!"
+    getxt "creating installation directory ...\n"
+    install -d "${instcfg[PREFIX]}" || fatal "Could not create '%s'!\n" "${instcfg[PREFIX]}"
 fi
 
-echo "unpacking files ..."
+getxt "unpacking files ...\n"
 cd "${instcfg[PREFIX]}"
 
 set +u
@@ -380,16 +408,16 @@
 ###SHAR###
 # ----------------------------------------------------------------------
 
-echo "Preparing trustbridge-tray-starter ..."
+getxt "Preparing trustbridge-tray-starter ...\n"
 sed -i "/^PREFIX=/c\PREFIX='${instcfg[PREFIX]}'" \
     "${instcfg[PREFIX]}/bin/trustbridge-tray-starter.sh"
 
-echo "Setting up cronjob ..."
+getxt "Setting up cronjob ...\n"
 setup_cronjob
 
-echo "Setting up autostart ..."
+getxt "Setting up autostart ...\n"
 setup_autostart
 
-echo "Writing installation configuration to: $instcfg_file ..."
+getxt "Writing installation configuration to: %s ...\n" "$instcfg_file"
 write_instcfg
 exit 0

http://wald.intevation.org/projects/trustbridge/