diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 647fa11..90e887b 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -8,6 +8,10 @@ on: env: CARGO_TERM_COLOR: always + FILE_ROOTSHELL: ../../rootshell/rootshell + FILE_RAYHUNTER_DAEMON_ORBIC: ../../rayhunter-daemon-orbic/rayhunter-daemon + FILE_RAYHUNTER_DAEMON_TPLINK: ../../rayhunter-daemon-tplink/rayhunter-daemon + jobs: build_rayhunter_check: @@ -105,8 +109,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.platform.target }} - - - run: cargo build --bin installer --release --target ${{ matrix.platform.target }} --features vendor + - run: cargo build --bin installer --release --target ${{ matrix.platform.target }} - uses: actions/upload-artifact@v4 with: name: installer-${{ matrix.platform.name }} diff --git a/.github/workflows/check-and-test.yml b/.github/workflows/check-and-test.yml index d7ea876..1f0d0c4 100644 --- a/.github/workflows/check-and-test.yml +++ b/.github/workflows/check-and-test.yml @@ -8,6 +8,7 @@ on: env: CARGO_TERM_COLOR: always + NO_FIRMWARE_BIN: true jobs: check_and_test: diff --git a/installer/Cargo.toml b/installer/Cargo.toml index afa58cd..9c6b744 100644 --- a/installer/Cargo.toml +++ b/installer/Cargo.toml @@ -3,9 +3,6 @@ name = "installer" version = "0.1.0" edition = "2024" -[features] -vendor = [] - [dependencies] anyhow = "1.0.98" axum = "0.8.3" diff --git a/installer/build.rs b/installer/build.rs new file mode 100644 index 0000000..b6682b6 --- /dev/null +++ b/installer/build.rs @@ -0,0 +1,45 @@ +use core::str; +use std::path::Path; +use std::process::exit; + +fn main() { + println!("cargo::rerun-if-env-changed=NO_FIRMWARE_BIN"); + let include_dir = Path::new(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../target/armv7-unknown-linux-musleabihf/release/" + )); + set_binary_var(&include_dir, "FILE_ROOTSHELL", "rootshell"); + set_binary_var( + &include_dir, + "FILE_RAYHUNTER_DAEMON_ORBIC", + "rayhunter-daemon", + ); + set_binary_var( + &include_dir, + "FILE_RAYHUNTER_DAEMON_TPLINK", + "rayhunter-daemon", + ); +} + +fn set_binary_var(include_dir: &Path, var: &str, file: &str) { + if std::env::var_os("NO_FIRMWARE_BIN").is_some() { + let out_dir = std::env::var("OUT_DIR").unwrap(); + std::fs::create_dir_all(&out_dir).unwrap(); + let blank = Path::new(&out_dir).join("blank"); + std::fs::write(&blank, &[]).unwrap(); + println!("cargo::rustc-env={var}={}", blank.display()); + return; + } + if std::env::var_os(var).is_none() { + let binary = include_dir.join(file); + if !binary.exists() { + println!( + "cargo::error=Firmware binary {file} not present at {}", + binary.display() + ); + exit(0); + } + println!("cargo::rustc-env={var}={}", binary.display()); + println!("cargo::rerun-if-changed={}", binary.display()); + } +} diff --git a/installer/src/orbic.rs b/installer/src/orbic.rs index ca4a3d6..7f8dff5 100644 --- a/installer/src/orbic.rs +++ b/installer/src/orbic.rs @@ -70,13 +70,7 @@ async fn setup_rootshell( serial_interface: &Interface, adb_device: &mut ADBUSBDevice, ) -> Result<()> { - #[cfg(feature = "vendor")] - let rootshell_bin = include_bytes!("../../rootshell/rootshell"); - - #[cfg(not(feature = "vendor"))] - let rootshell_bin = &tokio::fs::read("target/armv7-unknown-linux-musleabihf/release/rootshell") - .await - .context("Error reading rootshell from local file system")?; + let rootshell_bin = include_bytes!(env!("FILE_ROOTSHELL")); install_file( serial_interface, @@ -100,14 +94,7 @@ async fn setup_rayhunter( serial_interface: &Interface, mut adb_device: ADBUSBDevice, ) -> Result { - #[cfg(feature = "vendor")] - let rayhunter_daemon_bin = include_bytes!("../../rayhunter-daemon-orbic/rayhunter-daemon"); - - #[cfg(not(feature = "vendor"))] - let rayhunter_daemon_bin = - &tokio::fs::read("target/armv7-unknown-linux-musleabihf/release/rayhunter-daemon") - .await - .context("Error reading rayhunter-daemon from local file system")?; + let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON_ORBIC")); at_syscmd(serial_interface, "mkdir -p /data/rayhunter").await?; install_file( diff --git a/installer/src/tplink.rs b/installer/src/tplink.rs index 4eaf4f1..6ec2e87 100644 --- a/installer/src/tplink.rs +++ b/installer/src/tplink.rs @@ -114,12 +114,7 @@ async fn tplink_run_install(skip_sdcard: bool, admin_ip: String) -> Result<(), E ) .await?; - #[cfg(feature = "vendor")] - let rayhunter_daemon_bin = include_bytes!("../../rayhunter-daemon-tplink/rayhunter-daemon"); - - #[cfg(not(feature = "vendor"))] - let rayhunter_daemon_bin = - &tokio::fs::read("target/armv7-unknown-linux-musleabihf/release/rayhunter-daemon").await?; + let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON_TPLINK")); telnet_send_file(addr, "/media/card/rayhunter-daemon", rayhunter_daemon_bin).await?; telnet_send_file(