Skip to content

Commit c90ca0a

Browse files
committed
fix issue
1 parent f1c6d0d commit c90ca0a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

spug_api/libs/ssh.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from paramiko.rsakey import RSAKey
66
from paramiko.ssh_exception import AuthenticationException
77
from io import StringIO
8+
import base64
89
import time
910
import re
1011

@@ -132,7 +133,7 @@ def _get_channel(self):
132133

133134
counter = 0
134135
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'
136137
if self.default_env:
137138
command += f'{self.default_env}\n'
138139
command += f'echo {self.eof} $?\n'
@@ -176,10 +177,17 @@ def _make_env_command(self, environment):
176177
return f'export {str_envs}'
177178

178179
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
183191

184192
def __enter__(self):
185193
self.get_client()

0 commit comments

Comments
 (0)