diff --git a/development/oidc/cleanup_dev.sh b/development/oidc/cleanup_dev.sh new file mode 100755 index 0000000..23e1c95 --- /dev/null +++ b/development/oidc/cleanup_dev.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# cleanup_dev.sh -- Reset the OIDC dev environment to a clean state. +# This stops and removes all containers, networks, and volumes defined in +# container-compose.yml, then deletes the generated data directories so you +# can start fresh with "podman compose up -d" (or docker compose). +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +COMPOSE_FILE="${SCRIPT_DIR}/container-compose.yml" + +# colour helpers +if [ -t 1 ]; then + BOLD='\033[1m' RESET='\033[0m' GREEN='\033[0;32m' YELLOW='\033[0;33m' +else + BOLD='' RESET='' GREEN='' YELLOW='' +fi +info() { echo -e "${GREEN}[INFO]${RESET} $*"; } +warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; } + +# detect compose command +if command -v podman &>/dev/null && podman compose version &>/dev/null 2>&1; then + COMPOSE="podman compose" +elif command -v docker &>/dev/null && docker compose version &>/dev/null 2>&1; then + COMPOSE="docker compose" +else + warn "Neither 'podman compose' nor 'docker compose' found." + warn "Skipping container teardown - only data directories will be removed." + COMPOSE="" +fi + +# stop and remove containers / networks +if [ -n "$COMPOSE" ] && [ -f "$COMPOSE_FILE" ]; then + info "Stopping and removing containers defined in container-compose.yml …" + $COMPOSE -f "$COMPOSE_FILE" down --volumes --remove-orphans 2>/dev/null || true +else + warn "Compose file not found at ${COMPOSE_FILE} - skipping container teardown." +fi + +# remove generated data directories +# These match the volume mounts and the .gitignore entries +DATA_DIRS=( + config + f2b-run-local + fail2ban-config-local + keycloak-data + keycloak-db + pocket-id-data + authentik-media + authentik-db + authelia-config + authelia-db + authelia-redis +) + +info "Removing generated data directories …" +for dir in "${DATA_DIRS[@]}"; do + target="${SCRIPT_DIR}/${dir}" + if [ -e "$target" ]; then + rm -rf "$target" + info " Removed ${dir}/" + fi +done + +# remove generated .env +if [ -f "${SCRIPT_DIR}/.env" ]; then + rm -f "${SCRIPT_DIR}/.env" + info " Removed .env" +fi + +echo "" +info "${BOLD}OIDC dev environment cleaned.${RESET} Run 'podman compose up -d' (or docker compose) to start fresh." diff --git a/development/ssh_and_local/.gitignore b/development/ssh_and_local/.gitignore index 9183331..8bcba8d 100644 --- a/development/ssh_and_local/.gitignore +++ b/development/ssh_and_local/.gitignore @@ -1,3 +1,4 @@ +config fail2ban-config-local fail2ban-config-ssh f2b-run-local diff --git a/development/ssh_and_local/cleanup_dev.sh b/development/ssh_and_local/cleanup_dev.sh new file mode 100755 index 0000000..c515f4e --- /dev/null +++ b/development/ssh_and_local/cleanup_dev.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# cleanup_dev.sh -- Reset the ssh_and_local dev environment to a clean state. +# This stops and removes all containers, networks, and volumes defined in +# container-compose.yml, then deletes the generated data directories so you +# can start fresh with "podman compose up -d" (or docker compose). +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +COMPOSE_FILE="${SCRIPT_DIR}/container-compose.yml" + +# colour helpers +if [ -t 1 ]; then + BOLD='\033[1m' RESET='\033[0m' GREEN='\033[0;32m' YELLOW='\033[0;33m' +else + BOLD='' RESET='' GREEN='' YELLOW='' +fi +info() { echo -e "${GREEN}[INFO]${RESET} $*"; } +warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; } + +# detect compose command +if command -v podman &>/dev/null && podman compose version &>/dev/null 2>&1; then + COMPOSE="podman compose" +elif command -v docker &>/dev/null && docker compose version &>/dev/null 2>&1; then + COMPOSE="docker compose" +else + warn "Neither 'podman compose' nor 'docker compose' found." + warn "Skipping container teardown - only data directories will be removed." + COMPOSE="" +fi + +# stop and remove containers / networks +if [ -n "$COMPOSE" ] && [ -f "$COMPOSE_FILE" ]; then + info "Stopping and removing containers defined in container-compose.yml …" + $COMPOSE -f "$COMPOSE_FILE" down --volumes --remove-orphans 2>/dev/null || true +else + warn "Compose file not found at ${COMPOSE_FILE} - skipping container teardown." +fi + +# remove generated data directories +DATA_DIRS=( + config + f2b-run-local + fail2ban-config-local + fail2ban-config-ssh + ssh-keys +) + +info "Removing generated data directories …" +for dir in "${DATA_DIRS[@]}"; do + target="${SCRIPT_DIR}/${dir}" + if [ -e "$target" ]; then + rm -rf "$target" + info " Removed ${dir}/" + fi +done + +echo "" +info "${BOLD}Dev environment cleaned.${RESET} Run 'podman compose up -d' (or docker compose) to start fresh."