Ooooh, Python 3 is upon us.

This commit is contained in:
Rudd-O 2019-06-14 04:04:00 +00:00
parent 39a133301b
commit 473d7cdea6

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/python3 -u
import pipes try:
from pipes import quote
except ImportError:
from shlex import quote
import os import os
import subprocess import subprocess
import sys import sys
@ -28,16 +31,29 @@ else:
] + parms ] + parms
if remotehost: if remotehost:
args = " ".join(pipes.quote(x) for x in parms) args = " ".join(quote(x) for x in parms)
poop = file(path_to_bombshell, "rb").read().encode("hex_codec") with open(path_to_bombshell, "r") as f:
therest_template = ("test -x ./.bombshell-client || " poop = quote(f.read())
"python -c 'import os; file(\"./.bombshell-client\", \"wb\").write(\"%s\".decode(\"hex_codec\")); os.chmod(\"./.bombshell-client\", 0700)' || " therest_template = ('''
"exit 127 ;" set -e
"./.bombshell-client %s %s %s") which bombshell-client >/dev/null 2>&1 && {
therest = therest_template % (poop, exec bombshell-client %s %s %s
} || {
echo %s > .bombshell-client.tmp
chmod +x .bombshell-client.tmp
mv -fT .bombshell-client.tmp .bombshell-client
exec ./.bombshell-client %s %s %s
}
''')
therest = therest_template % (
"-d" if os.getenv("BOMBSHELL_DEBUG") else "", "-d" if os.getenv("BOMBSHELL_DEBUG") else "",
pipes.quote(host), quote(host),
args) args,
poop,
"-d" if os.getenv("BOMBSHELL_DEBUG") else "",
quote(host),
args,
)
cmd = [ cmd = [
'ssh', 'ssh',
'-o', 'BatchMode yes', '-o', 'BatchMode yes',