blob: 26ef19aa607f06bf76345520e9f95c514bba0d01 [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
12def main(argv):
Austin Schuh46ecbf72015-10-15 00:02:40 -070013 srcs = argv[1:argv.index('--')]
Brian Silvermanaf485d62015-10-12 00:37:14 -040014 args = argv[argv.index('--') + 1:]
15
Brian Silvermand54068e2015-10-14 17:56:05 -040016 ROBORIO_TARGET_DIR = '/home/admin/robot_code'
17 ROBORIO_USER = 'admin'
18
19 target_dir = ROBORIO_TARGET_DIR
20 user = ROBORIO_USER
21 destination = args[-1]
22
23 result = re.match('(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?', destination)
24 if not result:
25 print('Not sure how to parse destination "%s"!' % destination,
26 file=sys.stderr)
27 return 1
28 if result.group(1):
29 user = result.group(1)
30 hostname = result.group(2)
31 if result.group(3):
32 target_dir = result.group(3)
33
34 ssh_target = '%s@%s' % (user, hostname)
35
36 subprocess.check_call(
Austin Schuh1e4eea22015-11-08 12:50:05 -080037 ['rsync', '-c', '-v', '-z', '--copy-links'] + srcs +
Brian Silvermand54068e2015-10-14 17:56:05 -040038 ['%s:%s' % (ssh_target, target_dir)])
39 subprocess.check_call(
40 ('ssh', ssh_target, '&&'.join([
41 'chmod u+s %s/starter_exe' % target_dir,
42 'echo \'Done moving new executables into place\'',
43 'bash -c \'sync && sync && sync\'',
44 ])))
Brian Silvermanaf485d62015-10-12 00:37:14 -040045
46if __name__ == '__main__':
47 main(sys.argv)