#!/usr/bin/env bash # Remove supaspin. Run on the server: sudo bash uninstall.sh # Asks before deleting instances (their data is gone for good) and before removing the # shared cluster objects that the first-run setup created. set -uo pipefail [ "$(id -u)" -eq 0 ] || { echo "Run as root: sudo bash uninstall.sh" >&2; exit 1; } if [ -x /snap/bin/microk8s.kubectl ]; then K=/snap/bin/microk8s.kubectl; else K=kubectl; fi # Ask on the terminal (works when the script itself arrives through a pipe), else on stdin. ask() { if { : /dev/null; then read -r -p "$1" a . nums="$($K get ns -o name 2>/dev/null | sed -n 's#^namespace/supaspin-\([0-9][0-9]*\)$#\1#p' | sort -n)" if [ -n "$nums" ]; then echo "Instances found: $(echo $nums)" ask "Delete ALL of them, with their databases and files? Type yes: " if [ "$a" = "yes" ]; then for n in $nums; do /usr/local/bin/supaspin delete "$n" --yes; done else echo "Keeping the instances; they will keep running without the supaspin command." fi fi ask "Also remove the shared cluster objects (StorageClass supaspin-local-sc, issuer supaspin-letsencrypt, PriorityClass supaspin-low, namespace supaspin-certs with saved certificates)? Type yes: " if [ "$a" = "yes" ]; then $K delete storageclass supaspin-local-sc --ignore-not-found $K delete clusterissuer supaspin-letsencrypt --ignore-not-found $K delete priorityclass supaspin-low --ignore-not-found $K delete namespace supaspin-certs --ignore-not-found fi fi rm -f /usr/local/bin/supaspin rm -rf /usr/share/supaspin /etc/supaspin /var/lib/supaspin echo "supaspin removed."