Skip to content

Commit

Permalink
vm: fix env. and command escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Sep 4, 2024
1 parent 244b531 commit 5d99c01
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tasks/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,17 @@ def run_command(ctx, name, path, cmd, env=None):
ip_addr = _get_ip(name)
cmd_base = _build_ssh_command(ip_addr)

# Manually re-escape quotation marks for the underlying ssh command
cmd = cmd.replace('"', '\\"')

env_var_str = ""
if env is not None:
env_var_list = [env_var for env_var in env]
env_var_str = " ".join(env_var_list)
for env_var in env_var_list:
env_var_str += f"export {env_var};"

if len(env_var_list) > 0:
env_var_str += " &&"
env_var_str += " "

cmd = "{} \"bash -c '{}cd {} && {}'\"".format(
cmd_base, env_var_str, path, cmd
Expand Down

0 comments on commit 5d99c01

Please sign in to comment.