S.Çağlar Onur | a95895d | 2015-02-09 13:34:11 -0500 | [diff] [blame^] | 1 | #! /usr/bin/env python |
Scott Baker | ff0af58 | 2014-09-26 12:13:21 -0700 | [diff] [blame] | 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: copy-opencloud <srcfn> <desthost:destfn>" |
| 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 | enctext = base64.b64encode(open(srcfn).read()) |
Scott Baker | 92fa104 | 2014-09-26 12:23:27 -0700 | [diff] [blame] | 26 | #script = 'sudo bash -C "base64 -d -i > %s <<EOF\n%s\nEOF\n"' % (destfn, enctext) |
| 27 | script = 'base64 -d -i > %s <<EOF\n%s\nEOF\n' % (destfn, enctext) |
| 28 | |
Scott Baker | ff0af58 | 2014-09-26 12:13:21 -0700 | [diff] [blame] | 29 | |
| 30 | file("/tmp/script","w").write(script) |
| 31 | |
| 32 | p = subprocess.Popen(["ssh", "-A", hostname], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 33 | print p.communicate(input=script)[0] |
| 34 | |
| 35 | |
| 36 | """ |
| 37 | SRCPATHNAME=$1 |
| 38 | DESTHOSTNAME=$2 |
| 39 | DESTPATHNAME=$3 |
| 40 | echo "base64 -d -i > $DESTPATHNAME <<EOF" > /tmp/ssh-up |
| 41 | base64 $SRCPATHNAME >> /tmp/ssh-up |
| 42 | echo "EOF" >> /tmp/ssh-up |
| 43 | ssh -A $DESTHOSTNAME < /tmp/ssh-up |
| 44 | """ |