1 contributor
#!/bin/bash
set -euo pipefail
PROJECT_ID="pve-net-hang-watchdog"
ORG_ID="xdev"
INSTALL_DIR="/usr/local/lib/${ORG_ID}/${PROJECT_ID}"
DOC_DIR="/usr/local/share/doc/${ORG_ID}/${PROJECT_ID}"
COMMAND_PATH="/usr/local/sbin/pve-net-hang-watchdog.sh"
UNINSTALL_WRAPPER="/usr/local/sbin/${ORG_ID}-${PROJECT_ID}-uninstall"
CONFIG_PATH="/etc/default/${ORG_ID}-${PROJECT_ID}"
UNIT_PATH="/etc/systemd/system/${PROJECT_ID}.service"
FORCE_MODE=0
log() {
if [[ "${FORCE_MODE}" -eq 0 ]]; then
echo "$@"
fi
}
require_root() {
if [[ "${EUID}" -ne 0 ]]; then
echo "ERROR: this script must be run as root" >&2
exit 1
fi
}
main() {
while [[ $# -gt 0 ]]; do
case "$1" in
--force)
FORCE_MODE=1
shift
;;
-h|--help)
echo "Usage: $0 [--force]"
exit 0
;;
*)
echo "ERROR: unknown option: $1" >&2
exit 1
;;
esac
done
require_root
log "=== Uninstalling ${PROJECT_ID} ==="
systemctl disable pve-net-hang-watchdog.service >/dev/null 2>&1 || true
systemctl stop pve-net-hang-watchdog.service >/dev/null 2>&1 || true
rm -f "${UNIT_PATH}"
systemctl daemon-reload
rm -f "${UNINSTALL_WRAPPER}"
rm -f "${COMMAND_PATH}"
rm -f "${CONFIG_PATH}"
rm -rf "${DOC_DIR}"
rm -rf "${INSTALL_DIR}"
rmdir /usr/local/lib/${ORG_ID} 2>/dev/null || true
rmdir /usr/local/share/doc/${ORG_ID} 2>/dev/null || true
log "Uninstall complete."
}
main "$@"