-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_automount
executable file
·109 lines (100 loc) · 2.29 KB
/
_automount
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
# automount - Connecting to a NAS local and remote
# This script mounts a directory via sshfs.
# A user can configure two mount options - a remote and a local one
# This is usefull if connecting to a Network Attached Storage (NAS) from the Internet involves a relay which is not needed if the user is in the same network as the NAS.
# A Config file has to look like this and named automount.conf
# DIRNAME=folder
# HOST_LOCAL=192.168.10.2
# PORT_LOCAL=22
# HOST_REMOTE=relay.remote.net
# PORT_REMOTE=22
# PATH_SERVER="/mnt/folder"
# MNT_PNT="/mnt/folder"
OPTIONS="ServerAliveInterval=5"
# Search for config files
if [ -f "$HOME/.config/automount/automount.conf" ] ; then
source "$HOME/.config/automount/automount.conf"
elif [ -f "$HOME/.config/automount.conf" ] ; then
source "$HOME/.config/automount.conf"
elif [ -f "$HOME/.automount.conf" ] ; then
source "$HOME/.automount.conf"
else
echo "No config file found. Create one first"
exit 1
fi
# Test if folder is mounted
test_mountpoint () {
if [[ "$(ls -l $MNT_PNT | head -n 1 | awk '{print $2}')" == "0" ]]
then
return 1
else
return 0
fi
}
# Mount locally
mount_local () {
sshfs $USERNAME@$HOST_LOCAL:$PATH_SERVER $MNT_PNT -p $PORT_LOCAL -o $OPTIONS
}
# Mount remote
mount_remote () {
sshfs $USERNAME@$HOST_REMOTE:$PATH_SERVER $MNT_PNT -p $PORT_REMOTE -o $OPTIONS
}
case $1 in
"remote")
if test_mountpoint
then
echo "Already mounted"
exit 1
elif mount_remote && test_mountpoint
then
echo "Mounted $DIRNAME remotely"
exit 0
else
echo "Could not mounted $DIRNAME remotely"
exit 1
fi
;;
"local")
if test_mountpoint
then
echo "Already mounted"
exit 1
elif mount_local && test_mountpoint
then
echo "Mounted $DIRNAME locally"
exit 0
else
echo "Could not mounted $DIRNAME locally"
exit 1
fi
;;
"umount")
umount $MNT_PNT
exit 0
;;
"test")
if test_mountpoint
then
echo "Mounted"
else
echo "Not Mounted"
fi
exit 0
;;
"show-config")
echo "USERNAME=$USERNAME"
echo "DIRNAME=$DIRNAME"
echo "HOST_LOCAL=$HOST_LOCAL"
echo "PORT_LOCAL=$PORT_LOCAL"
echo "HOST_REMOTE=$HOST_REMOTE"
echo "PORT_REMOTE=$PORT_REMOTE"
echo "PATH_SERVER=$PATH_SERVER"
echo "MNT_PNT=$MNT_PNT"
exit 0
;;
*)
echo "No valid option given"
exit 1
;;
esac