From 9e54386b011ad331888dce727110a169639887c9 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Sun, 23 Jun 2024 20:15:22 -0400 Subject: [PATCH] Add cleanup function to destroy and allow clean restart --- lmde-expert.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lmde-expert.sh b/lmde-expert.sh index 6876dc4..dffa3b7 100755 --- a/lmde-expert.sh +++ b/lmde-expert.sh @@ -267,6 +267,38 @@ function install_expert() { expert_step } +function install_cleanup() { + if [[ "$DEBUG" ]]; then + local cmd="echo" + else + local cmd="" + fi + + for subvol in "${!SUBVOLS_DEFAULT[@]}" + do + ${cmd} umount /target/"${SUBVOLS_DEFAULT[$subvol]}" + done + + if [[ "$SWAP" ]]; then + ${cmd} umount /target/swap + fi + + ${cmd} umount /target/boot/efi + ${cmd} umount /target/boot + ${cmd} umount /target + + if [[ "$ENCRYPTION" ]]; then + ${cmd} cryptsetup luksClose luksvol + fi + + ${cmd} dd if=/dev/zero of="${RootPart}" bs=1024 count=10 + ${cmd} dd if=/dev/zero of="${EFIPart}" bs=1024 count=10 + if [[ "$BootPart" != "@boot" ]]; then + ${cmd} dd if=/dev/zero of="${BootPart}" bs=1024 count=10 + fi +} + + declare -a POSITIONAL_ARGS=() declare INSTALL_MODE="normal" @@ -291,6 +323,10 @@ while [[ $# -gt 0 ]]; do INSTALL_MODE=expert shift ;; + --clean) + INSTALL_MODE=clean + shift + ;; *) POSITIONAL_ARGS+=("$1") # save positional arg shift @@ -317,6 +353,7 @@ else case "$INSTALL_MODE" in normal) install_normal;; expert) install_expert;; + clean) install_cleanup;; *) echo "Error, unknown installation mode detected." exit 3