| 1 | = SSHFS Mount Script = |
| 2 | |
| 3 | This is a script to mount fules systens via SFTP using Fuse. |
| 4 | |
| 5 | {{{ |
| 6 | #!/bin/bash |
| 7 | |
| 8 | # http://fuse.sourceforge.net/sshfs.html |
| 9 | |
| 10 | # the place file systems are to be mounted |
| 11 | MOUNT_POINT="/media" |
| 12 | if [[ ! -d "$MOUNT_POINT" ]]; then |
| 13 | echo "It looks like $MOUNT_POINT doesn't exist?" |
| 14 | exit |
| 15 | fi |
| 16 | |
| 17 | # check for server to mount on standard input |
| 18 | if [[ $1 ]]; then |
| 19 | SERVER=$1 |
| 20 | elif [[ ! $1 ]]; then |
| 21 | echo "Type the server you want to mount and then [ENTER]:" |
| 22 | read server |
| 23 | SERVER=$server |
| 24 | fi |
| 25 | |
| 26 | # check the server is setup in ~/.ssh/config |
| 27 | SSH_CONFIG=$(grep "Host $SERVER" ~/.ssh/config) |
| 28 | if [[ ! $SSH_CONFIG ]]; then |
| 29 | echo "It looks like you need to edit yur ~/.ssh/config" |
| 30 | echo "to add entries like this for each server:" |
| 31 | echo |
| 32 | echo "Host example" |
| 33 | echo " User root" |
| 34 | echo " Hostname example.org" |
| 35 | echo |
| 36 | exit |
| 37 | fi |
| 38 | |
| 39 | # check if the mount point exists and if not create it |
| 40 | if [[ ! -d "$MOUNT_POINT/$SERVER"]]; then |
| 41 | echo "Creating $MOUNT_POINT/$SERVER" |
| 42 | mkdir "$MOUNT_POINT/$SERVER" |
| 43 | fi |
| 44 | |
| 45 | # check is the file system appears to already be mounted |
| 46 | DF=$(df | awk -F' ' '{ print $6 }' | grep "$MOUNT_POINT/$SERVER") |
| 47 | if [[ $DF ]]; then |
| 48 | echo "It appears that $SERVER is already mounted at $DF?" |
| 49 | exit |
| 50 | fi |
| 51 | |
| 52 | # Mount the file system |
| 53 | sshfs $SERVER:/ $MOUNT_POINT/$SERVER/ |
| 54 | }}} |