-
Notifications
You must be signed in to change notification settings - Fork 0
/
,,
executable file
·90 lines (78 loc) · 2.17 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
#!/bin/sh
# check if is sourced
if [ "$0" = "," ]; then
echo 'remote-exec: You should not source ,,' >&2
return
fi
set -e
if [ ! -t 0 ] || [ ! -t 1 ] || [ ! -t 2 ]; then
echo 'remote-exec: WHAT ARE YOU DOING??? YOU SHOULD NEVER REDIRECT , OR ,, !!!' >&2
exit 114
fi
REL=""
WD="$PWD"
while true; do
OWD="$PWD"
if [ -f .rmt-config ]; then
. "$PWD/.rmt-config"
break
else
REL="$(basename "$OWD")/$REL"
cd ..
if [ "$PWD" = "$OWD" ]; then
echo 'remote-exec: .rmt-config not found' >&2
exit 3
fi
fi
done
OWD="$(realpath "$OWD")"
set +e
if [ -z "$RMT_LOCALHOST" ]; then
echo 'remote-exec: WHAT ARE YOU DOING??? YOU SHOULD USE , INSTEAD OF ,, !!!' >&2
exit 114
fi
set -e
cd "$WD"
if [ -z "$RMT_HOST" ]; then
echo 'remote-exec: RMT_HOST not found' >&2
exit 2
fi
if [ -z "$RMT_SSH" ]; then
RMT_SSH="ssh -Y -t"
fi
if [ -z "$RMT_SSHFS" ]; then
RMT_SSHFS="sshfs"
fi
if [ -z "$RMT_RDIR" ]; then
RMT_RDIR=".rmt"
fi
# check if already mounted
RDH="$(printf '%s' "$OWD" | sha1sum | cut -d ' ' -f 1)"
RD="$RMT_RDIR/$RDH"
if ssh "$RMT_HOST" mount | grep -qF "/$RDH type fuse.sshfs"; then
if [ "$#" -eq 1 ] && [ "$1" = "," ]; then
echo "remote-exec: Unmounting remote dir $RD" >&2
ssh "$RMT_HOST" umount "$RD"
ssh "$RMT_HOST" rmdir "$RD"
echo "remote-exec: Unmount succeed" >&2
exit 0
fi
else
if [ "$#" -eq 1 ] && [ "$1" = "," ]; then
echo "remote-exec: WARNING: $OWD is already unmounted" >&2
exit 4
fi
echo "remote-exec: Creating remote dir $RD" >&2
ssh "$RMT_HOST" mkdir -p "$RD"
echo "remote-exec: Mount $OWD to remote dir by reversed sshfs" >&2
ssh "$RMT_HOST" $RMT_SSHFS "$RMT_LOCALHOST:$OWD" "$RD"
fi
CMD="/usr/bin/env -C $(/usr/bin/printf '%q' "$RD/$REL") $RMT_RENV"
if [ "$#" -eq 0 ]; then
RMT_RSHELL="$(ssh "$RMT_HOST" echo '$SHELL')"
CMD="$CMD $(/usr/bin/printf '%q' "$RMT_RSHELL")"
else
CMD="$CMD$(/usr/bin/printf ' %q' "$@")"
fi
echo "remote-exec: $RMT_SSH -Y $RMT_HOST /bin/sh -c $(/usr/bin/printf '%q' "$CMD")" >&2
exec $RMT_SSH "$RMT_HOST" /bin/sh -c "$(/usr/bin/printf '%q' "$CMD")"