blob: 205ea2dbe8ac2abe27e7fd8023f6804e60b88356 [file] [log] [blame]
Scott Baker5f6ec0c2014-09-26 12:13:21 -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: copy-opencloud <srcfn> <desthost:destfn>"
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
25enctext = base64.b64encode(open(srcfn).read())
Scott Baker4646bf62014-09-26 12:23:27 -070026#script = 'sudo bash -C "base64 -d -i > %s <<EOF\n%s\nEOF\n"' % (destfn, enctext)
27script = 'base64 -d -i > %s <<EOF\n%s\nEOF\n' % (destfn, enctext)
28
Scott Baker5f6ec0c2014-09-26 12:13:21 -070029
30file("/tmp/script","w").write(script)
31
32p = subprocess.Popen(["ssh", "-A", hostname], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
33print p.communicate(input=script)[0]
34
35
36"""
37SRCPATHNAME=$1
38DESTHOSTNAME=$2
39DESTPATHNAME=$3
40echo "base64 -d -i > $DESTPATHNAME <<EOF" > /tmp/ssh-up
41base64 $SRCPATHNAME >> /tmp/ssh-up
42echo "EOF" >> /tmp/ssh-up
43ssh -A $DESTHOSTNAME < /tmp/ssh-up
44"""