#!/bin/bash

set -e

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

function maybe_remove_hooks_symlink() {
  local target=$(readlink -f /etc/nvidia-mig-manager/hooks.yaml)
  if [ "${target}" = "/etc/nvidia-mig-manager/hooks-minimal.yaml" ]; then
    rm -rf /etc/nvidia-mig-manager/hooks.yaml
  fi
  if [ "${target}" = "/etc/nvidia-mig-manager/hooks-default.yaml" ]; then
    rm -rf /etc/nvidia-mig-manager/hooks.yaml
  fi
}

function maybe_remove_config_symlink() {
  local target=$(readlink -f /etc/nvidia-mig-manager/config.yaml)
  if [ "${target}" = "/etc/nvidia-mig-manager/config-default.yaml" ]; then
    rm -rf /etc/nvidia-mig-manager/config.yaml
  fi
}

case "${1}" in
  purge)
    maybe_remove_hooks_symlink
    maybe_remove_config_symlink
  ;;

  remove|upgrade|disappear)
    exit 0
  ;;

  *)
    echo "postrm called with unknown argument \`${1}'" >&2
    exit 1
  ;;

esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

db_stop

exit 0
