#!/bin/sh

set -e

[ "$CARNET_SCRIPT_DEBUG" ] && set -vx

if [ "$1" = "remove" ]; then
  if [ -f /etc/apache2/conf.d/aosi-www-aai.conf ]; then
    rm -f /etc/apache2/conf.d/aosi-www-aai.conf
  fi

  a2disconf aosi-www-aai --quiet || true

  # reload apache2 
  service apache2 reload
fi

[ "$1" = "purge" ] || exit 0

dpkg-statoverride --remove /var/lib/aosi-www/schema > /dev/null 2> /dev/null || true
dpkg-statoverride --remove /var/lib/aosi-www/schema/sifrarnici > /dev/null 2> /dev/null || true
dpkg-statoverride --remove /var/lib/aosi-www/inst_img > /dev/null 2> /dev/null || true

if [ -d /var/lib/aosi-www/schema ]; then
  rm -rf /var/lib/aosi-www/schema
fi

if [ -d /var/lib/aosi-www/inst_img ]; then
  rm -rf /var/lib/aosi-www/inst_img
fi

if [ -f /etc/aosi-www/config.php ]; then
  rm -f /etc/aosi-www/config.php
fi

if [ -f /etc/aosi-www/config.php.cn-old ]; then
  rm -f /etc/aosi-www/config.php.cn-old
fi

if [ -f /var/lib/aosi-www/aosi_proxy.php ]; then
  rm -f /var/lib/aosi-www/aosi_proxy.php
fi

if [ -f /etc/apache2/conf.d/aosi-www-aai.conf ]; then
  rm -f /etc/apache2/conf.d/aosi-www-aai.conf
fi

#DEBHELPER#
