-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmymount
More file actions
executable file
·134 lines (111 loc) · 2.69 KB
/
Copy pathmymount
File metadata and controls
executable file
·134 lines (111 loc) · 2.69 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
PROJECT=$1
OPTION=$2
cd $(dirname $(readlink -f $0))
declare -A PROFILE
declare -A SAMBA_PROFILE
source <(cat etc/projects.d/*.conf)
PROJECT_MNT_PATH=~/mnt/$PROJECT
function checkMountPoint {
if [ -d "$PROJECT_MNT_PATH" ]; then
mountpoint "$PROJECT_MNT_PATH"
if [ "$?" == "0" ]; then
echo "Project already mounted $PROJECT_MNT_PATH"
exit 3
else
echo "Reconnect..."
fi
fi
}
function prepareMount {
_UID=`id -u`
_GID=`id -g`
mkdir -p $PROJECT_MNT_PATH
}
function showStatus {
echo ===== PROJECTS =====
for i in "${!PROFILE[@]}"; do
echo $i
done
echo
echo ===== SAMBA PROJECTS =====
for i in "${!SAMBA_PROFILE[@]}"; do
echo $i
done
echo
echo ===== MOUNTED =====
mount -t fuse.sshfs
mount -t cifs
echo
}
CONF=`ls etc/projects.d/*.conf > /dev/null 2>&1`
if [ $? -ne "0" ]; then
echo "No projects profiles"
exit 2
fi
if [ -z "$PROJECT" ]; then
showStatus
exit 0
fi
if [ -n "${PROFILE[$PROJECT]}" ]; then
RESP=`which sshfs`
if [ $? -ne "0" ]; then
echo 'No sshfs! Use: sudo apt-get install sshfs'
exit 10
fi
TYPE='sshfs'
SSH_SERVER_STR=${PROFILE[$PROJECT]}
elif [ -n "${SAMBA_PROFILE[$PROJECT]}" ]; then
RESP=`which mount.cifs`
if [ $? -ne "0" ]; then
echo 'No mount.cifs! Use: sudo apt-get install cifs-utils'
exit 10
fi
TYPE='mount.cifs'
SSH_SERVER_STR=${SAMBA_PROFILE[$PROJECT]}
else
echo "No such project profile"
exit 4
fi
if [ "$TYPE" == "sshfs" ]; then
case "$OPTION" in
-u)
fusermount -u -z $PROJECT_MNT_PATH
rmdir $PROJECT_MNT_PATH
exit 0
;;
*)
checkMountPoint
prepareMount
sshfs -o allow_other,reconnect,cache_timeout=5,ServerAliveInterval=15,ServerAliveCountMax=3 "$SSH_SERVER_STR" $PROJECT_MNT_PATH
if [ 0 != "$?" ]; then
echo 'Error'
rmdir $PROJECT_MNT_PATH
exit 5
fi
exit 0
;;
esac
elif [ "$TYPE" == "mount.cifs" ]; then
case "$OPTION" in
-u)
umount $PROJECT_MNT_PATH
rmdir $PROJECT_MNT_PATH
exit 0
;;
*)
checkMountPoint
prepareMount
/sbin/mount.cifs -o allow_other,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,iocharset=utf8 ${SSH_SERVER_STR/VAR_MOUNTPOINT/$PROJECT_MNT_PATH}
if [ 0 != "$?" ]; then
echo 'Error'
rmdir $PROJECT_MNT_PATH
exit 5
fi
exit 0
;;
esac
else
echo "No such type"
exit 6
fi