-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
68 lines (54 loc) · 2.71 KB
/
deploy.py
File metadata and controls
68 lines (54 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import argparse
import subprocess
from pathlib import Path
def run(cmd):
print("Executing", " ".join([f'"{x}"' for x in cmd]))
subprocess.run(cmd, check=True)
def main():
parser = argparse.ArgumentParser(description="Deploy image on the remote RPi.")
parser.add_argument("image", type=Path, help="image file")
# this path includes rpi4/autosar
parser.add_argument("--path", required=True, type=Path, help="remote tftp path")
parser.add_argument("--ssh-host", required=True, help="ssh host")
parser.add_argument("--scp", required=True, type=Path, help="path to scp")
parser.add_argument("--ssh", required=True, type=Path, help="path to ssh")
parser.add_argument("--rpi", required=False, action='store_true', help="whether to update Raspberry config with new kernel")
parser.add_argument("--beaglev", required=False, action='store_true', help="whether to rename new kernel for beaglev")
args = parser.parse_args()
assert args.ssh.is_file()
assert args.scp.is_file()
assert args.image.is_file()
name = args.image.stem
remote_file = f"{args.ssh_host}:{args.path}/{name}.img"
run([args.scp, args.image.absolute(), remote_file])
remote_cmd = f"chmod 777 {args.path}/{name}.img"
try:
run([args.ssh, args.ssh_host, remote_cmd])
except subprocess.CalledProcessError:
print("Failed to set permissions on remote file.")
if args.rpi:
# TODO: this only works for 32-bit Autosar
# need to edit config.txt in parent fodler
remote_cmd = f"sed -i -E 's/^kernel=.*/kernel=autosar\/{name}.img/' {args.path}/../config.txt"
run([args.ssh, args.ssh_host, remote_cmd])
# TODO: to enable both variants simultaneous need something like:
"""
if args.is_32:
remote_cmd = f"sed -i -E 's/^kernel=.*/kernel=autosar\/{name}.img/' {args.path}/config32.txt"
run([args.ssh, args.ssh_host, remote_cmd])
# force symlink to be on 32-bit config
remote_cmd = f" cd /proj/tftp/research/rpi4/autosar && ln -s -f config32.txt config.txt"
run([args.ssh, args.ssh_host, remote_cmd])
else:
remote_cmd = f"sed -i -E 's/^kernel=.*/kernel=autosar\/{name}.img/' {args.path}/config64.txt"
run([args.ssh, args.ssh_host, remote_cmd])
# force symlink to be on 64-bit config
remote_cmd = f" cd /proj/tftp/research/rpi4 && ln -s -f config64.txt config.txt"
run([args.ssh, args.ssh_host, remote_cmd])
"""
if args.beaglev:
remote_cmd = f"cp {args.path}/{name}.img {args.path}/autosar.bin"
run([args.ssh, args.ssh_host, remote_cmd])
if __name__ == '__main__':
main()