Last active
July 1, 2024 06:40
-
-
Save TheBunnyMan123/bddf298020e55fdfb32726c37af2129b to your computer and use it in GitHub Desktop.
Script that automatically mounts an SFTP remote and prints the directory to STDOUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
mkdir -p "$HOME/.remote-mount" | |
if mountpoint -q "$HOME/.remote-mount" | |
then | |
umount "$HOME/.remote-mount" | |
fi | |
if [ ! -z "$(ls -A "$HOME/.remote-mount")" ] | |
then | |
echo "Directory not empty and not an existing mount" 1>&2 | |
exit 128 | |
fi | |
if [ -z $1 ] | |
then | |
echo "Didn't specify a remote (first argument, port is second argument (and optional)" 1>&2 | |
exit 128 | |
fi | |
if [ ! -z $2 ] | |
then | |
sshfs "$1:/" "$HOME/.remote-mount" -p $2 | |
else | |
sshfs "$1:/" "$HOME/.remote-mount" | |
fi | |
echo "running remote again will unmount the previous mount. to unmount run 'unmount ~/.remote-mount'" 1>&2 | |
echo "$HOME/.remote-mount" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment