blob: d71ebad5ddb36baf23159f54158d31d83621508e [file] [log] [blame]
S.Çağlar Onura95895d2015-02-09 13:34:11 -05001#! /usr/bin/env python
Scott Bakerff0af582014-09-26 12:13:21 -07002
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 Baker92fa1042014-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 Bakerff0af582014-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"""