diff --git a/unload-chroot.sh b/unload-chroot.sh new file mode 100644 index 0000000..10ed83e --- /dev/null +++ b/unload-chroot.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -euxo pipefail + +# Path to the variables log file +VARIABLES_LOG="/rescue/variables.log" + +# Check if variables log file exists +if [ ! -f "$VARIABLES_LOG" ]; then + echo "❌ No variables log file found. Aborting unmount." + exit 1 +fi + +# Read the variables from the log file and convert them to shell format +partition=$(sed -n 's/^partition="\([^"]*\)"/\1/p' "$VARIABLES_LOG") +efi=$(sed -n 's/^efi="\([^"]*\)"/\1/p' "$VARIABLES_LOG") +home=$(sed -n 's/^home="\([^"]*\)"/\1/p' "$VARIABLES_LOG") + +# Check if necessary variables are loaded +if [ -z "$partition" ] || [ -z "$efi" ] || [ -z "$home" ]; then + echo "❌ Missing variables. Please ensure the script was run previously with valid variables." + exit 1 +fi + +# Unmount the partitions and resources in reverse order of mounting + +echo "Unmounting /rescue/run..." +umount /rescue/run || true +echo "Unmounting /rescue/dev/pts..." +umount /rescue/dev/pts || true +echo "Unmounting /rescue/dev..." +umount /rescue/dev || true +echo "Unmounting /rescue/sys..." +umount /rescue/sys || true +echo "Unmounting /rescue/proc..." +umount /rescue/proc || true +echo "Unmounting /rescue/home..." +umount /rescue/home || true +echo "Unmounting /rescue/boot..." +umount /rescue/boot || true +echo "Unmounting /rescue..." +umount /rescue || true + +# Optional: clean up the /rescue directory after unmounting +echo "Removing /rescue directory (if needed)..." +rmdir /rescue || true + +echo "✅ All partitions and resources have been unmounted and cleaned up."