#!/bin/bash # # mount-ssh # jms1 2016-09-28 # # Use sshfs to mount a server's filesystem on this laptop. # https://osxfuse.github.io/ # * Requires both FUSE and SSHFS # # If this script's name is something other than "mount-ssh", the server name # will be parsed from this script's name. This means you can copy, symlink, or # hard-link the script to a new name, and that copy will mount that server. # # 2017-10-10 jms1 - added `allow_other` option PATH="/usr/bin:/bin:/usr/local/bin:/usr/sbin:/sbin" ######################################## # Figure out which server we're mounting, # and where the mount point should be. SERVER="${1:-}" if [[ "$SERVER" == "" ]] then MYNAME="${0##*/}" if [[ $MYNAME != "mount-ssh" ]] then if [[ "$MYNAME" != "${MYNAME##*mount-}" ]] then SERVER="${MYNAME##*mount-}" fi fi fi if [[ -z "$SERVER" ]] then echo "ERROR: no server name specified" exit 1 fi MPOINT="$HOME/mnt/$SERVER" ######################################## # Make sure the mount point exists mkdir -p $MPOINT if [[ ! -d $MPOINT ]] then echo "ERROR: unable to create $MPOINT" exit 1 fi ######################################## # Make sure it's not already mounted if mount | grep -q " on $MPOINT " then echo "INFO: $MPOINT is already mounted" exit 0 fi ######################################## # If an icon exists for this server, use it if [[ -f "$HOME/mnt/$SERVER.icns" ]] then ICON="-o volicon=$HOME/mnt/$SERVER.icns" else ICON="" fi ######################################## # Do the deed sshfs "${SERVER}:/" "$MPOINT" $ICON \ -o 'allow_other' \ -o 'reconnect' \ -o 'ServerAliveInterval=30' \ -o 'noappledouble' \ -o "volname=$SERVER"