/
rsshfs
executable file
·44 lines (39 loc) · 1.09 KB
/
rsshfs
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
#!/bin/bash
# Reverse sshfs (GPLv3)
#
# Usage:
# rsshfs <localpath> <remotehost>:<remotepath> [-o ro]
# rsshfs -u <remotehost>:<remotepath>
#
# Romain Vimont (®om) <rom@rom1v.com>
quote() {
[[ $# != 0 ]] && printf '%q ' "$@" | sed 's/.$//'
}
if [[ $# -lt 2 ]]
then
printf "Error: missing parameters\n" >&2
printf "Usage:\n" >&2
printf " $0 <localpath> <remotehost>:<remotepath> [-o ro]\n" >&2
printf " $0 -u <remotehost>:<remotepath>\n" >&2
exit 1;
fi
lpath="$1"
IFS=: read rhost rpath <<< "$2"
qrpath="$(quote "$rpath")"
if [[ "-u" = "$lpath" ]]
then
printf "Unmounting '$rhost:$rpath'...\n"
ssh "$rhost" fusermount -u "$qrpath"
else
qlpath=$(quote "$lpath")
shift 2 # remove the two main pamars to keep the remainder
# warning: the array will be flatten to a string anyway
qall=$(quote "$@")
printf "Mounting '$lpath' on '$rhost:$rpath'...\n"
fifo=/tmp/rsshfs-$$
rm -f "$fifo"
mkfifo -m600 "$fifo" &&
< "$fifo" /usr/lib/openssh/sftp-server |
ssh "$rhost" sshfs -o slave ":$qlpath" "$qrpath" "$qall" > "$fifo"
rm "$fifo"
fi