forked from Tatoeba/imouto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.sh
executable file
·49 lines (43 loc) · 1.13 KB
/
mount.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -e -u
PORT="2222"
HOST="127.0.0.1"
USER="vagrant"
function usage_instructions {
echo "USAGE:"
echo "To mount: $0 -M <HOST-DIR-PATH> <GUEST-DIR-PATH>"
echo "To unmount: $0 -U <HOST-DIR-PATH>"
echo "Note: For mounting both <HOST-DIR-PATH> and <GUEST-DIR-PATH> must exist and <HOST-DIR-PATH> should be empty"
}
function check_sshfs {
command -v sshfs >/dev/null 2>&1 || { echo >&2 "'sshfs' not found! Please install it first!"; exit 1; }
}
check_sshfs
if [ "$#" -eq 2 ] ; then
if [ "$1" != "-U" ] && [ "$1" != "-u" ] ; then
echo "Invalid arguments!"
usage_instructions
exit 1
else
HOST_DIR="$2"
fusermount -u "$HOST_DIR"
echo "Successfully unmounted at $HOST_DIR"
exit 0
fi
elif [ "$#" -eq 3 ] ; then
if [ "$1" != "-M" ] && [ "$1" != "-m" ] ; then
echo "Invalid arguments!"
usage_instructions
exit 1
else
HOST_DIR="$2"
GUEST_DIR="$3"
sshfs -o ssh_command="ssh -p $PORT -i $HOME/.vagrant.d/insecure_private_key" "$USER"@"$HOST":"$GUEST_DIR" "$HOST_DIR"
echo "Successfully mounted $HOST:$PORT's $GUEST_DIR at $HOST_DIR"
exit 0
fi
else
echo "Invalid number of arguments!"
usage_instructions
exit 1
fi