Add cleanup function to destroy and allow clean restart

This commit is contained in:
Eric Renfro 2024-06-23 20:15:22 -04:00
parent 4dc3e37dc4
commit 9e54386b01
Signed by: psi-jack
SSH key fingerprint: SHA256:1TKB8Z257L8EHK8GWNxKgMhD8a+FAR+f+j3nnlcuNVM

View file

@ -267,6 +267,38 @@ function install_expert() {
expert_step 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 -a POSITIONAL_ARGS=()
declare INSTALL_MODE="normal" declare INSTALL_MODE="normal"
@ -291,6 +323,10 @@ while [[ $# -gt 0 ]]; do
INSTALL_MODE=expert INSTALL_MODE=expert
shift shift
;; ;;
--clean)
INSTALL_MODE=clean
shift
;;
*) *)
POSITIONAL_ARGS+=("$1") # save positional arg POSITIONAL_ARGS+=("$1") # save positional arg
shift shift
@ -317,6 +353,7 @@ else
case "$INSTALL_MODE" in case "$INSTALL_MODE" in
normal) install_normal;; normal) install_normal;;
expert) install_expert;; expert) install_expert;;
clean) install_cleanup;;
*) *)
echo "Error, unknown installation mode detected." echo "Error, unknown installation mode detected."
exit 3 exit 3