3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/bup-python" || exit $?
13 exec "$bup_python" "$0"
17 from __future__ import absolute_import
18 from subprocess import PIPE
19 import getopt, os, signal, struct, subprocess, sys
21 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
23 from bup import compat, options, ssh, path
24 from bup.compat import argv_bytes
25 from bup.helpers import DemuxConn, log
26 from bup.io import byte_stream
30 bup on <hostname> index ...
31 bup on <hostname> save ...
32 bup on <hostname> split ...
33 bup on <hostname> get ...
35 o = options.Options(optspec, optfunc=getopt.getopt)
36 opt, flags, extra = o.parse(compat.argv[1:])
38 o.fatal('arguments expected')
40 class SigException(Exception):
41 def __init__(self, signum):
43 Exception.__init__(self, 'signal %d received' % signum)
44 def handler(signum, frame):
45 raise SigException(signum)
47 signal.signal(signal.SIGTERM, handler)
48 signal.signal(signal.SIGINT, handler)
51 out = byte_stream(sys.stdout)
58 hp = argv_bytes(extra[0]).split(b':')
60 (hostname, port) = (hp[0], None)
63 argv = [argv_bytes(x) for x in extra[1:]]
64 p = ssh.connect(hostname, port, b'on--server', stderr=PIPE)
67 argvs = b'\0'.join([b'bup'] + argv)
68 p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
70 sp = subprocess.Popen([path.exe(), b'server'],
71 stdin=p.stdout, stdout=p.stdin)
74 # Demultiplex remote client's stderr (back to stdout/stderr).
75 dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "wb"))
76 for line in iter(dmc.readline, b''):
80 # if we get a signal while waiting, we have to keep waiting, just
81 # in case our child doesn't die.
87 except SigException as e:
88 log('\nbup on: %s\n' % e)
89 os.kill(p.pid, e.signum)
91 except SigException as e:
94 log('\nbup on: %s\n' % e)