blob: a1f53d36046e15addc57dbeaa1d935140fe97bdb [file] [log] [blame]
Scott Baker4646bf62014-09-26 12:23:27 -07001#! /usr/bin/python
2
3import base64
4import os
5import sys
6import subprocess
7import StringIO
8
9if len(sys.argv)<3:
10 print >> sys.stderr, "syntax: diff-opencloud <localfn> <remotehost:remotefn>"
11 sys.exit(-1)
12
13srcfn = sys.argv[1]
14dest = sys.argv[2]
15
16if not ":" in dest:
17 print >> sys.stderr, "malformed desthost:destfn"
18 sys.exit(-1)
19
20(hostname,destfn) = dest.split(":",1)
21
22if destfn.endswith("/"):
23 destfn = destfn + os.path.basename(srcfn)
24
25script = 'echo START; base64 %s' % destfn
26
27file("/tmp/script","w").write(script)
28
29p = subprocess.Popen(["ssh", "-A", hostname], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
30enctext = p.communicate(input=script)[0]
31
32enctext = enctext.split("START")[1]
33
34text = base64.b64decode(enctext)
35
36file("/tmp/diff-src","w").write(text)
37os.system("diff /tmp/diff-src %s" % srcfn)
38
39"""
40SRCPATHNAME=$1
41DESTHOSTNAME=$2
42DESTPATHNAME=$3
43echo "base64 -d -i > $DESTPATHNAME <<EOF" > /tmp/ssh-up
44base64 $SRCPATHNAME >> /tmp/ssh-up
45echo "EOF" >> /tmp/ssh-up
46ssh -A $DESTHOSTNAME < /tmp/ssh-up
47"""