forked from minio/minfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount.minfs
executable file
·101 lines (89 loc) · 2.17 KB
/
mount.minfs
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
#!/bin/sh
#
warn ()
{
echo "$@" >&2
}
_init ()
{
PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PATH
export PATH
prefix="/sbin";
cmd_line=$(echo "/sbin/minfs");
mounttab=/proc/mounts
UPDATEDBCONF="/etc/updatedb.conf"
}
start_minfs ()
{
cmd_line=$(echo "$cmd_line $mount_opts $minio_endpoint $mount_point");
$cmd_line
}
print_usage ()
{
cat << EOF
USAGE: $0 -o<options> <endpoint>/<bucket> <mountpoint>
To display the version number of the mount helper: $0 -V
EOF
}
update_updatedb()
{
# Append MinFS to PRUNEFS variable in updatedb.conf(5).
# updatedb(8) should not index files under MinFS. MinFS
# does its own indexing.
test -f $UPDATEDBCONF && {
if ! grep -q 'fuse.MinFS' $UPDATEDBCONF; then
sed 's/\(PRUNEFS.*\)"/\1 fuse.MinFS"/' $UPDATEDBCONF \
> ${UPDATEDBCONF}.bak
mv -f ${UPDATEDBCONF}.bak $UPDATEDBCONF
fi
}
}
main ()
{
minio_endpoint=$1
mount_point=$2
mount_opts=$3
if [ "x${mount_opts}" = "x-o" ] ; then
mount_opts="$3 $4"
fi
while getopts "Vh" opt; do
case "${opt}" in
V)
${cmd_line} -V;
exit 0;
;;
h)
print_usage;
exit 0;
;;
?)
print_usage;
exit 0;
;;
esac
done
grep_ret=$(echo ${mount_point} | grep '^\-o');
[ "x" != "x${grep_ret}" ] && {
cat <<EOF >&2
-o options cannot be specified in either first two arguments. Please specify correct style.
EOF
exit 1;
}
# No need to do a ! -d test, it is taken care while initializing the
# variable mount_point
[ -z "$mount_point" -o ! -d "$mount_point" ] && {
cat <<EOF >&2
Mount point does not exist, Please specify a valid mount point.
EOF
exit 1;
}
# Simple check to avoid multiple identical mounts
if grep -q "[[:space:]+]${mount_point}[[:space:]+]fuse" $mounttab; then
warn "$0: according to mtab, MinFS is already mounted on" \
"$mount_point"
exit 32;
fi
update_updatedb;
start_minfs;
}
_init "$@" && main "$@";