Last active
December 10, 2015 02:19
-
-
Save nottsknight/4366797 to your computer and use it in GitHub Desktop.
Short script for UNIX users to automatically connect to a remote file system via the sshfs program. Needs to be configured with the address of the server (line 4), your preferred mount point (line 5), a directory you can guarantee will be present IFF the file system is mounted (line 10), and the path to your home directory on the remote server (…
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 | |
# Script to mount or unmount a remote filesystem via sshfs | |
SERVERNAME="user@host.name" | |
MOUNTPOINT="$HOME/cs-home" | |
if [[ ! -d "$MOUNTPOINT" ]]; then | |
mkdir $MOUNTPOINT | |
fi | |
if [[ -d "$MOUNTPOINT/Private" ]]; then | |
if [[ $PWD =~ /home/ianknight/cs-home.* ]]; then | |
echo "Cannot unmount while still inside cs-home..." | |
exit 1 | |
else | |
fusermount -u $MOUNTPOINT | |
echo "Unmounted $SERVERNAME from $MOUNTPOINT." | |
exit 0 | |
fi | |
else | |
sshfs -o idmap=user "$SERVERNAME:/your/home/dir" "$MOUNTPOINT" | |
echo "Mounted $SERVERNAME at $MOUNTPOINT." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Converted from Python to BASH, since it makes much more sense.