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

# Fixup for 0.1.0 packaging mistake where dh_install created directories:
#   /usr/sbin/saikyo-avd/saikyo-avd
#   /lib/systemd/system/saikyo-avd.service/saikyo-avd.service
#   /lib/systemd/system/saikyo-avd.timer/saikyo-avd.timer
# Remove them before unpacking the corrected package.

if [[ "$1" == "upgrade" || "$1" == "install" ]]; then
  for d in \
    /usr/sbin/saikyo-avd \
    /lib/systemd/system/saikyo-avd.service \
    /lib/systemd/system/saikyo-avd.timer
  do
    if [[ -d "$d" ]]; then
      rm -rf "$d" 2>/dev/null || true
    fi
  done
fi

exit 0
