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:
parent
33ca0e1422
commit
021e4d3b44
3 changed files with 121 additions and 12 deletions
|
|
@ -70,6 +70,15 @@ These are the included binaries and utilities:
|
|||
A simple utility. It's effectively an alias for
|
||||
"sudo chown -R user:user" on the target dir/file.
|
||||
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:
|
||||
This tool allows you to edit the RC file for your
|
||||
shell in your preferred editor. After saving, the
|
||||
|
|
|
|||
|
|
@ -2,24 +2,30 @@
|
|||
# This script is intended to be run via cron.
|
||||
|
||||
# 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.
|
||||
|
||||
# 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
|
||||
. $(dirname $(realpath $0))/daisy.source
|
||||
|
||||
dir_name=ByDate
|
||||
root_dir=$HOME/$dir_name
|
||||
today_sym=$HOME/Today
|
||||
if [[ $1 == '' ]]; then
|
||||
echo "Usage: $LD_BIN <folder>"
|
||||
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
|
||||
today=$(date -I)
|
||||
|
|
@ -49,6 +55,5 @@ test -L "$today_sym" && rm -rf "$today_sym"
|
|||
|
||||
# Now we can set up today's directory
|
||||
mkdir -p "$root_dir/$year/$month/$day"
|
||||
cd $root_dir
|
||||
ln -s "./$dir_name/$year/$month/$day" "$today_sym"
|
||||
ln -s "$root_dir/$year/$month/$day" "$today_sym"
|
||||
exitcode=@?
|
||||
95
sshp
Executable file
95
sshp
Executable 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue