-
Notifications
You must be signed in to change notification settings - Fork 1
/
mount.sh
160 lines (133 loc) · 3.5 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# mntftp - Simple FTP Mount tool for Linux
# Copyright (C) 2020 Dovi Cowan - dovi@fullynetworking.co.uk
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 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 <https://www.gnu.org/licenses/>.
echo "mntftp - Simple FTP Mount tool for Linux"
echo
echo "Copyright (C) 2020 Dovi Cowan - dovi@fullynetworking.co.uk"
echo "This program comes with ABSOLUTELY NO WARRANTY; for details see the GNU GPL v3.0."
echo "This is free software, and you are welcome to redistribute it"
echo "under certain conditions; see the GNU GPL v3.0."
echo
echo "FTP MOUNTER v1"
echo
MOUNTS_FILE=~/.local/share/mntftp/mount.txt
if [ "$1" = "" ]
then
echo "Error - You must enter an option"
echo "Use option 'help' for help"
exit 1
fi
case "$1" in
mount|m)
if [ "$2" = "" ]
then
echo "Error - you did not enter a mount option"
echo "Use option 'help' for help"
exit 1
fi
if [ "$3" != "" ]
then
MOUNTS_FILE="$3"
fi
IN=`cat $MOUNTS_FILE`
LINES=(${IN//$'\n'/ })
for i in "${LINES[@]}"; do
if [ "${i:0:1}" != "#" ]; then
IFS=':' read -ra ADDR <<< "$i"
#echo ${ADDR[0]}
if [ "${ADDR[3]}" = "$2" ]
then
if [ -d ~/mnt/${ADDR[3]} ]
then
echo "Mountpoint exists. Mounting ..."
else
echo "Mountpoint doesn't exist. Creating mountpoint ..."
mkdir ~/mnt/${ADDR[3]}
echo "Created mountpoint. Mounting ..."
fi
if [ "$(ls -A ~/mnt/${ADDR[3]})" ];
then
echo "Mountpoint in use!"
echo "Ensure the mountpoint is empty before mounting"
exit 1
fi
curlftpfs -o user="${ADDR[0]}:${ADDR[1]}" ${ADDR[2]} ~/mnt/${ADDR[3]}
echo "Mounted"
#echo "$2"
exit 0
fi
fi
done
echo "Invalid mountname!"
;;
umount|u)
if [ "$2" = "" ]
then
echo "Error - you did not enter a mount option"
echo "Use option 'help' for help"
exit 1
fi
if [ "$3" != "" ]
then
MOUNTS_FILE="$3"
fi
IN=`cat $MOUNTS_FILE`
LINES=(${IN//$'\n'/ })
for i in "${LINES[@]}"; do
IFS=':' read -ra ADDR <<< "$i"
#echo ${ADDR[0]}
if [ "${ADDR[3]}" = "$2" ]
then
if [ "$(ls -A ~/mnt/${ADDR[3]})" ];
then
echo
else
echo "Not mounted!"
exit 0
fi
sudo umount ~/mnt/${ADDR[3]}
echo "Unmounted"
exit 0
fi
done
echo "Invalid mountname!"
;;
list|l)
if [ "$2" != "" ]
then
MOUNTS_FILE="$2"
fi
cat $MOUNTS_FILE
exit 0
;;
edit|e)
sudo nano $MOUNTS_FILE
exit 0
;;
help|h)
echo "FTP MOUNTER uses curlftpfs to mount FTP drives to a local folder."
echo "FTP MOUNTER reads mount information from mount.txt by default. Use custom_mounts_file to use a custom mounts file, as detailed below."
echo
echo "USAGE:"
echo "mntftp [mount|umount|add|remove|edit] mountname (custom_mounts_file)"
echo "mntftp list (custom_mounts_file)"
echo
echo "FTP MOUNTER v1 by Dovi Cowan - Fully Networking UK - dovi@fullynetworking.co.uk"
exit 0
;;
*)
echo "Option not valid!"
echo "Use 'help' option for valid options"
;;
esac
exit 1