Last active
December 11, 2015 06:18
-
-
Save synaptiko/4557863 to your computer and use it in GitHub Desktop.
Simple shell script for un/mounting over SSH. Usage: ./mount-sshf <USER> <SERVER> [kill] It uses xclip command to copy and run command "cd <MOUNTED_DIR>" directly in terminal.
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
#!/bin/sh | |
if [ $# -ge 2 ]; then | |
USER=$1 | |
SERVER=$2 | |
DIR=${MOUNT_SSHFS__ROOT_DIR:-/var/tmp/mount-sshfs}/$SERVER | |
# it's possible to use primary or clip | |
XCLIP_SEL_MODE=${MOUNT_SSHFS__XCLIP_SEL_MODE:-primary} | |
if [ -d $DIR ]; then | |
if [ $# -eq 3 -a "$3" = "kill" ]; then | |
killall -9 sshfs | |
fi | |
fusermount -u $DIR | |
if [ $? -eq 0 ]; then | |
rm -ri $DIR | |
echo "Unmounted from $DIR" | |
else | |
echo "For safety reason directory was not deleted" | |
fi | |
else | |
mkdir -p $DIR | |
sshfs $USER@$SERVER:/ $DIR | |
if [ $? -eq 0 ]; then | |
echo "cd $DIR" | xclip -sel $XCLIP_SEL_MODE | |
echo "Mounted to $DIR" | |
else | |
rm -r $DIR | |
echo "Error: connection to $USER@$SERVER failed" | |
fi | |
fi | |
else | |
echo "Usage: ./mount-sshfs <USER> <SERVER> [kill]" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment