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): |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 26 | args = argv[argv.index('--') + 1:] |
| 27 | |
Comran Morshed | 3896733 | 2016-04-23 19:26:48 -0700 | [diff] [blame^] | 28 | relative_dir = '' |
| 29 | recursive = False |
| 30 | |
| 31 | if '--dirs' in argv: |
| 32 | dirs_index = argv.index('--dirs') |
| 33 | srcs = argv[1:dirs_index] |
| 34 | relative_dir = argv[dirs_index + 1] |
| 35 | recursive = True |
| 36 | else: |
| 37 | srcs = argv[1:argv.index('--')] |
| 38 | |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 39 | ROBORIO_TARGET_DIR = '/home/admin/robot_code' |
| 40 | ROBORIO_USER = 'admin' |
| 41 | |
| 42 | target_dir = ROBORIO_TARGET_DIR |
| 43 | user = ROBORIO_USER |
| 44 | destination = args[-1] |
| 45 | |
| 46 | result = re.match('(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?', destination) |
| 47 | if not result: |
| 48 | print('Not sure how to parse destination "%s"!' % destination, |
| 49 | file=sys.stderr) |
| 50 | return 1 |
| 51 | if result.group(1): |
| 52 | user = result.group(1) |
| 53 | hostname = result.group(2) |
| 54 | if result.group(3): |
| 55 | target_dir = result.group(3) |
| 56 | |
| 57 | ssh_target = '%s@%s' % (user, hostname) |
| 58 | |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame] | 59 | rsync_cmd = (['rsync', '-c', '-v', '-z', '--copy-links'] + srcs + |
Comran Morshed | 3896733 | 2016-04-23 19:26:48 -0700 | [diff] [blame^] | 60 | ['%s:%s/%s' % (ssh_target, target_dir, relative_dir)]) |
Austin Schuh | b64799c | 2015-12-19 22:35:51 -0800 | [diff] [blame] | 61 | try: |
| 62 | subprocess.check_call(rsync_cmd) |
| 63 | except subprocess.CalledProcessError as e: |
| 64 | if e.returncode == 127: |
| 65 | print('Unconfigured roboRIO, installing rsync.') |
| 66 | install(ssh_target, 'libattr1_2.4.47-r0.36_cortexa9-vfpv3.ipk') |
| 67 | install(ssh_target, 'libacl1_2.2.52-r0.36_cortexa9-vfpv3.ipk') |
| 68 | install(ssh_target, 'rsync_3.1.0-r0.7_cortexa9-vfpv3.ipk') |
| 69 | subprocess.check_call(rsync_cmd) |
| 70 | else: |
| 71 | raise e |
| 72 | |
Comran Morshed | 3896733 | 2016-04-23 19:26:48 -0700 | [diff] [blame^] | 73 | if not recursive: |
| 74 | subprocess.check_call( |
| 75 | ('ssh', ssh_target, '&&'.join([ |
| 76 | 'chmod u+s %s/starter_exe' % target_dir, |
| 77 | 'echo \'Done moving new executables into place\'', |
| 78 | 'bash -c \'sync && sync && sync\'', |
| 79 | ]))) |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 80 | |
| 81 | if __name__ == '__main__': |
| 82 | main(sys.argv) |