## arg 1:  the new package version
## arg 2:  the old package version
# shellcheck disable=SC2016

_stop_asd_service() {
  if systemctl is-active asd.service &>/dev/null; then
    echo 'In order to preserve the data, the asd service will now be stopped.'
    systemctl stop asd.service &>/dev/null
  fi
}

pre_upgrade() {
  for version in 5.69 5.76; do
    if [ "$(vercmp "$2" "$version")" -lt 0 ]; then
      _stop_asd_service
      echo 'Start the asd service manually after upgrade is complete.'
    fi
  done
}

post_install() {
  echo 'Consult the manpage (`man 1 asd`) and backup your data before use.'
}

pre_remove() {
  _stop_asd_service
}
