2020-11-13 10:02:20 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# depends on sshfs fuse for ssh
|
2020-12-01 10:47:17 -08:00
|
|
|
module_load filesystem # mounted
|
|
|
|
module_load net-utils # host_reachable
|
2020-11-20 15:53:16 -08:00
|
|
|
|
2020-11-13 10:02:20 -08:00
|
|
|
function smount(){
|
|
|
|
local HOST
|
2021-01-14 13:26:12 -08:00
|
|
|
local PORT
|
2020-11-13 10:02:20 -08:00
|
|
|
HOST=$(sed 's/.*@\(.*\):.*/\1/' <<< "$1")
|
2021-01-14 13:26:12 -08:00
|
|
|
# TODO search for -p and extract port, this 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
|
2020-11-13 10:02:20 -08:00
|
|
|
if [[ $(mounted $2) ]]; then
|
|
|
|
echo "remote $1 already mounted at $2, aborting mount"
|
|
|
|
else
|
2020-11-21 08:59:08 -08:00
|
|
|
echo "mounting via ssh"
|
2020-12-01 10:47:17 -08:00
|
|
|
echo sshfs "$*"
|
2020-11-24 11:17:43 -08:00
|
|
|
mkdir -p $2
|
2020-12-01 10:47:17 -08:00
|
|
|
# can add any options after mount point directory like -o default_permissions
|
|
|
|
sshfs "$@"
|
2020-11-13 10:02:20 -08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function usmount(){
|
2020-11-20 15:53:16 -08:00
|
|
|
if [[ $(mounted $1) ]]; then
|
2020-11-13 10:02:20 -08:00
|
|
|
echo "unmounting remote file system at $1"
|
|
|
|
fusermount -u $1
|
|
|
|
else
|
|
|
|
echo "nothing mounted at $1, aborting unmount"
|
|
|
|
fi
|
|
|
|
}
|