#!/usr/bin/env bash
set -euo pipefail

# Fixup for packaging mistake (0.1.0/0.1.1) where dh_install created directories:
#   /usr/sbin/saikyo-av-admin/saikyo-av-admin
#   /etc/xdg/autostart/saikyo-av-gui.desktop/saikyo-av-gui.desktop
# Remove them before unpacking corrected package.

if [[ "$1" == "upgrade" || "$1" == "install" ]]; then
  for d in \
    /usr/sbin/saikyo-av-admin \
    /etc/xdg/autostart/saikyo-av-gui.desktop
  do
    if [[ -d "$d" ]]; then
      rm -rf "$d" 2>/dev/null || true
    fi
  done
fi

exit 0
