Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 1 | # This file is run by shell scripts generated by the aos_downloader Skylark |
| 2 | # macro. Everything before the first -- is a hard-coded list of files to |
| 3 | # download. |
| 4 | |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 5 | from __future__ import print_function |
| 6 | |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 7 | import sys |
| 8 | import subprocess |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 9 | import re |
| 10 | import os |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 11 | |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 12 | |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame] | 13 | def install(ssh_target, pkg): |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 14 | """Installs a package from NI on the ssh target.""" |
| 15 | print("Installing", pkg) |
| 16 | PKG_URL = "http://download.ni.com/ni-linux-rt/feeds/2015/arm/ipk/cortexa9-vfpv3/" + pkg |
| 17 | subprocess.check_call(["wget", PKG_URL, "-O", pkg]) |
| 18 | try: |
| 19 | subprocess.check_call([ |
| 20 | "external/ssh/usr/bin/scp", "-S", "external/ssh/usr/bin/ssh", pkg, |
| 21 | ssh_target + ":/tmp/" + pkg |
| 22 | ]) |
| 23 | subprocess.check_call([ |
| 24 | "external/ssh/usr/bin/ssh", ssh_target, "opkg", "install", |
| 25 | "/tmp/" + pkg |
| 26 | ]) |
| 27 | subprocess.check_call( |
| 28 | ["external/ssh/usr/bin/ssh", ssh_target, "rm", "/tmp/" + pkg]) |
| 29 | finally: |
| 30 | subprocess.check_call(["rm", pkg]) |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame] | 31 | |
| 32 | |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 33 | def main(argv): |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 34 | args = argv[argv.index("--") + 1:] |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 35 | |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 36 | relative_dir = "" |
| 37 | recursive = False |
Comran Morshed | 3896733 | 2016-04-23 19:26:48 -0700 | [diff] [blame] | 38 | |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 39 | if "--dirs" in argv: |
| 40 | dirs_index = argv.index("--dirs") |
| 41 | srcs = argv[1:dirs_index] |
| 42 | relative_dir = argv[dirs_index + 1] |
| 43 | recursive = True |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame] | 44 | else: |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 45 | srcs = argv[1:argv.index("--")] |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame] | 46 | |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 47 | ROBORIO_TARGET_DIR = "/home/admin/robot_code" |
| 48 | ROBORIO_USER = "admin" |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 49 | |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 50 | target_dir = ROBORIO_TARGET_DIR |
| 51 | user = ROBORIO_USER |
| 52 | destination = args[-1] |
| 53 | |
| 54 | result = re.match("(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?", destination) |
| 55 | if not result: |
| 56 | print( |
| 57 | "Not sure how to parse destination \"%s\"!" % destination, |
| 58 | file=sys.stderr) |
| 59 | return 1 |
| 60 | if result.group(1): |
| 61 | user = result.group(1) |
| 62 | hostname = result.group(2) |
| 63 | if result.group(3): |
| 64 | target_dir = result.group(3) |
| 65 | |
| 66 | ssh_target = "%s@%s" % (user, hostname) |
| 67 | |
| 68 | rsync_cmd = ([ |
| 69 | "external/rsync/usr/bin/rsync", "-e", "external/ssh/usr/bin/ssh", "-c", |
| 70 | "-v", "-z", "--copy-links" |
| 71 | ] + srcs + ["%s:%s/%s" % (ssh_target, target_dir, relative_dir)]) |
| 72 | try: |
| 73 | subprocess.check_call(rsync_cmd) |
| 74 | except subprocess.CalledProcessError as e: |
| 75 | if e.returncode == 127: |
| 76 | print("Unconfigured roboRIO, installing rsync.") |
| 77 | install(ssh_target, "libattr1_2.4.47-r0.36_cortexa9-vfpv3.ipk") |
| 78 | install(ssh_target, "libacl1_2.2.52-r0.36_cortexa9-vfpv3.ipk") |
| 79 | install(ssh_target, "rsync_3.1.0-r0.7_cortexa9-vfpv3.ipk") |
| 80 | subprocess.check_call(rsync_cmd) |
| 81 | else: |
| 82 | raise e |
| 83 | |
| 84 | if not recursive: |
| 85 | subprocess.check_call( |
| 86 | ("external/ssh/usr/bin/ssh", ssh_target, "&&".join([ |
| 87 | "chmod u+s %s/starter_exe" % target_dir, |
| 88 | "echo \'Done moving new executables into place\'", |
| 89 | "bash -c \'sync && sync && sync\'", |
| 90 | ]))) |
| 91 | |
| 92 | |
| 93 | if __name__ == "__main__": |
| 94 | main(sys.argv) |