Skip to content

Commit 43c1690

Browse files
committed
modify postrm to backup secrets.enc
1 parent 7181ec7 commit 43c1690

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

debian/postrm

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,44 @@ echo "Sekrets: Running post-removal cleanup..."
66
case "$1" in
77
remove|purge)
88
USER=$(logname)
9+
SEKRETS_FILE_LOCAL="/home/$USER/.local/share/sekrets/sekrets.enc"
10+
911
echo "Removing Sekrets configuration and data directories for user: $USER"
1012

11-
sudo -H -u "$USER" bash -c 'rm -rf ~/.local/share/sekrets ~/.config/sekrets' || true
13+
# Find sekrets.enc inside ~/snap/sekrets/ (any subfolder)
14+
SEKRETS_FILE_SNAP=$(find "/home/$USER/snap/sekrets" -type f -name "sekrets.enc" 2>/dev/null | head -n 1)
15+
16+
backup_sekret_file() {
17+
FILE_PATH=$1
18+
if [ -f "$FILE_PATH" ]; then
19+
echo "⚠️ WARNING: Your secrets file ($FILE_PATH) will be deleted!"
20+
echo "Would you like to copy it to a safe location before removal? (y/N)"
21+
22+
read -r confirm
23+
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
24+
echo "Enter the full path where you want to save sekrets.enc:"
25+
read -r backup_location
26+
27+
# Ensure the directory exists before proceeding
28+
if [ -d "$backup_location" ]; then
29+
cp "$FILE_PATH" "$backup_location/sekrets.enc"
30+
echo "✅ sekrets.enc has been copied to $backup_location"
31+
else
32+
echo "❌ Invalid directory. Skipping backup."
33+
fi
34+
else
35+
echo "❗ Proceeding with removal without backup."
36+
fi
37+
fi
38+
}
39+
40+
# Check and prompt for both local and snap directory
41+
backup_sekret_file "$SEKRETS_FILE_LOCAL"
42+
if [ -n "$SEKRETS_FILE_SNAP" ]; then
43+
backup_sekret_file "$SEKRETS_FILE_SNAP"
44+
fi
45+
46+
# Remove Sekrets config and data directories
47+
sudo -H -u "$USER" bash -c 'rm -rf ~/.local/share/sekrets ~/.config/sekrets ~/snap/sekrets' || true
1248
;;
1349
esac

0 commit comments

Comments
 (0)