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 | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame^] | 12 | def install(ssh_target, pkg): |
| 13 | """Installs a package from NI on the ssh target.""" |
| 14 | print('Installing', pkg) |
| 15 | PKG_URL = 'http://download.ni.com/ni-linux-rt/feeds/2015/arm/ipk/cortexa9-vfpv3/' + pkg |
| 16 | subprocess.check_call(['wget', PKG_URL, '-O', pkg]) |
| 17 | try: |
| 18 | subprocess.check_call(['scp', pkg, ssh_target + ':/tmp/' + pkg]) |
| 19 | subprocess.check_call(['ssh', ssh_target, 'opkg', 'install', '/tmp/' + pkg]) |
| 20 | subprocess.check_call(['ssh', ssh_target, 'rm', '/tmp/' + pkg]) |
| 21 | finally: |
| 22 | subprocess.check_call(['rm', pkg]) |
| 23 | |
| 24 | |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 25 | def main(argv): |
Austin Schuh | 46ecbf7 | 2015-10-15 00:02:40 -0700 | [diff] [blame] | 26 | srcs = argv[1:argv.index('--')] |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 27 | args = argv[argv.index('--') + 1:] |
| 28 | |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 29 | ROBORIO_TARGET_DIR = '/home/admin/robot_code' |
| 30 | ROBORIO_USER = 'admin' |
| 31 | |
| 32 | target_dir = ROBORIO_TARGET_DIR |
| 33 | user = ROBORIO_USER |
| 34 | destination = args[-1] |
| 35 | |
| 36 | result = re.match('(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?', destination) |
| 37 | if not result: |
| 38 | print('Not sure how to parse destination "%s"!' % destination, |
| 39 | file=sys.stderr) |
| 40 | return 1 |
| 41 | if result.group(1): |
| 42 | user = result.group(1) |
| 43 | hostname = result.group(2) |
| 44 | if result.group(3): |
| 45 | target_dir = result.group(3) |
| 46 | |
| 47 | ssh_target = '%s@%s' % (user, hostname) |
| 48 | |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame^] | 49 | rsync_cmd = (['rsync', '-c', '-v', '-z', '--copy-links'] + srcs + |
| 50 | ['%s:%s' % (ssh_target, target_dir)]) |
| 51 | try: |
| 52 | subprocess.check_call(rsync_cmd) |
| 53 | except subprocess.CalledProcessError as e: |
| 54 | if e.returncode == 127: |
| 55 | print('Unconfigured roboRIO, installing rsync.') |
| 56 | install(ssh_target, 'libattr1_2.4.47-r0.36_cortexa9-vfpv3.ipk') |
| 57 | install(ssh_target, 'libacl1_2.2.52-r0.36_cortexa9-vfpv3.ipk') |
| 58 | install(ssh_target, 'rsync_3.1.0-r0.7_cortexa9-vfpv3.ipk') |
| 59 | subprocess.check_call(rsync_cmd) |
| 60 | else: |
| 61 | raise e |
| 62 | |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 63 | subprocess.check_call( |
| 64 | ('ssh', ssh_target, '&&'.join([ |
| 65 | 'chmod u+s %s/starter_exe' % target_dir, |
| 66 | 'echo \'Done moving new executables into place\'', |
| 67 | 'bash -c \'sync && sync && sync\'', |
| 68 | ]))) |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 69 | |
| 70 | if __name__ == '__main__': |
| 71 | main(sys.argv) |