my dotfiles for arch
1#!/bin/bash
2set -e
3
4echo "=== Snapper Cleanup Script ==="
5
6# 1. Show existing configs
7echo "[*] Listing Snapper configs..."
8snapper list-configs || { echo "No snapper configs found."; exit 0; }
9
10# 2. For each config, list snapshots and ask to delete
11for config in $(snapper list-configs | awk 'NR>1 {print $1}'); do
12 echo ""
13 echo "[*] Config: $config"
14 snapper -c "$config" list || true
15 read -rp "Delete ALL snapshots for config '$config'? [y/N] " ans
16 if [[ "$ans" =~ ^[Yy]$ ]]; then
17 echo " -> Deleting snapshots for $config"
18 snapper -c "$config" delete 1-999999 || true
19 fi
20 read -rp "Remove config '$config'? [y/N] " ans2
21 if [[ "$ans2" =~ ^[Yy]$ ]]; then
22 echo " -> Removing config $config"
23 snapper delete-config "$config" || true
24 fi
25done
26
27# 3. Optionally uninstall Snapper
28read -rp "Do you also want to uninstall Snapper? [y/N] " ans3
29if [[ "$ans3" =~ ^[Yy]$ ]]; then
30 if command -v zypper >/dev/null 2>&1; then
31 sudo zypper remove -y snapper
32 elif command -v dnf >/dev/null 2>&1; then
33 sudo dnf remove -y snapper
34 elif command -v apt >/dev/null 2>&1; then
35 sudo apt remove -y snapper
36 else
37 echo "Could not detect package manager. Please uninstall Snapper manually."
38 fi
39else
40 echo "Snapper package left installed."
41fi
42
43echo "=== Snapper cleanup complete ==="