-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshproxy_syncfile
More file actions
executable file
·62 lines (49 loc) · 1.14 KB
/
sshproxy_syncfile
File metadata and controls
executable file
·62 lines (49 loc) · 1.14 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
#!/bin/bash
for d in $SSHPROXY_CONF $HOME/.ssh /etc/ssh; do
CNF="$d/proxy/syncfile.conf"
if [ -n "$d" -a -f "$CNF" ]; then
. "$CNF"
break
fi
done
if [ -z "${gateway}" ]; then
echo "incomplete configuration"
exit 1
fi
declare LOCALFILE REMOTEFILE
if [ -n "$1" ]; then
LOCALFILE="$1"
else
LOCALFILE="${localfile:-~/.ssh/authorized_keys2}"
fi
if [ -n "$2" ]; then
REMOTEFILE="$2"
else
REMOTEFILE="${remotefile:-${LOCALFILE}}"
fi
if [ "${LOCALFILE:0:2}" == "~/" ]; then
LOCALFILE="${HOME}/${LOCALFILE:2}"
fi
if [ "${REMOTEFILE:0:2}" == "~/" ]; then
REMOTEFILE="${REMOTEFILE:2}"
fi
if [ "${REMOTEFILE:0:$[${#HOME}+1]}" == "${HOME}/" ]; then
REMOTEFILE="${REMOTEFILE:$[${#HOME}+1]}"
fi
if [ ! -f "${LOCALFILE}" ]; then
echo "File '${LOCALFILE}' not found!"
exit 1
fi
SHATOOL=sha256sum
SHAFILE="${LOCALFILE}.sum"
SHASUM=$(which ${SHATOOL})
if [ -z "${SHASUM}" -o \! -e "${SHASUM}" ]; then
echo "${SHATOOL} not found"
exit 1
fi
if [ -f "${SHAFILE}" ] && ${SHASUM} --check --quiet "${SHAFILE}"; then
exit 0
fi
set -e
echo "put \"${LOCALFILE}\" \"${REMOTEFILE}\"" | sftp "${user:-$(id -un)}@${gateway}"
${SHASUM} "${LOCALFILE}" > "${SHAFILE}"