Files
my-cd-webhook/install/uninstall.sh
T
fisher fc40facfc5 Follow the house shell conventions
Constants UPPER_SNAKE, mutable locals PascalCase, braced expansions
throughout, per Development/Coding conventions in the vault.
2026-08-23 08:57:15 +00:00

37 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Remove the CD webhook receiver from this host.
#
# Stops and deletes the user service. Deliberately leaves the secrets file and
# the deploy logs in place -- removing a receiver is not a reason to destroy
# credentials or the record of what was deployed. Pass --purge to remove them.
set -Eeuo pipefail
readonly CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/cd-webhook"
readonly STATE_DIR="${XDG_STATE_HOME:-${HOME}/.local/state}/cd-webhook"
readonly SYSTEMD_DIR="${HOME}/.config/systemd/user"
readonly UNIT_NAME="cd-webhook.service"
Purge=0
[[ "${1:-}" == "--purge" ]] && Purge=1
echo "Stopping ${UNIT_NAME} ..."
systemctl --user disable --now "${UNIT_NAME}" 2>/dev/null || true
rm -f "${SYSTEMD_DIR}/${UNIT_NAME}"
systemctl --user daemon-reload
# The rendered hooks file holds the webhook secrets, so it goes regardless; it
# is regenerated from targets.json plus secrets.env on the next install.
rm -f "${CONFIG_DIR}/hooks.json"
if [[ ${Purge} -eq 1 ]]; then
echo "Purging secrets and deploy logs ..."
rm -rf "${CONFIG_DIR}" "${STATE_DIR}"
else
echo "Kept ${CONFIG_DIR}/secrets.env and deploy logs in ${STATE_DIR}"
echo " (re-run with --purge to remove them too)"
fi
echo "Done."