|
5 | 5 | from paramiko.rsakey import RSAKey
|
6 | 6 | from paramiko.ssh_exception import AuthenticationException
|
7 | 7 | from io import StringIO
|
| 8 | +import base64 |
8 | 9 | import time
|
9 | 10 | import re
|
10 | 11 |
|
@@ -132,7 +133,7 @@ def _get_channel(self):
|
132 | 133 |
|
133 | 134 | counter = 0
|
134 | 135 | self.channel = self.client.invoke_shell()
|
135 |
| - command = 'export PS1= && stty -echo; unsetopt zle\n' |
| 136 | + command = 'export PS1= && stty -echo; unsetopt zle; set -e\n' |
136 | 137 | if self.default_env:
|
137 | 138 | command += f'{self.default_env}\n'
|
138 | 139 | command += f'echo {self.eof} $?\n'
|
@@ -176,10 +177,17 @@ def _make_env_command(self, environment):
|
176 | 177 | return f'export {str_envs}'
|
177 | 178 |
|
178 | 179 | def _handle_command(self, command, environment):
|
179 |
| - commands = command.strip().splitlines() |
180 |
| - commands.insert(0, self._make_env_command(environment)) |
181 |
| - commands.append(f'echo {self.eof} $?\n') |
182 |
| - return ';'.join(x for x in commands if x).encode() |
| 180 | + new_command = f'trap \'echo {self.eof} $?; rm -f $SPUG_EXEC_FILE\' EXIT\n' |
| 181 | + env_command = self._make_env_command(environment) |
| 182 | + if env_command: |
| 183 | + new_command += f'{env_command}\n' |
| 184 | + new_command += command |
| 185 | + b64_command = base64.standard_b64encode(new_command.encode()) |
| 186 | + |
| 187 | + commands = 'export SPUG_EXEC_FILE=$(mktemp)\n' |
| 188 | + commands += f'echo {b64_command.decode()} | base64 -d > $SPUG_EXEC_FILE\n' |
| 189 | + commands += 'bash $SPUG_EXEC_FILE\n' |
| 190 | + return commands |
183 | 191 |
|
184 | 192 | def __enter__(self):
|
185 | 193 | self.get_client()
|
|
0 commit comments