After gemini-propoesed fixes
This commit is contained in:
parent
2e31283b61
commit
83324dd0f7
11 changed files with 228 additions and 307 deletions
12
agenda
12
agenda
|
|
@ -28,10 +28,7 @@ root_dir=$(dirname $1)/.daisy/$(basename $1)
|
||||||
today_sym=$1
|
today_sym=$1
|
||||||
|
|
||||||
# Present day
|
# Present day
|
||||||
today=$(date -I)
|
read year month day < <(date "+%Y %m %d")
|
||||||
year=$(echo $today | awk -F"-" '{print $1}')
|
|
||||||
month=$(echo $today | awk -F"-" '{print $2}')
|
|
||||||
day=$(echo $today | awk -F"-" '{print $3}')
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
@ -50,11 +47,10 @@ function errorFn
|
||||||
trap errorFn ERR
|
trap errorFn ERR
|
||||||
|
|
||||||
# First we clear out empty folders, and remove the symlink if it exists
|
# 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 -e "$root_dir" && find "$root_dir" -maxdepth 3 -type d -empty -delete
|
||||||
test -L "$today_sym" && rm -rf "$today_sym"
|
|
||||||
|
|
||||||
# Now we can set up today's directory
|
# Now we can set up today's directory
|
||||||
mkdir -p "$root_dir/$year/$month/$day"
|
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"
|
ln -s "$root_dir" "$today_sym/.tree"
|
||||||
exitcode=@?
|
exitcode=$?
|
||||||
|
|
|
||||||
133
cdz
133
cdz
|
|
@ -1,118 +1,85 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Usage: cdz <archive>
|
||||||
|
|
||||||
if [[ $LD_INTERNAL -ne 1 ]];
|
if [[ $LD_INTERNAL -ne 1 ]]; then
|
||||||
then
|
|
||||||
LD_INTERNAL=1
|
LD_INTERNAL=1
|
||||||
. $(dirname $(realpath $0))/daisy.source
|
. $(dirname $(realpath $0))/daisy.source
|
||||||
fi
|
fi
|
||||||
|
|
||||||
target=$1
|
target=$1
|
||||||
|
if [[ -z "$target" ]]; then
|
||||||
# Check if file exists
|
|
||||||
if [[ -z "$target" ]];
|
|
||||||
then
|
|
||||||
echo "No target specified."
|
echo "No target specified."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test -f "$target";
|
if [[ ! -f "$target" ]]; then
|
||||||
then
|
|
||||||
echo "File not found: \"$target\""
|
echo "File not found: \"$target\""
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if archivemount is present
|
target_abs=$(realpath "$target")
|
||||||
which archivemount 1>/dev/null 2>/dev/null
|
name=$(basename "$target")
|
||||||
hasmounter=$?
|
|
||||||
|
|
||||||
file "$target" 1>/dev/null
|
has_archivemount=$(command -v archivemount >/dev/null 2>&1; echo $?)
|
||||||
exitcode=$?
|
|
||||||
report=$(file "$target")
|
if [[ $has_archivemount -eq 0 && $NO_ARCHIVEMOUNT -ne 1 ]]; then
|
||||||
name=$(echo $@ | sed 's/:.*//' | sed 's|.*/||')
|
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=(:)
|
comm1=(:)
|
||||||
comm2=(echo "Unsupported archive type$add: \"$target\"")
|
comm2=(echo "Unsupported archive type: $mime_type")
|
||||||
comm3=(:)
|
comm3=(:)
|
||||||
comm4=(:)
|
comm4=(:)
|
||||||
comm5=(:)
|
comm5=(:)
|
||||||
|
|
||||||
echo $report | grep "tar archive" 1>/dev/null
|
if [[ $use_mounter -eq 1 ]]; then
|
||||||
istar=$?
|
echo "Using archivemount..."
|
||||||
echo $report | grep "Zip archive" 1>/dev/null
|
comm2=(archivemount -o allow_root,use_ino "$target_abs")
|
||||||
iszip=$?
|
comm4=(cd ..)
|
||||||
echo $report | grep "Android" 1>/dev/null
|
comm5=(umount)
|
||||||
iszip=$?
|
elif [[ $mime_type == *"tar"* || $target == *.tar* ]]; then
|
||||||
echo $report | grep "RAR archive" 1>/dev/null
|
comm2=(tar xvf "$target_abs" -C)
|
||||||
israr=$?
|
elif [[ $mime_type == "application/zip" ]]; then
|
||||||
|
if command -v unzip >/dev/null 2>&1; then
|
||||||
# TAR archives come in many forms, if none of our tests say it's tar
|
comm2=(unzip -q "$target_abs" -d)
|
||||||
# ...but it looks like tar and barks like tar, let's take the shot.
|
else
|
||||||
# Seems to work fairly well for the record.
|
comm1=(echo "unzip is missing")
|
||||||
res=$(echo "$target" | grep ".tar")
|
comm3=(exit 1)
|
||||||
if [[ $res != "" ]];
|
fi
|
||||||
then
|
elif [[ $mime_type == "application/x-rar" ]]; then
|
||||||
istar=0
|
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
|
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)
|
dir=$(mktemp -d /tmp/extracted.XXXXXXXX)
|
||||||
|
|
||||||
# And the rest of the commands
|
|
||||||
"${comm1[@]}"
|
"${comm1[@]}"
|
||||||
"${comm2[@]}" $dir
|
if [[ ${comm2[0]} == "unrar" ]]; then
|
||||||
|
"${comm2[@]}" "$dir"
|
||||||
|
else
|
||||||
|
"${comm2[@]}" "$dir"
|
||||||
|
fi
|
||||||
"${comm3[@]}"
|
"${comm3[@]}"
|
||||||
|
|
||||||
currentpath=$(pwd)
|
sym="$(pwd)/$name.tmp"
|
||||||
sym="$currentpath/$name.tmp"
|
ln -sf "$dir" "$sym"
|
||||||
ln -f -s "$dir" "$sym"
|
|
||||||
cd "$sym"
|
cd "$sym"
|
||||||
|
|
||||||
echo "A symlink has been made under the name \"$sym\"."
|
echo "Extracted to $dir (linked via $sym)"
|
||||||
echo "This symlink points to the data directory \"$dir\"."
|
echo "Type exit to finish."
|
||||||
|
|
||||||
echo "Type 'exit' to exit the extracted archive's folder and auto-delete it."
|
|
||||||
eval $SHELL
|
eval $SHELL
|
||||||
|
|
||||||
"${comm4[@]}"
|
"${comm4[@]}"
|
||||||
"${comm5[@]}" $dir
|
"${comm5[@]}" "$dir"
|
||||||
rm -rf $dir
|
rm -rf "$dir"
|
||||||
rm "$sym"
|
rm "$sym"
|
||||||
|
|
|
||||||
21
daisy.source
21
daisy.source
|
|
@ -24,7 +24,6 @@ function ld_dbg
|
||||||
then
|
then
|
||||||
$@
|
$@
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Variables for use in other utilities
|
# Variables for use in other utilities
|
||||||
|
|
@ -38,10 +37,11 @@ fi
|
||||||
# Check for dependencies
|
# Check for dependencies
|
||||||
function _daisy_dependency_check
|
function _daisy_dependency_check
|
||||||
{
|
{
|
||||||
BIN=$(command -v $1 2>/dev/null)
|
if command -v "$1" >/dev/null 2>&1; then
|
||||||
res=$?
|
echo 1
|
||||||
|
else
|
||||||
echo $(($res ^ 1))
|
echo 0
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
LD_HAS_fzf=$(_daisy_dependency_check fzf)
|
LD_HAS_fzf=$(_daisy_dependency_check fzf)
|
||||||
|
|
@ -88,10 +88,9 @@ ld_dbg cat $LD_EDITORFILE
|
||||||
# Source everything in the config folder
|
# Source everything in the config folder
|
||||||
function _daisy_source_configs
|
function _daisy_source_configs
|
||||||
{
|
{
|
||||||
for f in `find "$LD_CONFIG_FOLDER" -name "*.src" -type f`;
|
while IFS= read -r -d '' f; do
|
||||||
do
|
source "$f"
|
||||||
source "$f"
|
done < <(find "$LD_CONFIG_FOLDER" -name "*.src" -type f -print0)
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Installation into PATH
|
# Installation into PATH
|
||||||
|
|
@ -124,7 +123,7 @@ function daisy_wait_for_editor
|
||||||
|
|
||||||
while true;
|
while true;
|
||||||
do
|
do
|
||||||
alive=$(ps aux | grep $fname | grep $pname)
|
alive=$(pgrep -f "$pname.*$fname")
|
||||||
if [[ $alive == "" ]]
|
if [[ $alive == "" ]]
|
||||||
then
|
then
|
||||||
break
|
break
|
||||||
|
|
@ -265,7 +264,7 @@ function ched
|
||||||
for editor in "${editors[@]}";
|
for editor in "${editors[@]}";
|
||||||
do
|
do
|
||||||
editor_real=$(command -v "$editor")
|
editor_real=$(command -v "$editor")
|
||||||
if command -v "$editor_rmeal" >/dev/null 2>&1;
|
if command -v "$editor_real" >/dev/null 2>&1;
|
||||||
then
|
then
|
||||||
if [[ $(realpath "$EDITOR") == "$editor_real" ]];
|
if [[ $(realpath "$EDITOR") == "$editor_real" ]];
|
||||||
then
|
then
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Lackadaisical squashfs tools - Destroy
|
# Lackadaisical squashfs tools - Destroy
|
||||||
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
|
||||||
DIR="$1"
|
|
||||||
|
|
||||||
|
DIR="$1"
|
||||||
if [[ -z "$DIR" ]]; then
|
if [[ -z "$DIR" ]]; then
|
||||||
echo "Usage: $0 <directory>"
|
echo "Usage: $0 <directory>"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -10,47 +9,42 @@ fi
|
||||||
|
|
||||||
DIR=$(readlink -f "$DIR")
|
DIR=$(readlink -f "$DIR")
|
||||||
DIR_SHORT=$(basename "$DIR")
|
DIR_SHORT=$(basename "$DIR")
|
||||||
|
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
||||||
|
|
||||||
if [[ ! -f "$DIR/.needs_mount" ]]; then
|
if [[ ! -f "$DIR/.needs_mount" ]]; then
|
||||||
if ! mountpoint -q "$DIR"; then
|
if ! mountpoint -q "$DIR"; then
|
||||||
echo "Error: $DIR does not appear to be a SquashFS-backed directory (missing .needs_mount)."
|
echo "Error: $DIR is not a SquashFS directory."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Disable systemd service
|
# Stop systemd service
|
||||||
ESC_PATH=$(systemd-escape -p "$DIR")
|
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 stop "$SERVICE_NAME" 2>/dev/null
|
||||||
sudo systemctl disable "$SERVICE_NAME" 2>/dev/null
|
sudo systemctl disable "$SERVICE_NAME" 2>/dev/null
|
||||||
|
|
||||||
# Ensure it is mounted to copy merged data
|
# Ensure it is mounted to copy merged data
|
||||||
echo "Ensuring image is mounted to preserve 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)
|
# Atomic copy-out
|
||||||
# Copy data out (preserving all attributes)
|
TEMP_DIR=$(mktemp -d /tmp/squash-dest.XXXXXXXX)
|
||||||
sudo rsync -a "$DIR/" "$TEMP_DIR/"
|
sudo rsync -aX "$DIR/" "$TEMP_DIR/" || { echo "Error: Failed to copy data."; exit 1; }
|
||||||
|
|
||||||
# Unmount the overlay and squashfs
|
# Unmount
|
||||||
echo "Unmounting..."
|
"$BIN_DIR/umount-squash-image" "$DIR"
|
||||||
"$BIN_DIR"/umount-squash-image "$DIR"
|
|
||||||
|
|
||||||
# Restore data to original location
|
# Restore original directory structure
|
||||||
echo "Restoring files..."
|
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
|
||||||
sudo rm -rf "$DIR"
|
sudo rm -rf "$DIR"
|
||||||
sudo mv "$TEMP_DIR" "$DIR"
|
sudo mv "$TEMP_DIR" "$DIR"
|
||||||
|
|
||||||
# Cleanup hidden image and overlay files
|
# Final cleanup
|
||||||
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
|
sudo rm -rf "$OVERLAY_ROOT" "${OVERLAY_ROOT}.img"
|
||||||
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
|
|
||||||
|
|
||||||
|
echo "Success: SquashFS image destroyed and data restored to \"$DIR\"."
|
||||||
|
|
|
||||||
13
editx
13
editx
|
|
@ -16,15 +16,12 @@ then
|
||||||
ched "EDITOR env variable not set! You will have to set it yourself in the next screen."
|
ched "EDITOR env variable not set! You will have to set it yourself in the next screen."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exists=$(file "$1" >/dev/null && echo $?)
|
[[ -e "$1" ]] && existed=1 || existed=0
|
||||||
|
|
||||||
touch "$1"
|
touch "$1"
|
||||||
chmod +x "$1"
|
chmod +x "$1"
|
||||||
$EDITOR "$1"
|
daisy_editor "$1"
|
||||||
wait $!
|
|
||||||
size=$(du "$1" | cut -f 1)
|
|
||||||
|
|
||||||
if [[ $size -eq 0 && $exists -ne 0 ]];
|
if [[ ! -s "$1" && $existed -eq 0 ]]; then
|
||||||
then
|
rm -f "$1"
|
||||||
rm -rf "$1"
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,101 +1,78 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Lackadaisical squashfs tools
|
# Lackadaisical squashfs tools
|
||||||
# Allows you to create a modifiable squashfs-backed image for a folder
|
# Allows you to create a modifiable squashfs-backed image for a folder
|
||||||
|
|
||||||
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
||||||
DIR=$1
|
DIR="$1"
|
||||||
|
|
||||||
if [[ -z "$DIR" ]]; then
|
if [[ -z "$DIR" ]]; then
|
||||||
echo "Usage: $0 <directory>"
|
echo "Usage: $0 <directory>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test -d "$DIR"
|
if [[ ! -d "$DIR" ]]; then
|
||||||
if [[ $? -ne 0 ]]; then
|
echo "Error: Directory \"$DIR\" does not exist!"
|
||||||
echo Directory "$DIR" does not exist!
|
exit 1
|
||||||
exit -1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "You need support for FUSE, SquashFS, and OverlayFS."
|
echo "Checking system requirements (FUSE, SquashFS, OverlayFS)..."
|
||||||
echo "Checking your system for these requirements..."
|
|
||||||
for fs in fuse squashfs overlay; do
|
for fs in fuse squashfs overlay; do
|
||||||
if ! grep -q "$fs" /proc/filesystems; then
|
if ! grep -q "$fs" /proc/filesystems; then
|
||||||
echo "Loading $fs kernel module..."
|
echo "Attempting to load $fs module..."
|
||||||
if ! sudo modprobe "$fs"; then
|
sudo modprobe "$fs" || { echo "Error: $fs is not supported."; exit 1; }
|
||||||
echo "Error: $fs is not supported and could not be loaded."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
DIRSIZE=$(du -s "$DIR")
|
|
||||||
|
|
||||||
DIR=$(readlink -f "$DIR")
|
DIR=$(readlink -f "$DIR")
|
||||||
DIR_SHORT=$(basename "$DIR")
|
DIR_SHORT=$(basename "$DIR")
|
||||||
echo Compressing "$DIR"
|
DIRSIZE=$(du -sh "$DIR" | cut -f1)
|
||||||
|
|
||||||
# Make basic dirs
|
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
|
||||||
mkdir -p "${DIR}"
|
OVERLAY_UPPER="$OVERLAY_ROOT/upper"
|
||||||
mkdir -p "${DIR_SHORT}"
|
OVERLAY_LOWER="$OVERLAY_ROOT/lower"
|
||||||
|
OVERLAY_WORK="$OVERLAY_ROOT/work"
|
||||||
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
|
OVERLAY_TARG="$DIR"
|
||||||
OVERLAY_UPPER=${OVERLAY_ROOT}/upper
|
|
||||||
OVERLAY_LOWER=${OVERLAY_ROOT}/lower
|
|
||||||
OVERLAY_WORK=${OVERLAY_ROOT}/work
|
|
||||||
OVERLAY_TARG=$DIR
|
|
||||||
RECREATE=false
|
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"
|
mkdir -p "$OVERLAY_ROOT"
|
||||||
|
|
||||||
# Check for existing image
|
if [[ -f "${OVERLAY_ROOT}.img" ]]; then
|
||||||
if test -f "${OVERLAY_ROOT}.img"; then
|
echo "Existing image found, updating..."
|
||||||
echo "We already have an existing image, updating it..."
|
"$BIN_DIR/mount-squash-image" "$DIR"
|
||||||
mount-squash-image "$DIR"
|
DIRSIZE=$(du -sh "$DIR" | cut -f1)
|
||||||
DIRSIZE=$(du -s "$DIR")
|
|
||||||
RECREATE=true
|
RECREATE=true
|
||||||
fi
|
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
|
if [[ "$RECREATE" == "true" ]]; then
|
||||||
echo "Copy created, now unmount and swap everything."
|
echo "Cleaning up old layers..."
|
||||||
umount-squash-image "$DIR"
|
"$BIN_DIR/umount-squash-image" "$DIR"
|
||||||
sudo rm -rf "$OVERLAY_UPPER"
|
# Safety check before destructive RM
|
||||||
sudo rm -rf "$OVERLAY_LOWER"
|
if [[ -n "$OVERLAY_ROOT" && "$OVERLAY_ROOT" != "/" ]]; then
|
||||||
sudo rm -rf "$OVERLAY_WORK"
|
sudo rm -rf "$OVERLAY_UPPER" "$OVERLAY_LOWER" "$OVERLAY_WORK"
|
||||||
rm -rf "${OVERLAY_ROOT}.img"
|
rm -f "${OVERLAY_ROOT}.img"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv "${OVERLAY_ROOT}.img.1" "${OVERLAY_ROOT}.img"
|
mv "${OVERLAY_ROOT}.img.1" "${OVERLAY_ROOT}.img"
|
||||||
|
|
||||||
# Make the dirs for the overlay
|
# Prepare overlay structure
|
||||||
mkdir -p "$OVERLAY_UPPER"
|
mkdir -p "$OVERLAY_UPPER" "$OVERLAY_LOWER" "$OVERLAY_WORK" "$OVERLAY_TARG"
|
||||||
mkdir -p "$OVERLAY_LOWER"
|
|
||||||
mkdir -p "$OVERLAY_WORK"
|
|
||||||
mkdir -p "$OVERLAY_TARG"
|
|
||||||
|
|
||||||
# Reset dir
|
# Reset original directory to mountpoint
|
||||||
sudo rm -rf "$DIR"
|
sudo rm -rf "$DIR"
|
||||||
mkdir -p "$DIR"
|
mkdir -p "$DIR"
|
||||||
touch "${DIR}/.needs_mount"
|
touch "$DIR/.needs_mount"
|
||||||
|
|
||||||
echo "========================================================================="
|
echo "-------------------------------------------------------------------------"
|
||||||
echo "Storage data:"
|
echo "Storage Stats:"
|
||||||
echo "Uncompressed: $DIRSIZE"
|
echo " Original size: $DIRSIZE"
|
||||||
echo " Compressed: $(du -s ${OVERLAY_ROOT}.img)"
|
echo " Compressed: $(du -sh "${OVERLAY_ROOT}.img" | cut -f1)"
|
||||||
echo "========================================================================="
|
echo "-------------------------------------------------------------------------"
|
||||||
|
|
||||||
# Service content embedded
|
# SystemD Service Setup
|
||||||
SERVICE_CONTENT="[Unit]
|
SERVICE_CONTENT="[Unit]
|
||||||
Description=SquashFS Mount for %I
|
Description=SquashFS Mount for %I
|
||||||
After=local-fs.target
|
After=local-fs.target
|
||||||
|
|
@ -113,7 +90,7 @@ echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/squash-mount@.service > /
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
ESC_PATH=$(systemd-escape -p "$DIR")
|
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
|
read -p "Do you want to auto-enable the mount service ($SERVICE_NAME)? [y/N] " yn
|
||||||
case $yn in
|
case $yn in
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,46 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
DIR="$@"
|
# Lackadaisical squashfs tools - Mount
|
||||||
|
|
||||||
|
DIR="$1"
|
||||||
|
if [[ -z "$DIR" ]]; then
|
||||||
|
echo "Usage: $0 <directory>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
DIR=$(readlink -f "$DIR")
|
DIR=$(readlink -f "$DIR")
|
||||||
DIR_SHORT=$(basename "$DIR")
|
DIR_SHORT=$(basename "$DIR")
|
||||||
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
BIN_DIR=$(dirname "$(readlink -f "$0")")
|
||||||
mkdir -p "$DIR"
|
|
||||||
|
|
||||||
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
|
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
|
||||||
OVERLAY_UPPER=${OVERLAY_ROOT}/upper
|
OVERLAY_UPPER="$OVERLAY_ROOT/upper"
|
||||||
OVERLAY_LOWER=${OVERLAY_ROOT}/lower
|
OVERLAY_LOWER="$OVERLAY_ROOT/lower"
|
||||||
OVERLAY_WORK=${OVERLAY_ROOT}/work
|
OVERLAY_WORK="$OVERLAY_ROOT/work"
|
||||||
OVERLAY_TARG=$DIR
|
OVERLAY_TARG="$DIR"
|
||||||
|
|
||||||
if [ ! -f "${OVERLAY_ROOT}.img" ]; then
|
if [[ ! -f "${OVERLAY_ROOT}.img" ]]; then
|
||||||
echo "Error: SquashFS image ${OVERLAY_ROOT}.img not found." >&2
|
echo "Error: SquashFS image \"${OVERLAY_ROOT}.img\" not found." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
sudo mount "${OVERLAY_ROOT}.img" "$OVERLAY_LOWER" -t squashfs -o loop
|
||||||
EXIT_CODE=$?
|
if [[ $? -ne 0 ]]; then
|
||||||
if [ $EXIT_CODE -ne 0 ]; then
|
echo "Error: Failed to mount squashfs image." >&2
|
||||||
echo "Error: Failed to mount squashfs image (exit code $EXIT_CODE)." >&2
|
exit 1
|
||||||
exit $EXIT_CODE
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo mount -t overlay -o lowerdir="$OVERLAY_LOWER",upperdir="$OVERLAY_UPPER",workdir="$OVERLAY_WORK" none "$OVERLAY_TARG"
|
# Mount overlay
|
||||||
EXIT_CODE=$?
|
sudo mount -t overlay none "$OVERLAY_TARG" \
|
||||||
if [ $EXIT_CODE -ne 0 ]; then
|
-o lowerdir="$OVERLAY_LOWER",upperdir="$OVERLAY_UPPER",workdir="$OVERLAY_WORK"
|
||||||
echo "Error: Failed to mount overlay (exit code $EXIT_CODE)." >&2
|
|
||||||
# Cleanup: unmount the lower squashfs if overlay mount fails
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "Error: Failed to mount overlay." >&2
|
||||||
sudo umount "$OVERLAY_LOWER" 2>/dev/null
|
sudo umount "$OVERLAY_LOWER" 2>/dev/null
|
||||||
exit $EXIT_CODE
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "SquashFS filesystem is mounted and ready."
|
echo "SquashFS filesystem is mounted and ready."
|
||||||
exit 0
|
|
||||||
|
|
|
||||||
18
own
18
own
|
|
@ -5,13 +5,19 @@
|
||||||
LD_INTERNAL=1
|
LD_INTERNAL=1
|
||||||
. $(dirname $(realpath $0))/daisy.source
|
. $(dirname $(realpath $0))/daisy.source
|
||||||
|
|
||||||
if [[ $@ == '' ]];
|
if [[ -z "$1" ]]; then
|
||||||
then
|
echo "$LD_BIN: Quickly take ownership of files/folders."
|
||||||
echo "$LD_BIN: Used to quickly take ownership of files/folders."
|
|
||||||
echo "Requires sudo. If sudo is not installed, this tool will fai."
|
|
||||||
echo "Usage: $LD_BIN <folders or files>"
|
echo "Usage: $LD_BIN <folders or files>"
|
||||||
echo "Means: chown -R <youruser>:<youruser> <folders or files>"
|
echo "Requires sudo. If sudo is not installed, this tool will fail."
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
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)" "$@"
|
||||||
|
|
|
||||||
101
sshp
101
sshp
|
|
@ -1,95 +1,58 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# sshp ("SSH PLUS") from lackadaisical
|
||||||
|
|
||||||
mounts=()
|
mounts=()
|
||||||
ssh_args=()
|
ssh_args=()
|
||||||
remote_port=$((10000 + RANDOM % 10000))
|
remote_port=$((10000 + RANDOM % 10000))
|
||||||
local_user=$(whoami)
|
local_user=$(whoami)
|
||||||
|
|
||||||
usage()
|
usage() {
|
||||||
{
|
echo "Usage: sshp -m <local>:<remote> [user@]host [ssh_options]"
|
||||||
echo "sshp (\"SSH PLUS\") from lackadaisical."
|
exit 1
|
||||||
echo "Accepts all standard SSH options (see man ssh)."
|
|
||||||
echo "Additionally, supports SSHFS mounts using a Docker-style syntax (-m)."
|
|
||||||
echo "Usage: sshp -m <local>:<remote> [user@]host [ssh_options]"
|
|
||||||
echo "Example: sshp -m /home/juli:/home/juli juli@juli.pyon"
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-m)
|
-m)
|
||||||
if [[ -z "$2" ]]
|
if [[ -z "$2" ]]; then echo "Error: -m requires argument"; exit 1; fi
|
||||||
then
|
mounts+=("$2")
|
||||||
echo "Error: -m requires argument"
|
shift 2
|
||||||
exit 1
|
;;
|
||||||
fi
|
*)
|
||||||
mounts+=("$2")
|
ssh_args+=("$1")
|
||||||
shift 2
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
esac
|
||||||
ssh_args+=("$1")
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#ssh_args[@]} -eq 0 ]]
|
[[ ${#ssh_args[@]} -eq 0 ]] && usage
|
||||||
then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
mount_logic=""
|
mount_logic=""
|
||||||
unmount_logic=""
|
unmount_logic=""
|
||||||
|
|
||||||
for map in "${mounts[@]}"; do
|
for map in "${mounts[@]}"; do
|
||||||
local_path="${map%%:*}"
|
local_path="${map%%:*}"
|
||||||
remote_path="${map##*:}"
|
remote_path="${map##*:}"
|
||||||
|
[[ "$local_path" != /* ]] && local_path="$PWD/$local_path"
|
||||||
|
|
||||||
if [[ "$local_path" != /* ]]
|
mount_logic+="
|
||||||
then
|
echo '>> Preparing mount: ${remote_path}';
|
||||||
local_path="$PWD/$local_path"
|
mkdir -p \"${remote_path}\" 2>/dev/null || sudo mkdir -p \"${remote_path}\"
|
||||||
fi
|
|
||||||
|
|
||||||
mount_logic+="
|
sshfs -p ${remote_port} -o StrictHostKeyChecking=no,idmap=user ${local_user}@localhost:\"${local_path}\" \"${remote_path}\" 2>/dev/null || \
|
||||||
echo '>> Preparing mount: ${remote_path}';
|
sudo sshfs -p ${remote_port} -o StrictHostKeyChecking=no,idmap=user,allow_other ${local_user}@localhost:\"${local_path}\" \"${remote_path}\"
|
||||||
if ! mkdir -p \"${remote_path}\" 2>/dev/null
|
"
|
||||||
then
|
unmount_logic+="fusermount -u -z \"${remote_path}\" 2>/dev/null || sudo fusermount -u -z \"${remote_path}\" 2>/dev/null;"
|
||||||
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;
|
|
||||||
"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
remote_script="
|
remote_script="
|
||||||
if ! command -v sshfs >/dev/null 2>&1
|
if ! command -v sshfs >/dev/null 2>&1; then
|
||||||
then
|
echo 'WARNING: \"sshfs\" not found on remote host.'
|
||||||
echo 'WARNING: \"sshfs\" not found on remote host.'
|
else
|
||||||
echo '>> Skipping mounts, proceeding with shell only...';
|
${mount_logic}
|
||||||
echo '----------------------------------------------';
|
fi
|
||||||
else
|
\${SHELL:-bash};
|
||||||
${mount_logic}
|
|
||||||
fi
|
|
||||||
|
|
||||||
${SHELL:-bash};
|
|
||||||
|
|
||||||
if command -v sshfs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
${unmount_logic}
|
${unmount_logic}
|
||||||
fi
|
|
||||||
"
|
"
|
||||||
|
|
||||||
ssh -t -R ${remote_port}:localhost:22 "${ssh_args[@]}" "$remote_script"
|
ssh -t -R ${remote_port}:localhost:22 "${ssh_args[@]}" "$remote_script"
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,27 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
DIR="$@"
|
# Lackadaisical squashfs tools - Unmount
|
||||||
|
|
||||||
|
DIR="$1"
|
||||||
|
if [[ -z "$DIR" ]]; then
|
||||||
|
echo "Usage: $0 <directory>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
DIR=$(readlink -f "$DIR")
|
DIR=$(readlink -f "$DIR")
|
||||||
DIR_SHORT=$(basename "$DIR")
|
DIR_SHORT=$(basename "$DIR")
|
||||||
|
|
||||||
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
|
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
|
||||||
OVERLAY_UPPER=${OVERLAY_ROOT}/upper
|
OVERLAY_LOWER="$OVERLAY_ROOT/lower"
|
||||||
OVERLAY_LOWER=${OVERLAY_ROOT}/lower
|
OVERLAY_TARG="$DIR"
|
||||||
OVERLAY_WORK=${OVERLAY_ROOT}/work
|
|
||||||
OVERLAY_TARG=$DIR
|
|
||||||
|
|
||||||
sudo umount -R "$OVERLAY_TARG" 2>/dev/null
|
# Forcefully unmount both layers recursively
|
||||||
sudo umount -R "$OVERLAY_LOWER" 2>/dev/null
|
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."
|
echo "SquashFS filesystem has been unmounted."
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
11
what
11
what
|
|
@ -26,7 +26,10 @@
|
||||||
LD_INTERNAL=1
|
LD_INTERNAL=1
|
||||||
. $(dirname $(realpath $0))/daisy.source
|
. $(dirname $(realpath $0))/daisy.source
|
||||||
|
|
||||||
pwd=/
|
all_bins=$(compgen -c | sort -u)
|
||||||
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")
|
if [[ -n "$1" ]]; then
|
||||||
echo "$output"
|
echo "$all_bins" | grep -i "$1"
|
||||||
|
else
|
||||||
|
echo "$all_bins"
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue