Skip to content

Commit f2a7bdd

Browse files
committed
Always include firmware binaries statically into installer
1 parent dd72626 commit f2a7bdd

File tree

6 files changed

+52
-26
lines changed

6 files changed

+52
-26
lines changed

.github/workflows/build-release.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
FILE_ROOTSHELL: ../../rootshell/rootshell
12+
FILE_RAYHUNTER_DAEMON_ORBIC: ../../rayhunter-daemon-orbic/rayhunter-daemon
13+
FILE_RAYHUNTER_DAEMON_TPLINK: ../../rayhunter-daemon-tplink/rayhunter-daemon
14+
1115

1216
jobs:
1317
build_rayhunter_check:
@@ -105,8 +109,7 @@ jobs:
105109
- uses: dtolnay/rust-toolchain@stable
106110
with:
107111
targets: ${{ matrix.platform.target }}
108-
109-
- run: cargo build --bin installer --release --target ${{ matrix.platform.target }} --features vendor
112+
- run: cargo build --bin installer --release --target ${{ matrix.platform.target }}
110113
- uses: actions/upload-artifact@v4
111114
with:
112115
name: installer-${{ matrix.platform.name }}

.github/workflows/check-and-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
NO_FIRMWARE_BIN: true
1112

1213
jobs:
1314
check_and_test:

installer/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ name = "installer"
33
version = "0.1.0"
44
edition = "2024"
55

6-
[features]
7-
vendor = []
8-
96
[dependencies]
107
anyhow = "1.0.98"
118
axum = "0.8.3"

installer/build.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use core::str;
2+
use std::path::Path;
3+
use std::process::exit;
4+
5+
fn main() {
6+
let include_dir = Path::new(concat!(
7+
env!("CARGO_MANIFEST_DIR"),
8+
"/../target/armv7-unknown-linux-musleabihf/release/"
9+
));
10+
set_binary_var(&include_dir, "FILE_ROOTSHELL", "rootshell");
11+
set_binary_var(
12+
&include_dir,
13+
"FILE_RAYHUNTER_DAEMON_ORBIC",
14+
"rayhunter-daemon",
15+
);
16+
set_binary_var(
17+
&include_dir,
18+
"FILE_RAYHUNTER_DAEMON_TPLINK",
19+
"rayhunter-daemon",
20+
);
21+
}
22+
23+
fn set_binary_var(include_dir: &Path, var: &str, file: &str) {
24+
if std::env::var_os("NO_FIRMWARE_BIN").is_some() {
25+
let out_dir = std::env::var("OUT_DIR").unwrap();
26+
std::fs::create_dir_all(&out_dir).unwrap();
27+
let blank = Path::new(&out_dir).join("blank");
28+
std::fs::write(&blank, &[]).unwrap();
29+
println!("cargo::rustc-env={var}={}", blank.display());
30+
return;
31+
}
32+
if std::env::var_os(var).is_none() {
33+
let binary = include_dir.join(file);
34+
if !binary.exists() {
35+
println!(
36+
"cargo::error=Firmware binary {file} not present at {}",
37+
binary.display()
38+
);
39+
exit(0);
40+
}
41+
println!("cargo::rustc-env={var}={}", binary.display());
42+
}
43+
}

installer/src/orbic.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ async fn setup_rootshell(
7070
serial_interface: &Interface,
7171
adb_device: &mut ADBUSBDevice,
7272
) -> Result<()> {
73-
#[cfg(feature = "vendor")]
74-
let rootshell_bin = include_bytes!("../../rootshell/rootshell");
75-
76-
#[cfg(not(feature = "vendor"))]
77-
let rootshell_bin = &tokio::fs::read("target/armv7-unknown-linux-musleabihf/release/rootshell")
78-
.await
79-
.context("Error reading rootshell from local file system")?;
73+
let rootshell_bin = include_bytes!(env!("FILE_ROOTSHELL"));
8074

8175
install_file(
8276
serial_interface,
@@ -100,14 +94,7 @@ async fn setup_rayhunter(
10094
serial_interface: &Interface,
10195
mut adb_device: ADBUSBDevice,
10296
) -> Result<ADBUSBDevice> {
103-
#[cfg(feature = "vendor")]
104-
let rayhunter_daemon_bin = include_bytes!("../../rayhunter-daemon-orbic/rayhunter-daemon");
105-
106-
#[cfg(not(feature = "vendor"))]
107-
let rayhunter_daemon_bin =
108-
&tokio::fs::read("target/armv7-unknown-linux-musleabihf/release/rayhunter-daemon")
109-
.await
110-
.context("Error reading rayhunter-daemon from local file system")?;
97+
let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON_ORBIC"));
11198

11299
at_syscmd(serial_interface, "mkdir -p /data/rayhunter").await?;
113100
install_file(

installer/src/tplink.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ async fn tplink_run_install(skip_sdcard: bool, admin_ip: String) -> Result<(), E
114114
)
115115
.await?;
116116

117-
#[cfg(feature = "vendor")]
118-
let rayhunter_daemon_bin = include_bytes!("../../rayhunter-daemon-tplink/rayhunter-daemon");
119-
120-
#[cfg(not(feature = "vendor"))]
121-
let rayhunter_daemon_bin =
122-
&tokio::fs::read("target/armv7-unknown-linux-musleabihf/release/rayhunter-daemon").await?;
117+
let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON_TPLINK"));
123118

124119
telnet_send_file(addr, "/media/card/rayhunter-daemon", rayhunter_daemon_bin).await?;
125120
telnet_send_file(

0 commit comments

Comments
 (0)