#!/bin/sh

set -e

# Source debconf library.
. /usr/share/debconf/confmodule

unset_perms() {
    find $1 | xargs -n 1 /usr/share/biomaj-watcher/bin/unsetperms.sh
}


case "$1" in
    remove)
      # Update configuration files
      unset_perms /etc/biomaj/db_properties/
      # Update generated banks
      unset_perms /var/lib/biomaj/
      # Update logs
      unset_perms /var/log/biomaj/
    ;;
    *)
    ;;
esac    

case "$1" in
    upgrade)
    ;;
    remove|upgrade|deconfigure)
      # Remove post installation created files

      # Remove admin credentials
      if [ -e /usr/share/biomaj/.bmajwatcherpasswd ]; then
         rm /usr/share/biomaj/.bmajwatcherpasswd
      fi

      if [ -e /usr/share/biomaj-watcher/bin/WatcherConfigurator.class ]; then
         rm /usr/share/biomaj-watcher/bin/WatcherConfigurator.class
      fi

    ;;

    failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac


#DEBHELPER#
