This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues/pull-requests.
bash-shell-network/all/modules/sshfs.sh

47 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# depends on sshfs fuse for ssh
module_load filesystem # mounted
module_load net-utils # host_reachable
module_load ssh
function smount() {
local HOST
local PORT
local config
HOST=$(sed 's/.*@\(.*\):.*/\1/' <<<"$1")
# TODO sed search for -p and extract port, below assumes 3 and 4 position
PORT=$([[ $3 = "-p" ]] && echo $4 || echo 22)
[[ ! $(host_reachable $HOST $PORT) ]] && echo host $HOST not reachable, aborting mount && return 1
if [[ $(mounted $2) ]]; then
echo "aborting mount: $1 already mounted at $2"
else
echo "SSHFS: mounting $1 at $2"
mkdir -p $2
# can add any options after mount point directory like -o default_permissions
if [[ $SSH_CONFIG ]]; then
[[ ! -f "$SSH_CONFIG" ]] && ssh_config "$SSH_CONFIG"
config=$([[ -f $SSH_CONFIG ]] && echo "-F $SSH_CONFIG")
fi
# echo sshfs "$*" "$config"
sshfs $* $config
fi
}
function usmount() {
if [[ $(mounted $1) ]]; then
echo "unmounting remote file system at $1"
fusermount -u $1
else
echo "nothing mounted at $1, aborting unmount"
fi
}
function mntBackup() {
smount root@$1:/backup /backup/remote -p 22 -o allow_other
}
function umntBackup() {
usmount /backup/remote
}