Last active
October 27, 2018 22:26
-
-
Save Birch-san/9c8f971e7c5a2b997ca93ffd5c00765e to your computer and use it in GitHub Desktop.
How to use OSXFUSE + SSHFS to mount/unmount a remote filesystem
This file contains hidden or 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
#!/bin/sh | |
# mounts a host named 'mycoolhost' (as described in SSH config): | |
# ./sshfs_mount.sh | |
# unmount: | |
# ./sshfs_mount.sh 0 | |
REMOTE_HOST='mycoolhost' | |
REMOTE_DIR='/home/mycooluser' | |
VOLNAME="$REMOTE_HOST" | |
LOCAL_DIR="$HOME/mnt/$VOLNAME" | |
BIND="$REMOTE_HOST:$REMOTE_DIR" | |
mkdir -p "$LOCAL_DIR" | |
if [ "$1" == "0" ]; then | |
echo "unmounting '$VOLNAME'..." | |
umount "$BIND" | |
else | |
if mount | grep -q "^$BIND"; then | |
echo "'$VOLNAME' already mounted:" | |
mount | grep "^$BIND" | |
else | |
echo "mounting '$VOLNAME'..." | |
/usr/local/bin/sshfs "$BIND" "$LOCAL_DIR" -ovolname="$VOLNAME" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment