3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import
9 import sys, os, struct, getopt, subprocess, signal
11 from subprocess import PIPE
12 from bup import options, ssh, path
13 from bup.helpers import DemuxConn, log
17 bup on <hostname> index ...
18 bup on <hostname> save ...
19 bup on <hostname> split ...
21 o = options.Options(optspec, optfunc=getopt.getopt)
22 (opt, flags, extra) = o.parse(sys.argv[1:])
24 o.fatal('arguments expected')
26 class SigException(Exception):
27 def __init__(self, signum):
29 Exception.__init__(self, 'signal %d received' % signum)
30 def handler(signum, frame):
31 raise SigException(signum)
33 signal.signal(signal.SIGTERM, handler)
34 signal.signal(signal.SIGINT, handler)
41 hp = extra[0].split(':')
43 (hostname, port) = (hp[0], None)
47 p = ssh.connect(hostname, port, 'on--server', stderr=PIPE)
50 argvs = '\0'.join(['bup'] + argv)
51 p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
53 sp = subprocess.Popen([path.exe(), 'server'],
54 stdin=p.stdout, stdout=p.stdin)
57 # Demultiplex remote client's stderr (back to stdout/stderr).
58 dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "w"))
59 for line in iter(dmc.readline, ""):
60 sys.stdout.write(line)
63 # if we get a signal while waiting, we have to keep waiting, just
64 # in case our child doesn't die.
70 except SigException as e:
71 log('\nbup on: %s\n' % e)
72 os.kill(p.pid, e.signum)
74 except SigException as e:
77 log('\nbup on: %s\n' % e)