From 074e2d8517af6aa7db24c18062c77cf1820b21d8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Apr 2022 16:05:40 +0200 Subject: [PATCH 1/2] update cp script --- scripts/q7s-cp.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/q7s-cp.py b/scripts/q7s-cp.py index 9bc18201..c9680b0d 100755 --- a/scripts/q7s-cp.py +++ b/scripts/q7s-cp.py @@ -11,16 +11,27 @@ def main(): print(f"Running command: {cmd}") result = os.system(cmd) if result != 0: - print("") - print("Removing problematic SSH key and trying again..") - remove_ssh_key_cmd = ( - 'ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "[localhost]:1535"' - ) - os.system(remove_ssh_key_cmd) + prompt_ssh_key_removal() print(f'Running command "{cmd}"') result = os.system(cmd) +def prompt_ssh_key_removal(): + do_remove_key = input("Do you want to remove problematic keys on localhost ([Y]/n)?: ") + if not do_remove_key.lower() in ["y", "yes", "1", ""]: + sys.exit(1) + port = 0 + while True: + port = input("Enter port to remove: ") + if not port.isdecimal(): + print("Invalid port detected") + else: + break + cmd = f'ssh-keygen -f "$ {{HOME}}/.ssh/known_hosts" -R "[localhost]:{port}"' + print(f"Removing problematic SSH key with command {cmd}..") + os.system(cmd) + + def handle_args(): help_string = ( "This script copies files to the Q7S as long as port forwarding is active.\n" @@ -58,8 +69,7 @@ def handle_args(): ) # Positional argument(s) parser.add_argument( - "source", help="Source files to copy or target files to copy back to host", - nargs="+" + "source", help="Source files to copy or target files to copy back to host" ) return parser.parse_args() @@ -72,10 +82,6 @@ def build_cmd(args): address = "" port_args = "" target = args.target - if args.invert and len(args.source) > 1: - print("Multiple source files not allowed for inverse copying") - sys.exit(1) - source_files = " ".join(args.source) if args.flatsat: address = "eive@flatsat.eive.absatvirt.lw" else: @@ -92,9 +98,9 @@ def build_cmd(args): else: target = args.target if args.invert: - cmd += f"{port_args} {address}:{source_files} {target}" + cmd += f"{port_args} {address}:{args.source} {target}" else: - cmd += f"{port_args} {source_files} {address}:{target}" + cmd += f"{port_args} {args.source} {address}:{target}" return cmd From 10d0bf1550d57b5b5a748c86b7c068ed052edbd2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 2 May 2022 23:51:39 +0200 Subject: [PATCH 2/2] mini fix --- scripts/q7s-cp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/q7s-cp.py b/scripts/q7s-cp.py index c9680b0d..a189e3e6 100755 --- a/scripts/q7s-cp.py +++ b/scripts/q7s-cp.py @@ -27,7 +27,7 @@ def prompt_ssh_key_removal(): print("Invalid port detected") else: break - cmd = f'ssh-keygen -f "$ {{HOME}}/.ssh/known_hosts" -R "[localhost]:{port}"' + cmd = f'ssh-keygen -f "${{HOME}}/.ssh/known_hosts" -R "[localhost]:${port}"' print(f"Removing problematic SSH key with command {cmd}..") os.system(cmd)