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