Files
gitea-homelab/scripts/uninstall.sh
Raghav bb68b6b9f2 Initial commit
Co-Authored-By: Oz <oz-agent@warp.dev>
2026-04-16 09:04:22 +05:30

51 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/lib.sh"
PURGE_DATA=false
PURGE_IMAGES=false
ASSUME_YES=false
WITH_TLS=false
CLOSE_PUBLIC_WEB=false
for arg in "$@"; do
case "$arg" in
--purge-data) PURGE_DATA=true ;;
--purge-images) PURGE_IMAGES=true ;;
--yes) ASSUME_YES=true ;;
--with-tls) WITH_TLS=true ;;
--close-public-web) CLOSE_PUBLIC_WEB=true ;;
*) die "Unknown argument: $arg" ;;
esac
done
load_env
if [[ "${PURGE_DATA}" == "true" && "${ASSUME_YES}" != "true" ]]; then
read -r -p "This will delete ${GITEA_BASE_PATH}/gitea-data and ${GITEA_BASE_PATH}/postgres. Continue? [y/N]: " answer
[[ "${answer}" == "y" || "${answer}" == "Y" ]] || die "Aborted by user"
fi
log "Stopping and removing containers"
if [[ "${WITH_TLS}" == "true" ]]; then
compose --profile tls down --remove-orphans
else
compose down --remove-orphans
fi
if [[ "${PURGE_IMAGES}" == "true" ]]; then
log "Removing docker images"
docker image rm gitea/gitea:1.24.2 postgres:16-alpine caddy:2.10-alpine || true
fi
if [[ "${PURGE_DATA}" == "true" ]]; then
log "Purging persistent data under ${GITEA_BASE_PATH}"
rm -rf "${GITEA_BASE_PATH}/gitea-data" "${GITEA_BASE_PATH}/postgres" "${GITEA_BASE_PATH}/caddy-data" "${GITEA_BASE_PATH}/caddy-config"
fi
remove_firewall_rules "${CLOSE_PUBLIC_WEB}"
log "Uninstall complete"