flowey_lib_hvlite/_jobs/
local_check_cca_emu_prereq.rs1use flowey::node::prelude::*;
7use std::fs;
8
9flowey_request! {
10 pub struct Params {
11 pub done: WriteVar<SideEffect>,
12 }
13}
14
15new_simple_flow_node!(struct Node);
16
17impl SimpleFlowNode for Node {
18 type Request = Params;
19
20 fn imports(ctx: &mut ImportCtx<'_>) {
21 ctx.import::<crate::run_cargo_build::Node>();
22 ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
23 }
24
25 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
26 let Params { done } = request;
27
28 let required_packages_installed = ctx.reqv(|v| {
29 flowey_lib_common::install_dist_pkg::Request::Install {
30 package_names: vec![
31 "netcat-openbsd".into(),
32 "python3".into(),
33 "python3-pip".into(),
34 "telnet".into(),
35 "docker.io".into(),
36 "gcc-aarch64-linux-gnu".into(),
37 "flex".into(),
39 "bison".into(),
40 "libssl-dev".into(),
41 "python3-venv".into(),
42 ],
43 done: v,
44 }
45 });
46
47 ctx.emit_rust_step("check prerequisite of arm64 emulation environment", |ctx| {
48 done.claim(ctx);
49 required_packages_installed.claim(ctx);
50 move |rt| {
51 let group_name = "docker";
53 let group_file = fs::read_to_string("/etc/group").expect("Failed to read /etc/group");
54 let docker_group = group_file
55 .lines()
56 .find(|line| line.starts_with(&format!("{group_name}:")));
57
58 if docker_group.is_none() {
59 anyhow::bail!("Group '{group_name}' does not exist, please add it using 'sudo groupadd docker'");
60 }
61
62 let output = flowey::shell_cmd!(rt, "id -nG").output()?;
64 let output = String::from_utf8(output.stdout)?;
65 let is_member = output.split_whitespace().any(|g| g == group_name);
66 if !is_member {
67 anyhow::bail!("Current user does NOT belong to the '{group_name}' group, please add it using 'sudo usermod -aG docker $USER', and restart the shell!");
68 }
69
70 Ok(())
71 }
72 });
73
74 Ok(())
75 }
76}