Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Sep 23, 2021
1 parent f1c6d0d commit c90ca0a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions spug_api/libs/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from paramiko.rsakey import RSAKey
from paramiko.ssh_exception import AuthenticationException
from io import StringIO
import base64
import time
import re

Expand Down Expand Up @@ -132,7 +133,7 @@ def _get_channel(self):

counter = 0
self.channel = self.client.invoke_shell()
command = 'export PS1= && stty -echo; unsetopt zle\n'
command = 'export PS1= && stty -echo; unsetopt zle; set -e\n'
if self.default_env:
command += f'{self.default_env}\n'
command += f'echo {self.eof} $?\n'
Expand Down Expand Up @@ -176,10 +177,17 @@ def _make_env_command(self, environment):
return f'export {str_envs}'

def _handle_command(self, command, environment):
commands = command.strip().splitlines()
commands.insert(0, self._make_env_command(environment))
commands.append(f'echo {self.eof} $?\n')
return ';'.join(x for x in commands if x).encode()
new_command = f'trap \'echo {self.eof} $?; rm -f $SPUG_EXEC_FILE\' EXIT\n'
env_command = self._make_env_command(environment)
if env_command:
new_command += f'{env_command}\n'
new_command += command
b64_command = base64.standard_b64encode(new_command.encode())

commands = 'export SPUG_EXEC_FILE=$(mktemp)\n'
commands += f'echo {b64_command.decode()} | base64 -d > $SPUG_EXEC_FILE\n'
commands += 'bash $SPUG_EXEC_FILE\n'
return commands

def __enter__(self):
self.get_client()
Expand Down

0 comments on commit c90ca0a

Please sign in to comment.