#!/bin/bash
-##################################################################
-# START_IP_HEADER #
-# #
-# Written by Francois Fleuret #
-# Contact <francois.fleuret@idiap.ch> for comments & bug reports #
-# #
-# END_IP_HEADER #
-##################################################################
+#########################################################################
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the version 3 of the GNU General Public License #
+# as published by the Free Software Foundation. #
+# #
+# This program is distributed in the hope that it will be useful, but #
+# WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+# Written by and Copyright (C) Francois Fleuret #
+# Contact <francois.fleuret@idiap.ch> for comments & bug reports #
+#########################################################################
set -e
hostname=$1
remotepath=$2
+localpath=/mnt/sshfs/${hostname}/${remotepath}
-localpath=/tmp/sshfs/${hostname}/${remotepath}
+if [[ $1 == "--help" ]] || [[ $1 == "-h" ]]; then
+ cat <<EOF
+sshmount.sh [--help|-h|<hostname> [<remote path>]]
-if [[ $(mount | grep ${hostname}:${remotepath}) ]]; then
- fusermount -u ${localpath}
- echo "${localpath} is unmounted."
+Mount the remote path on /mnt/sshfs/<hostname>/<remotepath> if it is
+not already mounted. Umount it otherwise.
+
+If no argument is provided, tries to umount all the mounted sshfs
+volumes.
+EOF
+
+ exit 0
+fi
+
+if [[ $1 ]]; then
+ if [[ $(mount | grep ${hostname}:${remotepath}) ]]; then
+ fusermount -u ${localpath}
+ echo "sshfs umounted from ${localpath}."
+ else
+ mkdir -p ${localpath}
+ sshfs -o idmap=user -C ${hostname}:${remotepath} ${localpath}
+ echo "Remote ${hostname}:${remotepath} mounted on ${localpath}."
+ fi
else
- mkdir -p ${localpath}
- sshfs -o idmap=user -C ${hostname}:${remotepath} ${localpath}
- echo "${localpath} is mounted."
+ for v in $(mount | grep fuse.sshfs | cut -f 3 -d' '); do
+ fusermount -u ${v}
+ echo "sshfs umounted from ${v}"
+ done
fi