From 1889a2f978a2faeb37f4a2de19a37a11d2b60dba Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Fri, 8 May 2020 07:46:54 -0700 Subject: [PATCH] openwrt-ctrl: Add download option, and fix sysupgrade. Signed-off-by: Ben Greear --- openwrt_ctl.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/openwrt_ctl.py b/openwrt_ctl.py index 2f00b998..1b59391b 100755 --- a/openwrt_ctl.py +++ b/openwrt_ctl.py @@ -48,8 +48,9 @@ def usage(): print("--prompt Prompt to look for when commands are done (default: root@OpenWrt)") print("-s|--scheme (serial|telnet|ssh): connect via serial, ssh or telnet") print("-l|--log file log messages here") - print("--action (logread | journalctl | lurk | sysupgrade | reboot | cmd") + print("--action (logread | journalctl | lurk | sysupgrade | download | reboot | cmd") print("--value (option to help complete the action") + print("--value2 (option to help complete the action, dest filename for download") print("-h|--help") # see https://stackoverflow.com/a/13306095/11014343 @@ -77,8 +78,9 @@ def main(): parser.add_argument("-t", "--tty", type=str, help="tty serial device") parser.add_argument("-l", "--log", type=str, help="logfile for messages, stdout means output to console") parser.add_argument("--action", type=str, help="perform action", - choices=["logread", "journalctl", "lurk", "sysupgrade", "reboot", "cmd" ]) + choices=["logread", "journalctl", "lurk", "sysupgrade", "download", "reboot", "cmd" ]) parser.add_argument("--value", type=str, help="set value") + parser.add_argument("--value2", type=str, help="set value2") tty = None args = None @@ -131,7 +133,7 @@ def main(): egg.logfile = FileAdapter(logg) egg.sendline(NL) try: - i = egg.expect([prompt, "Please pres Enter to activate", "login:"], timeout=3) + i = egg.expect([prompt, "Please press Enter to activate", "login:"], timeout=3) if (i == 2): egg.sendline(user) egg.expect("Password:") @@ -196,7 +198,7 @@ def main(): egg.expect("__hello__") egg.expect(CCPROMPT) - logg.info("Action[%s] Value[%s] "%(args.action, args.value)) + logg.info("Action[%s] Value[%s] Value2[%s]"%(args.action, args.value, args.value2)) if (args.action == "reboot"): command = "reboot" @@ -227,13 +229,29 @@ def main(): logg.info("Command[%s]"%command) egg.sendline(command); - egg.expect("password:", timeout=5) + i = egg.expect(["password:", "Do you want to continue connecting"], timeout=5) + if i == 1: + egg.sendline("y") + egg.expect("password:", timeout=5) egg.sendline("lanforge") egg.expect(CCPROMPT, timeout=20) egg.sendline("sysupgrade /tmp/new_img.bin") egg.expect("link becomes ready", timeout=100) return + if (args.action == "download"): + command = "scp %s /tmp/%s"%(args.value, args.value2) + logg.info("Command[%s]"%command) + egg.sendline(command); + + i = egg.expect(["password:", "Do you want to continue connecting"], timeout=5) + if i == 1: + egg.sendline("y") + egg.expect("password:", timeout=5) + egg.sendline("lanforge") + egg.expect(CCPROMPT, timeout=20) + return + if (command is None): logg.info("No command specified, going to log out.") else: