From 83324dd0f730fee84ef2fd2fa191d1a2020a1d94 Mon Sep 17 00:00:00 2001 From: Sam Hardeman Date: Fri, 13 Mar 2026 01:38:34 +0100 Subject: [PATCH] After gemini-propoesed fixes --- agenda | 12 ++-- cdz | 133 ++++++++++++++++--------------------------- daisy.source | 21 ++++--- destroy-squash-image | 48 +++++++--------- editx | 13 ++--- make-squash-image | 101 +++++++++++++------------------- mount-squash-image | 50 +++++++++------- own | 18 ++++-- sshp | 101 +++++++++++--------------------- umount-squash-image | 27 ++++++--- what | 11 ++-- 11 files changed, 228 insertions(+), 307 deletions(-) diff --git a/agenda b/agenda index 837cd0f..f89dd61 100755 --- a/agenda +++ b/agenda @@ -28,10 +28,7 @@ root_dir=$(dirname $1)/.daisy/$(basename $1) today_sym=$1 # Present day -today=$(date -I) -year=$(echo $today | awk -F"-" '{print $1}') -month=$(echo $today | awk -F"-" '{print $2}') -day=$(echo $today | awk -F"-" '{print $3}') +read year month day < <(date "+%Y %m %d") set -e @@ -50,11 +47,10 @@ function errorFn trap errorFn ERR # First we clear out empty folders, and remove the symlink if it exists -test -e "$root_dir" && find "$root_dir" -maxdepth 3 -type d -empty -print | xargs rm -rf -test -L "$today_sym" && rm -rf "$today_sym" +test -e "$root_dir" && find "$root_dir" -maxdepth 3 -type d -empty -delete # Now we can set up today's directory mkdir -p "$root_dir/$year/$month/$day" -ln -s "$root_dir/$year/$month/$day" "$today_sym" +ln -sf "$root_dir/$year/$month/$day" "$today_sym" ln -s "$root_dir" "$today_sym/.tree" -exitcode=@? +exitcode=$? diff --git a/cdz b/cdz index a380222..94e5e4c 100755 --- a/cdz +++ b/cdz @@ -1,118 +1,85 @@ #!/usr/bin/env bash +# Usage: cdz -if [[ $LD_INTERNAL -ne 1 ]]; -then +if [[ $LD_INTERNAL -ne 1 ]]; then LD_INTERNAL=1 . $(dirname $(realpath $0))/daisy.source fi target=$1 - -# Check if file exists -if [[ -z "$target" ]]; -then +if [[ -z "$target" ]]; then echo "No target specified." exit 1 fi -if ! test -f "$target"; -then +if [[ ! -f "$target" ]]; then echo "File not found: \"$target\"" exit 2 fi -# Check if archivemount is present -which archivemount 1>/dev/null 2>/dev/null -hasmounter=$? +target_abs=$(realpath "$target") +name=$(basename "$target") -file "$target" 1>/dev/null -exitcode=$? -report=$(file "$target") -name=$(echo $@ | sed 's/:.*//' | sed 's|.*/||') +has_archivemount=$(command -v archivemount >/dev/null 2>&1; echo $?) + +if [[ $has_archivemount -eq 0 && $NO_ARCHIVEMOUNT -ne 1 ]]; then + use_mounter=1 +else + use_mounter=0 +fi + +mime_type=$(file --mime-type -b "$target") -# Check for archive type, supported types are zip/tar/rar comm1=(:) -comm2=(echo "Unsupported archive type$add: \"$target\"") +comm2=(echo "Unsupported archive type: $mime_type") comm3=(:) comm4=(:) comm5=(:) -echo $report | grep "tar archive" 1>/dev/null -istar=$? -echo $report | grep "Zip archive" 1>/dev/null -iszip=$? -echo $report | grep "Android" 1>/dev/null -iszip=$? -echo $report | grep "RAR archive" 1>/dev/null -israr=$? - -# TAR archives come in many forms, if none of our tests say it's tar -# ...but it looks like tar and barks like tar, let's take the shot. -# Seems to work fairly well for the record. -res=$(echo "$target" | grep ".tar") -if [[ $res != "" ]]; -then - istar=0 +if [[ $use_mounter -eq 1 ]]; then + echo "Using archivemount..." + comm2=(archivemount -o allow_root,use_ino "$target_abs") + comm4=(cd ..) + comm5=(umount) +elif [[ $mime_type == *"tar"* || $target == *.tar* ]]; then + comm2=(tar xvf "$target_abs" -C) +elif [[ $mime_type == "application/zip" ]]; then + if command -v unzip >/dev/null 2>&1; then + comm2=(unzip -q "$target_abs" -d) + else + comm1=(echo "unzip is missing") + comm3=(exit 1) + fi +elif [[ $mime_type == "application/x-rar" ]]; then + if command -v unrar >/dev/null 2>&1; then + # unrar needs the directory as the last argument + comm2=(unrar x -idq "$target_abs") + else + comm1=(echo "unrar is missing") + comm3=(exit 1) + fi fi -if [[ $NO_ARCHIVEMOUNT -eq 1 ]]; then - hasmounter=1 -fi - -if (( $hasmounter == 0 )); then - echo "We have \`archivemount\`, so we'll use that!" - echo "If you'd prefer we not use it, please specify NO_ARCHIVEMOUNT=1" - istar=1 - iszip=1 - israr=1 -fi - -# Now we set the right command -if (( $istar == 0 )); then - comm2=(tar xvf "$target" -C) -elif (( $iszip == 0 )); then - which unzip 1>/dev/null - exitcode=$? - if (( $exitcode == 0 )); then - comm2=(unzip -q "$target" -d) - else - comm1=(echo "The utility 'unzip' is missing, please install it") - comm3=(exit 1) - fi -elif (( $israr == 0 )); then - which unrar 1>/dev/null - exitcode=$? - if (( exitcode == 0 )); then - comm2=(unrar -i nul "$target") - else - comm1=(echo "The utility 'unrar' is missing, please install it") - comm3=(exit 1) - fi -elif (( $hasmounter == 0 )); then - comm2=(archivemount -o allow_root -o use_ino "$target") - comm4=(cd ..) - comm5=(umount) -fi - -# Create the temp dir, usually dir=$(mktemp -d /tmp/extracted.XXXXXXXX) -# And the rest of the commands "${comm1[@]}" -"${comm2[@]}" $dir +if [[ ${comm2[0]} == "unrar" ]]; then + "${comm2[@]}" "$dir" +else + "${comm2[@]}" "$dir" +fi "${comm3[@]}" -currentpath=$(pwd) -sym="$currentpath/$name.tmp" -ln -f -s "$dir" "$sym" +sym="$(pwd)/$name.tmp" +ln -sf "$dir" "$sym" cd "$sym" -echo "A symlink has been made under the name \"$sym\"." -echo "This symlink points to the data directory \"$dir\"." +echo "Extracted to $dir (linked via $sym)" +echo "Type exit to finish." -echo "Type 'exit' to exit the extracted archive's folder and auto-delete it." eval $SHELL + "${comm4[@]}" -"${comm5[@]}" $dir -rm -rf $dir +"${comm5[@]}" "$dir" +rm -rf "$dir" rm "$sym" diff --git a/daisy.source b/daisy.source index 24fa572..97a43c6 100755 --- a/daisy.source +++ b/daisy.source @@ -24,7 +24,6 @@ function ld_dbg then $@ fi - echo } # Variables for use in other utilities @@ -38,10 +37,11 @@ fi # Check for dependencies function _daisy_dependency_check { - BIN=$(command -v $1 2>/dev/null) - res=$? - - echo $(($res ^ 1)) + if command -v "$1" >/dev/null 2>&1; then + echo 1 + else + echo 0 + fi } LD_HAS_fzf=$(_daisy_dependency_check fzf) @@ -88,10 +88,9 @@ ld_dbg cat $LD_EDITORFILE # Source everything in the config folder function _daisy_source_configs { - for f in `find "$LD_CONFIG_FOLDER" -name "*.src" -type f`; - do - source "$f" - done +while IFS= read -r -d '' f; do + source "$f" + done < <(find "$LD_CONFIG_FOLDER" -name "*.src" -type f -print0) } # Installation into PATH @@ -124,7 +123,7 @@ function daisy_wait_for_editor while true; do - alive=$(ps aux | grep $fname | grep $pname) + alive=$(pgrep -f "$pname.*$fname") if [[ $alive == "" ]] then break @@ -265,7 +264,7 @@ function ched for editor in "${editors[@]}"; do editor_real=$(command -v "$editor") - if command -v "$editor_rmeal" >/dev/null 2>&1; + if command -v "$editor_real" >/dev/null 2>&1; then if [[ $(realpath "$EDITOR") == "$editor_real" ]]; then diff --git a/destroy-squash-image b/destroy-squash-image index 8bde37f..6eef52a 100755 --- a/destroy-squash-image +++ b/destroy-squash-image @@ -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 " 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\"." diff --git a/editx b/editx index 839dfd2..685a977 100755 --- a/editx +++ b/editx @@ -16,15 +16,12 @@ then ched "EDITOR env variable not set! You will have to set it yourself in the next screen." fi -exists=$(file "$1" >/dev/null && echo $?) +[[ -e "$1" ]] && existed=1 || existed=0 touch "$1" -chmod +x "$1" -$EDITOR "$1" -wait $! -size=$(du "$1" | cut -f 1) +chmod +x "$1" +daisy_editor "$1" -if [[ $size -eq 0 && $exists -ne 0 ]]; -then - rm -rf "$1" +if [[ ! -s "$1" && $existed -eq 0 ]]; then + rm -f "$1" fi diff --git a/make-squash-image b/make-squash-image index b6111e9..17e0099 100755 --- a/make-squash-image +++ b/make-squash-image @@ -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 " 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 diff --git a/mount-squash-image b/mount-squash-image index ee46f3d..2c0fac9 100755 --- a/mount-squash-image +++ b/mount-squash-image @@ -1,38 +1,46 @@ #!/bin/bash -DIR="$@" +# Lackadaisical squashfs tools - Mount + +DIR="$1" +if [[ -z "$DIR" ]]; then + echo "Usage: $0 " + exit 1 +fi + DIR=$(readlink -f "$DIR") DIR_SHORT=$(basename "$DIR") BIN_DIR=$(dirname "$(readlink -f "$0")") -mkdir -p "$DIR" -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" -if [ ! -f "${OVERLAY_ROOT}.img" ]; then - echo "Error: SquashFS image ${OVERLAY_ROOT}.img not found." >&2 +if [[ ! -f "${OVERLAY_ROOT}.img" ]]; then + echo "Error: SquashFS image \"${OVERLAY_ROOT}.img\" not found." >&2 exit 1 fi -"$BIN_DIR"/umount-squash-image "$@" 1>/dev/null 2>/dev/null +# Unmount existing first +"$BIN_DIR/umount-squash-image" "$DIR" 2>/dev/null +# Mount lower squashfs image via loopback +mkdir -p "$OVERLAY_LOWER" sudo mount "${OVERLAY_ROOT}.img" "$OVERLAY_LOWER" -t squashfs -o loop -EXIT_CODE=$? -if [ $EXIT_CODE -ne 0 ]; then - echo "Error: Failed to mount squashfs image (exit code $EXIT_CODE)." >&2 - exit $EXIT_CODE +if [[ $? -ne 0 ]]; then + echo "Error: Failed to mount squashfs image." >&2 + exit 1 fi -sudo mount -t overlay -o lowerdir="$OVERLAY_LOWER",upperdir="$OVERLAY_UPPER",workdir="$OVERLAY_WORK" none "$OVERLAY_TARG" -EXIT_CODE=$? -if [ $EXIT_CODE -ne 0 ]; then - echo "Error: Failed to mount overlay (exit code $EXIT_CODE)." >&2 - # Cleanup: unmount the lower squashfs if overlay mount fails +# Mount overlay +sudo mount -t overlay none "$OVERLAY_TARG" \ + -o lowerdir="$OVERLAY_LOWER",upperdir="$OVERLAY_UPPER",workdir="$OVERLAY_WORK" + +if [[ $? -ne 0 ]]; then + echo "Error: Failed to mount overlay." >&2 sudo umount "$OVERLAY_LOWER" 2>/dev/null - exit $EXIT_CODE + exit 1 fi echo "SquashFS filesystem is mounted and ready." -exit 0 diff --git a/own b/own index a04be63..6db1b49 100755 --- a/own +++ b/own @@ -5,13 +5,19 @@ LD_INTERNAL=1 . $(dirname $(realpath $0))/daisy.source -if [[ $@ == '' ]]; -then - echo "$LD_BIN: Used to quickly take ownership of files/folders." - echo "Requires sudo. If sudo is not installed, this tool will fai." +if [[ -z "$1" ]]; then + echo "$LD_BIN: Quickly take ownership of files/folders." echo "Usage: $LD_BIN " - echo "Means: chown -R : " + echo "Requires sudo. If sudo is not installed, this tool will fail." exit 2 fi -sudo chown -R $(whoami):$(whoami) "$@" 1>/dev/null 2>/dev/null +# Ensure all arguments exist before attempting chown +for target in "$@"; do + if [[ ! -e "$target" ]]; then + echo "Error: \"$target\" does not exist." + exit 1 + fi +done + +sudo chown -R "$(whoami):$(whoami)" "$@" diff --git a/sshp b/sshp index eeedc7e..8f5c5c5 100755 --- a/sshp +++ b/sshp @@ -1,95 +1,58 @@ #!/usr/bin/env bash +# sshp ("SSH PLUS") from lackadaisical mounts=() ssh_args=() remote_port=$((10000 + RANDOM % 10000)) local_user=$(whoami) -usage() -{ - echo "sshp (\"SSH PLUS\") from lackadaisical." - echo "Accepts all standard SSH options (see man ssh)." - echo "Additionally, supports SSHFS mounts using a Docker-style syntax (-m)." - echo "Usage: sshp -m : [user@]host [ssh_options]" - echo "Example: sshp -m /home/juli:/home/juli juli@juli.pyon" - exit 1 +usage() { + echo "Usage: sshp -m : [user@]host [ssh_options]" + exit 1 } while [[ $# -gt 0 ]]; do - case "$1" in - -m) - if [[ -z "$2" ]] - then - echo "Error: -m requires argument" - exit 1 - fi - mounts+=("$2") - shift 2 - ;; - *) - ssh_args+=("$1") - shift - ;; - esac + case "$1" in + -m) + if [[ -z "$2" ]]; then echo "Error: -m requires argument"; exit 1; fi + mounts+=("$2") + shift 2 + ;; + *) + ssh_args+=("$1") + shift + ;; + esac done -if [[ ${#ssh_args[@]} -eq 0 ]] -then - usage -fi +[[ ${#ssh_args[@]} -eq 0 ]] && usage mount_logic="" unmount_logic="" for map in "${mounts[@]}"; do - local_path="${map%%:*}" - remote_path="${map##*:}" + local_path="${map%%:*}" + remote_path="${map##*:}" + [[ "$local_path" != /* ]] && local_path="$PWD/$local_path" - if [[ "$local_path" != /* ]] - then - local_path="$PWD/$local_path" - fi + mount_logic+=" + echo '>> Preparing mount: ${remote_path}'; + mkdir -p \"${remote_path}\" 2>/dev/null || sudo mkdir -p \"${remote_path}\" - mount_logic+=" - echo '>> Preparing mount: ${remote_path}'; - if ! mkdir -p \"${remote_path}\" 2>/dev/null - then - sudo mkdir -p \"${remote_path}\" - fi - - if ! sshfs -p ${remote_port} -o StrictHostKeyChecking=no,idmap=user ${local_user}@localhost:\"${local_path}\" \"${remote_path}\" 2>/dev/null - then - echo ' (User mount failed, attempting escalation...)'; - if ! sudo sshfs -p ${remote_port} -o StrictHostKeyChecking=no,idmap=user,allow_other ${local_user}@localhost:\"${local_path}\" \"${remote_path}\" - then - echo ' ! Mount failed completely. Check permissions or keys.'; - fi - else - echo ' > Mounted successfully.'; - fi - " - - unmount_logic+=" - fusermount -u -z \"${remote_path}\" 2>/dev/null || sudo fusermount -u -z \"${remote_path}\" 2>/dev/null; - " + sshfs -p ${remote_port} -o StrictHostKeyChecking=no,idmap=user ${local_user}@localhost:\"${local_path}\" \"${remote_path}\" 2>/dev/null || \ + sudo sshfs -p ${remote_port} -o StrictHostKeyChecking=no,idmap=user,allow_other ${local_user}@localhost:\"${local_path}\" \"${remote_path}\" + " + unmount_logic+="fusermount -u -z \"${remote_path}\" 2>/dev/null || sudo fusermount -u -z \"${remote_path}\" 2>/dev/null;" done remote_script=" - if ! command -v sshfs >/dev/null 2>&1 - then - echo 'WARNING: \"sshfs\" not found on remote host.' - echo '>> Skipping mounts, proceeding with shell only...'; - echo '----------------------------------------------'; - else - ${mount_logic} - fi - - ${SHELL:-bash}; - - if command -v sshfs >/dev/null 2>&1 - then + if ! command -v sshfs >/dev/null 2>&1; then + echo 'WARNING: \"sshfs\" not found on remote host.' + else + ${mount_logic} + fi + \${SHELL:-bash}; ${unmount_logic} - fi " ssh -t -R ${remote_port}:localhost:22 "${ssh_args[@]}" "$remote_script" diff --git a/umount-squash-image b/umount-squash-image index 58f36b1..18fd764 100755 --- a/umount-squash-image +++ b/umount-squash-image @@ -1,16 +1,27 @@ #!/bin/bash -DIR="$@" +# Lackadaisical squashfs tools - Unmount + +DIR="$1" +if [[ -z "$DIR" ]]; then + echo "Usage: $0 " + exit 1 +fi + DIR=$(readlink -f "$DIR") DIR_SHORT=$(basename "$DIR") -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_LOWER="$OVERLAY_ROOT/lower" +OVERLAY_TARG="$DIR" -sudo umount -R "$OVERLAY_TARG" 2>/dev/null -sudo umount -R "$OVERLAY_LOWER" 2>/dev/null +# Forcefully unmount both layers recursively +sudo umount -l -R "$OVERLAY_TARG" 2>/dev/null +sudo umount -l -R "$OVERLAY_LOWER" 2>/dev/null + +if mountpoint -q "$OVERLAY_TARG" || mountpoint -q "$OVERLAY_LOWER"; then + echo "Warning: Filesystem is still mounted. Check for open processes." + exit 1 +fi echo "SquashFS filesystem has been unmounted." exit 0 diff --git a/what b/what index b4a470d..707e0ce 100755 --- a/what +++ b/what @@ -26,7 +26,10 @@ LD_INTERNAL=1 . $(dirname $(realpath $0))/daisy.source -pwd=/ -all_bins=$(cd / && echo $PATH | sed 's/[:]/ /g' | xargs ls -A | grep -v ":" | sort | uniq) -output=$(printf '%s\n' "-n" $all_bins | grep -i "$1") -echo "$output" +all_bins=$(compgen -c | sort -u) + +if [[ -n "$1" ]]; then + echo "$all_bins" | grep -i "$1" +else + echo "$all_bins" +fi