#!/usr/bin/env python import pipes import os import subprocess import sys argv = list(sys.argv[1:]) if argv[0].startswith("--proxy="): remotehost = argv[0][8:] argv = argv[1:] else: remotehost = None host, parms = argv[0], argv[1:] path_to_bombshell = os.path.join(os.path.dirname(__file__), "bombshell-client") if os.getenv("BOMBSHELL_DEBUG"): cmd = [ path_to_bombshell, "-d", host, ] + parms else: cmd = [ path_to_bombshell, host, ] + parms if remotehost: args = " ".join(pipes.quote(x) for x in parms) poop = file(path_to_bombshell, "rb").read().encode("hex_codec") therest_template = ("test -x ./.bombshell-client || " "python -c 'import os; file(\"./.bombshell-client\", \"wb\").write(\"%s\".decode(\"hex_codec\")); os.chmod(\"./.bombshell-client\", 0700)' || " "exit 127 ;" "export BOMBSHELL_DEBUG=%s ;" "./.bombshell-client %s %s") therest = therest_template % (poop, pipes.quote(os.getenv("BOMBSHELL_DEBUG")), pipes.quote(host), args) cmd = [ 'ssh', '-o', 'BatchMode yes', remotehost, therest, ] os.execvp(cmd[0], cmd)