diff packaging/linux-installer-uninstall.inc @ 1139:1c9001db6ea2

Split up linux installer in to be able to create a uninstaller (TODO).
author Sascha Wilde <wilde@intevation.de>
date Wed, 17 Sep 2014 18:53:04 +0200
parents
children a72d59f8c3ea
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/packaging/linux-installer-uninstall.inc	Wed Sep 17 18:53:04 2014 +0200
@@ -0,0 +1,155 @@
+#-*-sh-*-
+rm_empty_dirs()
+{
+  # Args: $1 - DIRECTORY
+  #
+  # Recursively remove DIRECTORY and all it _parent_ directories as
+  # long as they are empty.
+  local directory="$1"
+  while [ -d "$directory" -a -z "$(ls 2>/dev/null -A "$directory")" ] ; do
+    getxt "Deleting empty directory '%s' ...\n" "$directory"
+    rmdir "$directory"
+    directory=`dirname "$directory"`
+  done
+}
+
+rm_files()
+{
+  for file in "$@" ; do
+    if [ -e "$file" ] ; then
+        getxt "Deleting '%s' ...\n" "$file"
+        rm "$file"
+    fi
+  done
+}
+
+remove_cronjob()
+{
+  setup_cronjob deinstall
+}
+
+deinstall_certs()
+{
+  local cinst="${oldinstcfg[PREFIX]}/bin/cinst"
+  local certlist=`ls 2>/dev/null -1  ${instdata_path}/list-installed.txt`
+
+  getxt "Uninstalling certificates ...\n"
+
+  if [ "$certlist" ] ; then
+      getxt "Using certificate list '%s'.\n" "$certlist"
+      if [ -x "$cinst" ] ; then
+          "$cinst" "list=$certlist" "choices=uninstall"
+      else
+        getxt >&2 "WARNING: can't execute %s for certificate deinstallation.\n" "$cinst"
+      fi
+  else
+    getxt "No certificate list found.  Nothing to do.\n"
+  fi
+}
+
+deinstall_etc()
+{
+  getxt "Removing cron job ...\n"
+  remove_cronjob
+
+  # FIXME: delete all files created by the application.
+  local tbcfg_files=( "${instcfg_path}/TrustBridge.ini"
+                      "${instcfg_path}/trustbridge-tray-starter.cfg"
+                      "$instcfg_file" )
+
+  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"
+
+  getxt "Removing configuration files:\n"
+  rm_files "${tbcfg_files[@]}"
+  rm_empty_dirs "$instcfg_path"
+
+  getxt "Removing TrustBridge from autostart\n"
+  rm_files "${autostart_path}/trustbridge.desktop"
+  update-desktop-database 2>&1 || true
+
+  getxt "Removing TrustBridge from start menu\n"
+  rm_files "${startmenu_path}/trustbridge.desktop"
+}
+
+deinstall()
+{
+  if [ "${oldinstcfg[PREFIX]}" ] ; then
+      getxt "Really deinstall TrustBridge from '%s'? [y/n]\n" "${oldinstcfg[PREFIX]}"
+      yorn || exit 0
+      deinstall_certs
+      local deinstdir="${oldinstcfg[PREFIX]}/bin"
+      getxt "Deinstalling from '%s'.\n" "${oldinstcfg[PREFIX]}"
+      for file in $BINNAMES ; do
+        local path="${deinstdir}/$file"
+        getxt "Deleting '%s' ...\n" "$path"
+        rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
+      done
+      rm_empty_dirs "$deinstdir"
+
+      # images
+      deinstdir="${oldinstcfg[PREFIX]}/share/doc/trustbridge/_images"
+      for file in $HELPNAMES_IMG; do
+        local path="${deinstdir}/$file"
+        if [ -f "$path" ]; then
+          getxt "Deleting '%s' ...\n" "$path"
+          rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
+        fi
+      done
+      rm_empty_dirs "$deinstdir"
+
+      # Javascript sources
+      deinstdir="${oldinstcfg[PREFIX]}/share/doc/trustbridge/_sources"
+      for file in $HELPNAMES_SOURCES; do
+        local path="${deinstdir}/$file"
+        if [ -f "$path" ]; then
+          getxt "Deleting '%s' ...\n" "$path"
+          rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
+        fi
+      done
+      rm_empty_dirs "$deinstdir"
+
+      # Static files
+      deinstdir="${oldinstcfg[PREFIX]}/share/doc/trustbridge/_static"
+      for file in $HELPNAMES_STATIC; do
+        local path="${deinstdir}/$file"
+        if [ -f "$path" ]; then
+          getxt "Deleting '%s' ...\n" "$path"
+          rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
+        fi
+      done
+      rm_empty_dirs "$deinstdir"
+
+      # The actual html
+      deinstdir="${oldinstcfg[PREFIX]}/share/doc/trustbridge"
+      for file in $HELPNAMES; do
+        local path="${deinstdir}/$file"
+        if [ -f "$path" ]; then
+          getxt "Deleting '%s' ...\n" "$path"
+          rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
+        fi
+      done
+      rm_empty_dirs "$deinstdir"
+      deinstdir="${oldinstcfg[PREFIX]}/share/pixmaps/trustbridge"
+      getxt "Deinstalling from '%s'.\n" "${oldinstcfg[PREFIX]}"
+      for file in $ICONNAME; do
+        local path="${deinstdir}/$file"
+        getxt "Deleting '%s' ...\n" "$path"
+        rm "$path" || getxt >&2 "WARNING: Could not delete: '%s'!\n" "$path"
+      done
+      deinstdir="${oldinstcfg[PREFIX]}/share/pixmaps/trustbridge"
+      rm_empty_dirs "$deinstdir"
+      deinstdir="${oldinstcfg[PREFIX]}/share/pixmaps"
+      rm_empty_dirs "$deinstdir"
+      deinstdir="${oldinstcfg[PREFIX]}/share"
+      rm_empty_dirs "$deinstdir"
+      deinstall_etc
+      getxt "Deinstallation finished.\n"
+  else
+    getxt "No current installation found!  No harm done.\n"
+  fi
+}

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