After gemini-propoesed fixes
This commit is contained in:
parent
2e31283b61
commit
83324dd0f7
11 changed files with 228 additions and 307 deletions
|
|
@ -1,101 +1,78 @@
|
|||
#!/bin/bash
|
||||
# Lackadaisical squashfs tools
|
||||
# Allows you to create a modifiable squashfs-backed image for a folder
|
||||
|
||||
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
||||
DIR=$1
|
||||
DIR="$1"
|
||||
|
||||
if [[ -z "$DIR" ]]; then
|
||||
echo "Usage: $0 <directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
test -d "$DIR"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo Directory "$DIR" does not exist!
|
||||
exit -1
|
||||
if [[ ! -d "$DIR" ]]; then
|
||||
echo "Error: Directory \"$DIR\" does not exist!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "You need support for FUSE, SquashFS, and OverlayFS."
|
||||
echo "Checking your system for these requirements..."
|
||||
echo "Checking system requirements (FUSE, SquashFS, OverlayFS)..."
|
||||
for fs in fuse squashfs overlay; do
|
||||
if ! grep -q "$fs" /proc/filesystems; then
|
||||
echo "Loading $fs kernel module..."
|
||||
if ! sudo modprobe "$fs"; then
|
||||
echo "Error: $fs is not supported and could not be loaded."
|
||||
exit 1
|
||||
fi
|
||||
echo "Attempting to load $fs module..."
|
||||
sudo modprobe "$fs" || { echo "Error: $fs is not supported."; exit 1; }
|
||||
fi
|
||||
done
|
||||
|
||||
DIRSIZE=$(du -s "$DIR")
|
||||
|
||||
DIR=$(readlink -f "$DIR")
|
||||
DIR_SHORT=$(basename "$DIR")
|
||||
echo Compressing "$DIR"
|
||||
DIRSIZE=$(du -sh "$DIR" | cut -f1)
|
||||
|
||||
# Make basic dirs
|
||||
mkdir -p "${DIR}"
|
||||
mkdir -p "${DIR_SHORT}"
|
||||
|
||||
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
|
||||
OVERLAY_UPPER=${OVERLAY_ROOT}/upper
|
||||
OVERLAY_LOWER=${OVERLAY_ROOT}/lower
|
||||
OVERLAY_WORK=${OVERLAY_ROOT}/work
|
||||
OVERLAY_TARG=$DIR
|
||||
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
|
||||
OVERLAY_UPPER="$OVERLAY_ROOT/upper"
|
||||
OVERLAY_LOWER="$OVERLAY_ROOT/lower"
|
||||
OVERLAY_WORK="$OVERLAY_ROOT/work"
|
||||
OVERLAY_TARG="$DIR"
|
||||
RECREATE=false
|
||||
|
||||
echo "Overlay information"
|
||||
echo "========================================================================="
|
||||
echo "> DIR = \"$DIR\""
|
||||
echo "> DIR_SHORT = \"$DIR_SHORT\""
|
||||
echo "> OVERLAY_ROOT = \"$OVERLAY_ROOT\""
|
||||
echo "> OVERLAY_UPPER = \"$OVERLAY_UPPER\""
|
||||
echo "> OVERLAY_LOWER= \"$OVERLAY_LOWER\""
|
||||
echo "> OVERLAY_WORK = \"$OVERLAY_WORK\""
|
||||
echo "> OVERLAY_TARG = \"$OVERLAY_TARG\""
|
||||
echo "========================================================================="
|
||||
|
||||
mkdir -p "$OVERLAY_ROOT"
|
||||
|
||||
# Check for existing image
|
||||
if test -f "${OVERLAY_ROOT}.img"; then
|
||||
echo "We already have an existing image, updating it..."
|
||||
mount-squash-image "$DIR"
|
||||
DIRSIZE=$(du -s "$DIR")
|
||||
if [[ -f "${OVERLAY_ROOT}.img" ]]; then
|
||||
echo "Existing image found, updating..."
|
||||
"$BIN_DIR/mount-squash-image" "$DIR"
|
||||
DIRSIZE=$(du -sh "$DIR" | cut -f1)
|
||||
RECREATE=true
|
||||
fi
|
||||
|
||||
sudo mksquashfs "$DIR" "${OVERLAY_ROOT}.img.1" -noappend -comp xz
|
||||
echo "Compressing \"$DIR\"..."
|
||||
sudo mksquashfs "$DIR" "${OVERLAY_ROOT}.img.1" -noappend -comp xz || exit 1
|
||||
|
||||
if [ $RECREATE == true ]; then
|
||||
echo "Copy created, now unmount and swap everything."
|
||||
umount-squash-image "$DIR"
|
||||
sudo rm -rf "$OVERLAY_UPPER"
|
||||
sudo rm -rf "$OVERLAY_LOWER"
|
||||
sudo rm -rf "$OVERLAY_WORK"
|
||||
rm -rf "${OVERLAY_ROOT}.img"
|
||||
if [[ "$RECREATE" == "true" ]]; then
|
||||
echo "Cleaning up old layers..."
|
||||
"$BIN_DIR/umount-squash-image" "$DIR"
|
||||
# Safety check before destructive RM
|
||||
if [[ -n "$OVERLAY_ROOT" && "$OVERLAY_ROOT" != "/" ]]; then
|
||||
sudo rm -rf "$OVERLAY_UPPER" "$OVERLAY_LOWER" "$OVERLAY_WORK"
|
||||
rm -f "${OVERLAY_ROOT}.img"
|
||||
fi
|
||||
fi
|
||||
|
||||
mv "${OVERLAY_ROOT}.img.1" "${OVERLAY_ROOT}.img"
|
||||
|
||||
# Make the dirs for the overlay
|
||||
mkdir -p "$OVERLAY_UPPER"
|
||||
mkdir -p "$OVERLAY_LOWER"
|
||||
mkdir -p "$OVERLAY_WORK"
|
||||
mkdir -p "$OVERLAY_TARG"
|
||||
# Prepare overlay structure
|
||||
mkdir -p "$OVERLAY_UPPER" "$OVERLAY_LOWER" "$OVERLAY_WORK" "$OVERLAY_TARG"
|
||||
|
||||
# Reset dir
|
||||
# Reset original directory to mountpoint
|
||||
sudo rm -rf "$DIR"
|
||||
mkdir -p "$DIR"
|
||||
touch "${DIR}/.needs_mount"
|
||||
touch "$DIR/.needs_mount"
|
||||
|
||||
echo "========================================================================="
|
||||
echo "Storage data:"
|
||||
echo "Uncompressed: $DIRSIZE"
|
||||
echo " Compressed: $(du -s ${OVERLAY_ROOT}.img)"
|
||||
echo "========================================================================="
|
||||
echo "-------------------------------------------------------------------------"
|
||||
echo "Storage Stats:"
|
||||
echo " Original size: $DIRSIZE"
|
||||
echo " Compressed: $(du -sh "${OVERLAY_ROOT}.img" | cut -f1)"
|
||||
echo "-------------------------------------------------------------------------"
|
||||
|
||||
# Service content embedded
|
||||
# SystemD Service Setup
|
||||
SERVICE_CONTENT="[Unit]
|
||||
Description=SquashFS Mount for %I
|
||||
After=local-fs.target
|
||||
|
|
@ -113,7 +90,7 @@ echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/squash-mount@.service > /
|
|||
sudo systemctl daemon-reload
|
||||
|
||||
ESC_PATH=$(systemd-escape -p "$DIR")
|
||||
SERVICE_NAME="squash-mount@-$ESC_PATH"
|
||||
SERVICE_NAME="squash-mount@$ESC_PATH.service"
|
||||
|
||||
read -p "Do you want to auto-enable the mount service ($SERVICE_NAME)? [y/N] " yn
|
||||
case $yn in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue