-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshmount.sh
More file actions
executable file
·137 lines (119 loc) · 3.4 KB
/
sshmount.sh
File metadata and controls
executable file
·137 lines (119 loc) · 3.4 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
135
136
137
#!/bin/bash
# default settings
MOUNT_OPTIONS=
MOUNT_POINT=
MOUNT_PATH=
MOUNT_USER=
MOUNT_PASSWORD=
MOUNT_HOST=
MOUNT_COMMAND=mount
# array to hold arguments without options
ARGV=()
PACKAGE=`basename $0`
# display usage help
function Usage()
{
cat <<-ENDOFMESSAGE
$PACKAGE - mount filesystem over ssh
$PACKAGE [command] [mount point] [mount path] [options]
arguments:
command - the command to execute, mount / m or unmount / u
mount point - the path to the mount point
mount path - the path on the remote server to mount
options:
-h, --help show brief help
-u, --user MOUNT_USER the username for the ssh login
-H, --host MOUNT_HOST the hostname for the ssh login
-p, --password MOUNT_PASSWORD the password for the ssh login
-o, --options MOUNT_OPTIONS the options string to pass to fusermount
NOTE:
This command requires the fuse-sshfs package.
The 'allow_other' option string value will require the /etc/fuse.conf option of 'user_allow_other'.
ENDOFMESSAGE
exit
}
# die with message
function Die()
{
echo "$* Use -h option to display help."
exit 1
}
# process command line arguments into values to use
function ProcessArguments() {
# separate options from arguments
while [ $# -gt 0 ]
do
opt=$1
shift
case ${opt} in
-u|--user)
if [ $# -eq 0 -o "${1:0:1}" = "-" ]; then
Die "The ${opt} option requires an argument."
fi
export MOUNT_USER=$1
shift
;;
-H|--host)
if [ $# -eq 0 -o "${1:0:1}" = "-" ]; then
Die "The ${opt} option requires an argument."
fi
export MOUNT_HOST=$1
shift
;;
-p|--password)
if [ $# -eq 0 -o "${1:0:1}" = "-" ]; then
# read password input
echo -n Password:
read -s password
echo
export MOUNT_PASSWORD=$password
else
export MOUNT_PASSWORD=$1
fi
shift
;;
-o|--options)
if [ $# -eq 0 -o "${1:0:1}" = "-" ]; then
export MOUNT_OPTIONS=""
else
export MOUNT_OPTIONS=$1
fi
shift
;;
-h|--help)
Usage;;
*)
if [ "${opt:0:1}" = "-" ]; then
Die "${opt}: unknown option."
fi
ARGV+=(${opt});;
esac
done
if [ ${#ARGV[@]} -gt 0 ]; then
export MOUNT_COMMAND=${ARGV[0]}
fi
if [ ${#ARGV[@]} -gt 1 ]; then
export MOUNT_POINT=${ARGV[1]}
fi
if [ ${#ARGV[@]} -gt 2 ]; then
export MOUNT_PATH=${ARGV[2]}
fi
}
# process command line arguments
ProcessArguments $*
#process command
case ${MOUNT_COMMAND} in
m|mount)
if [ -z "$MOUNT_OPTIONS" ]; then
echo ${MOUNT_PASSWORD} | sshfs ${MOUNT_USER}@${MOUNT_HOST}:${MOUNT_PATH} ${MOUNT_POINT} -o password_stdin
else
echo ${MOUNT_PASSWORD} | sshfs ${MOUNT_USER}@${MOUNT_HOST}:${MOUNT_PATH} ${MOUNT_POINT} -o password_stdin,${MOUNT_OPTIONS}
fi
;;
u|unmount)
fusermount -u ${MOUNT_POINT}
;;
*)
Die "${MOUNT_COMMAND} is an unknown command."
;;
esac