After gemini-propoesed fixes
This commit is contained in:
parent
2e31283b61
commit
83324dd0f7
11 changed files with 228 additions and 307 deletions
|
|
@ -1,8 +1,7 @@
|
|||
#!/bin/bash
|
||||
# Lackadaisical squashfs tools - Destroy
|
||||
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
||||
DIR="$1"
|
||||
|
||||
DIR="$1"
|
||||
if [[ -z "$DIR" ]]; then
|
||||
echo "Usage: $0 <directory>"
|
||||
exit 1
|
||||
|
|
@ -10,47 +9,42 @@ fi
|
|||
|
||||
DIR=$(readlink -f "$DIR")
|
||||
DIR_SHORT=$(basename "$DIR")
|
||||
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
||||
|
||||
if [[ ! -f "$DIR/.needs_mount" ]]; then
|
||||
if ! mountpoint -q "$DIR"; then
|
||||
echo "Error: $DIR does not appear to be a SquashFS-backed directory (missing .needs_mount)."
|
||||
exit 1
|
||||
fi
|
||||
if ! mountpoint -q "$DIR"; then
|
||||
echo "Error: $DIR is not a SquashFS directory."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Disable systemd service
|
||||
# Stop systemd service
|
||||
ESC_PATH=$(systemd-escape -p "$DIR")
|
||||
SERVICE_NAME="squash-mount@-$ESC_PATH"
|
||||
SERVICE_NAME="squash-mount@$ESC_PATH.service"
|
||||
|
||||
echo "Disabling systemd service ($SERVICE_NAME)..."
|
||||
echo "Disabling service ($SERVICE_NAME)..."
|
||||
sudo systemctl stop "$SERVICE_NAME" 2>/dev/null
|
||||
sudo systemctl disable "$SERVICE_NAME" 2>/dev/null
|
||||
|
||||
# Ensure it is mounted to copy merged data
|
||||
echo "Ensuring image is mounted to preserve data..."
|
||||
"$BIN_DIR"/mount-squash-image "$DIR" 1>/dev/null 2>/dev/null
|
||||
"$BIN_DIR/mount-squash-image" "$DIR" 1>/dev/null 2>/dev/null
|
||||
|
||||
echo "Destroying SquashFS image and restoring data to normal directory..."
|
||||
echo "Destroying image and restoring data..."
|
||||
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
# Copy data out (preserving all attributes)
|
||||
sudo rsync -a "$DIR/" "$TEMP_DIR/"
|
||||
# Atomic copy-out
|
||||
TEMP_DIR=$(mktemp -d /tmp/squash-dest.XXXXXXXX)
|
||||
sudo rsync -aX "$DIR/" "$TEMP_DIR/" || { echo "Error: Failed to copy data."; exit 1; }
|
||||
|
||||
# Unmount the overlay and squashfs
|
||||
echo "Unmounting..."
|
||||
"$BIN_DIR"/umount-squash-image "$DIR"
|
||||
# Unmount
|
||||
"$BIN_DIR/umount-squash-image" "$DIR"
|
||||
|
||||
# Restore data to original location
|
||||
echo "Restoring files..."
|
||||
# Restore original directory structure
|
||||
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
|
||||
sudo rm -rf "$DIR"
|
||||
sudo mv "$TEMP_DIR" "$DIR"
|
||||
|
||||
# Cleanup hidden image and overlay files
|
||||
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
|
||||
echo "Cleaning up ${OVERLAY_ROOT}..."
|
||||
sudo rm -rf "${OVERLAY_ROOT}.img"
|
||||
sudo rm -rf "${OVERLAY_ROOT}"
|
||||
|
||||
echo "Success: SquashFS image destroyed and data restored to $DIR."
|
||||
exit 0
|
||||
# Final cleanup
|
||||
sudo rm -rf "$OVERLAY_ROOT" "${OVERLAY_ROOT}.img"
|
||||
|
||||
echo "Success: SquashFS image destroyed and data restored to \"$DIR\"."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue