freenas-proxmox/packaging/DEBIAN/postrm

65 lines
2.0 KiB
Bash

#!/bin/bash
# postrm: truenas-proxmox v3.x removal script
set -e
PLUGIN_DST="/usr/share/perl5/PVE/Storage/Custom/TrueNAS.pm"
JS_DST="/usr/share/pve-manager/js/truenas-storage.js"
HELP_DST="/usr/share/pve-docs/truenas-storage.html"
TPL="/usr/share/pve-manager/index.html.tpl"
LOG_FILE="/var/log/truenas-proxmox-install.log"
log() {
echo "[truenas-proxmox] $*" | tee -a "$LOG_FILE"
}
remove_ui() {
rm -f "$JS_DST" && log "Removed ${JS_DST}"
rm -f "$HELP_DST" && log "Removed ${HELP_DST}"
if [ -f "$TPL" ] && grep -qF 'truenas-storage.js' "$TPL"; then
log "Removing <script> tag from ${TPL}"
sed -i '/truenas-storage\.js/d' "$TPL"
fi
}
restart_pve_services() {
# Bare statements (not `cmd && log ...`) so `set -e` actually aborts on
# failure instead of silently skipping past it — see tests/test-restart-services.sh.
log "Restarting Proxmox VE services ..."
pvedaemon restart
log "pvedaemon restarted"
pveproxy restart
log "pveproxy restarted"
pvestatd restart
log "pvestatd restarted"
systemctl restart pve-ha-lrm pve-ha-crm
log "pve-ha-lrm, pve-ha-crm restarted"
}
# Guard so tests can `source` this file (to exercise its functions) without
# running dpkg's maintainer-script logic below.
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
case "$1" in
remove)
log "Removing truenas-proxmox ..."
rm -f "$PLUGIN_DST" && log "Removed ${PLUGIN_DST}"
remove_ui
restart_pve_services
log "truenas-proxmox removed. Refresh your Proxmox browser tab."
;;
purge)
log "Purging truenas-proxmox ..."
rm -f "$PLUGIN_DST" "$JS_DST" "$HELP_DST" "$LOG_FILE"
[ -f "$TPL" ] && sed -i '/truenas-storage\.js/d' "$TPL"
;;
upgrade|failed-upgrade|disappear|abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "$0: called with unknown argument '$1'" >&2
exit 0
;;
esac
exit 0
fi