view packaging/linux-installer-uninstall.inc @ 1332:8362e30f7b55

(issue139) Check that pid is not running if the lock can be aquired If the lock on the lockfile can be aquired it might still be possible that another process is running. So we read the pid from the lockfile and check if another process with the same installation prefix as us is running.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 15 Oct 2014 14:19:46 +0200
parents 014586ef8a84
children
line wrap: on
line source
#-*-sh-*-

###INCLUDE:linux-installer-uninstall.l10n-de

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_and_config()
{
  local cinst="${oldinstcfg[PREFIX]}/bin/trustbridge-certificate-installer"
  local certlist=`ls 2>/dev/null -1  ${instdata_path}/list-installed.txt`

  getxt "Uninstalling certificates ...\n"

  if [ -f "$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
      rm_files "$certlist"
  else
    getxt "No certificate list found.  Nothing to do.\n"
  fi

  rm_files "${CFGPATH}/TrustBridge.ini"
  rm_empty_dirs "${CFGPATH}"
}

deinstall_etc()
{
  getxt "Removing cron job ...\n"
  remove_cronjob

  getxt "Removing certificate lists from: %s:\n" "$instdata_path"
  rm_files "$instdata_path"/list-2*.txt

  local tbcfg_files=( "${CFGPATH}/trustbridge-tray-starter.cfg"
                      "$instcfg_file" )

  getxt "Removing configuration files:\n"
  rm_files "${tbcfg_files[@]}"
  rm_empty_dirs "$instcfg_path"
  rm_empty_dirs "${CFGPATH}"

  getxt "Removing PID file from: %s:\n" "$instdata_path"
  rm_files "$instdata_path"/*.pid
  rm_empty_dirs "$instdata_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
      local certlist=`ls 2>/dev/null -1  ${instdata_path}/list-installed.txt`
      if [ -f "$certlist" ] ; then
        getxt "Do you also want to remove the certificates installed by TrustBridge? [y/n]\n"
        yorn && deinstall_certs_and_config
      fi
      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"

      # Licenses
      deinstdir="${oldinstcfg[PREFIX]}/share/doc/trustbridge/licenses"
      for file in $LICENSENAMES; 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/