blob: 5cdd94e91f3c508fd387f0ee0524bebb42de2894 [file] [log] [blame]
Brian Silvermanaf485d62015-10-12 00:37:14 -04001# 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 Silvermand54068e2015-10-14 17:56:05 -04005from __future__ import print_function
6
Brian Silvermanaf485d62015-10-12 00:37:14 -04007import sys
8import subprocess
Brian Silvermand54068e2015-10-14 17:56:05 -04009import re
10import os
Brian Silvermanaf485d62015-10-12 00:37:14 -040011
Austin Schuhb64799c2015-12-19 22:35:51 -080012def 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 Silvermanaf485d62015-10-12 00:37:14 -040025def main(argv):
Austin Schuh46ecbf72015-10-15 00:02:40 -070026 srcs = argv[1:argv.index('--')]
Brian Silvermanaf485d62015-10-12 00:37:14 -040027 args = argv[argv.index('--') + 1:]
28
Brian Silvermand54068e2015-10-14 17:56:05 -040029 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 Schuhb64799c2015-12-19 22:35:51 -080049 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 Silvermand54068e2015-10-14 17:56:05 -040063 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 Silvermanaf485d62015-10-12 00:37:14 -040069
70if __name__ == '__main__':
71 main(sys.argv)