blob: e49ee5d4c2f8ec9a35a62f838a4a769b9de30b24 [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 Schuh71f6fa72019-08-31 18:23:02 -070012
Austin Schuhb64799c2015-12-19 22:35:51 -080013def install(ssh_target, pkg):
Austin Schuh71f6fa72019-08-31 18:23:02 -070014 """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 Schuhb64799c2015-12-19 22:35:51 -080031
32
Brian Silvermanaf485d62015-10-12 00:37:14 -040033def main(argv):
Austin Schuh71f6fa72019-08-31 18:23:02 -070034 args = argv[argv.index("--") + 1:]
Brian Silvermanaf485d62015-10-12 00:37:14 -040035
Austin Schuh71f6fa72019-08-31 18:23:02 -070036 relative_dir = ""
37 recursive = False
Comran Morshed38967332016-04-23 19:26:48 -070038
Austin Schuh71f6fa72019-08-31 18:23:02 -070039 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 Schuhb64799c2015-12-19 22:35:51 -080044 else:
Austin Schuh71f6fa72019-08-31 18:23:02 -070045 srcs = argv[1:argv.index("--")]
Austin Schuhb64799c2015-12-19 22:35:51 -080046
Austin Schuh71f6fa72019-08-31 18:23:02 -070047 ROBORIO_TARGET_DIR = "/home/admin/robot_code"
48 ROBORIO_USER = "admin"
Brian Silvermanaf485d62015-10-12 00:37:14 -040049
Austin Schuh71f6fa72019-08-31 18:23:02 -070050 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
93if __name__ == "__main__":
94 main(sys.argv)