Generalized newday into agenda and added more capabilities.

Added `sshp`, a wrapper for ssh that also allows SSHFS mounts during connection.
This commit is contained in:
Sam Hardeman 2026-01-09 06:35:22 +01:00
parent 33ca0e1422
commit 021e4d3b44
3 changed files with 121 additions and 12 deletions

View file

@ -70,6 +70,15 @@ These are the included binaries and utilities:
A simple utility. It's effectively an alias for A simple utility. It's effectively an alias for
"sudo chown -R user:user" on the target dir/file. "sudo chown -R user:user" on the target dir/file.
Root permissions required! Root permissions required!
- sshp:
This is a wrapper for `ssh`, the meaning of the 'p' is "Plus".
Integrates SSHFS support. If both client and host have SSHFS,
this wrapper can be used to connect their file systems.
For example, if you need to move files from one machine to
another, you could do something like this:
"sshp -m /:/mnt/pc -m /home/claire:/home/claire claire@pyon.net"
If privilege escalation is necessary for FS access, you will
be asked for a password.
- shrc: - shrc:
This tool allows you to edit the RC file for your This tool allows you to edit the RC file for your
shell in your preferred editor. After saving, the shell in your preferred editor. After saving, the

View file

@ -2,24 +2,30 @@
# This script is intended to be run via cron. # This script is intended to be run via cron.
# It creates a folder structure in home for the current date in the following format: # It creates a folder structure in home for the current date in the following format:
# $HOME/ByDate/<Year>/<Month>/<Day> # $HOME/<Tag>/<Year>/<Month>/<Day>
# It also sets up a symlink in home: $HOME/Today # It also sets up a symlink for the tagged folder.
# This symlink will always point to the folder for the current date. # This symlink will always point to the folder for the current date.
# Finally, it removes any folders without data, to prevent clutter. # Finally, it removes any folders without data, to prevent clutter.
# - Why did you make this?
# I remember things better when they have a date attached to them.
# You can use this for a primitive form of note-taking, but aside from notes -
# you can store any data this way.
LD_INTERNAL=1 LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source . $(dirname $(realpath $0))/daisy.source
dir_name=ByDate if [[ $1 == '' ]]; then
root_dir=$HOME/$dir_name echo "Usage: $LD_BIN <folder>"
today_sym=$HOME/Today echo "Creates a folder within '.daisy' in the current directory containing"
echo "a tree of dates associated with the folder name given by argument."
echo "A symlink is (re-)created at the same time with the same folder name."
echo "For example, if given the folder 'notes', this utility will:"
echo "- Create a folder '/.daisy/notes/<year>/<month>/<day>'."
echo "- Create a symlink named 'notes' that points to it."
echo "It is recommended to run this via cron."
exit 1
fi
root_dir=$(dirname $1)/.daisy/$(basename $1)
today_sym=$1
# Present day # Present day
today=$(date -I) today=$(date -I)
@ -49,6 +55,5 @@ 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"
cd $root_dir ln -s "$root_dir/$year/$month/$day" "$today_sym"
ln -s "./$dir_name/$year/$month/$day" "$today_sym"
exitcode=@? exitcode=@?

95
sshp Executable file
View file

@ -0,0 +1,95 @@
#!/bin/bash
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 <local>:<remote> [user@]host [ssh_options]"
echo "Example: sshp -m /home/juli:/home/juli juli@juli.pyon"
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
done
if [[ ${#ssh_args[@]} -eq 0 ]]
then
usage
fi
mount_logic=""
unmount_logic=""
for map in "${mounts[@]}"; do
local_path="${map%%:*}"
remote_path="${map##*:}"
if [[ "$local_path" != /* ]]
then
local_path="$PWD/$local_path"
fi
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;
"
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
${unmount_logic}
fi
"
ssh -t -R ${remote_port}:localhost:22 "${ssh_args[@]}" "$remote_script"