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 | |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 13 | def install(ssh_target, pkg, ssh_path, scp_path): |
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([ |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 20 | scp_path, "-S", ssh_path, pkg, |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 21 | ssh_target + ":/tmp/" + pkg |
| 22 | ]) |
| 23 | subprocess.check_call([ |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 24 | ssh_path, ssh_target, "opkg", "install", |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 25 | "/tmp/" + pkg |
| 26 | ]) |
| 27 | subprocess.check_call( |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 28 | [ssh_path, ssh_target, "rm", "/tmp/" + pkg]) |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 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 | |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 68 | ssh_path = "external/ssh/ssh" |
| 69 | scp_path = "external/ssh/scp" |
| 70 | |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 71 | rsync_cmd = ([ |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 72 | "external/rsync/usr/bin/rsync", "-e", ssh_path, "-c", |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 73 | "-v", "-z", "--copy-links" |
| 74 | ] + srcs + ["%s:%s/%s" % (ssh_target, target_dir, relative_dir)]) |
| 75 | try: |
| 76 | subprocess.check_call(rsync_cmd) |
| 77 | except subprocess.CalledProcessError as e: |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 78 | if e.returncode == 127 or e.returncode == 12: |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 79 | print("Unconfigured roboRIO, installing rsync.") |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 80 | install(ssh_target, "libattr1_2.4.47-r0.36_cortexa9-vfpv3.ipk", |
| 81 | ssh_path, scp_path) |
| 82 | install(ssh_target, "libacl1_2.2.52-r0.36_cortexa9-vfpv3.ipk", |
| 83 | ssh_path, scp_path) |
| 84 | install(ssh_target, "rsync_3.1.0-r0.7_cortexa9-vfpv3.ipk", |
| 85 | ssh_path, scp_path) |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 86 | subprocess.check_call(rsync_cmd) |
| 87 | else: |
| 88 | raise e |
| 89 | |
| 90 | if not recursive: |
| 91 | subprocess.check_call( |
Brian Silverman | bd7860e | 2020-01-05 17:52:40 -0800 | [diff] [blame] | 92 | (ssh_path, ssh_target, "&&".join([ |
Austin Schuh | 71f6fa7 | 2019-08-31 18:23:02 -0700 | [diff] [blame] | 93 | "chmod u+s %s/starter_exe" % target_dir, |
| 94 | "echo \'Done moving new executables into place\'", |
| 95 | "bash -c \'sync && sync && sync\'", |
| 96 | ]))) |
| 97 | |
| 98 | |
| 99 | if __name__ == "__main__": |
| 100 | main(sys.argv) |