mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-05-30 07:59:27 -07:00
PR #888 introduced more files that the installer needs to bundle. Those files in particular are annoying to deal with because now every developer needs a working C crosscompiler to get the installer working. This prompted me to do some other refactoring. Refactor install-dev to not build the wifi tools if there is no crosscompiler, and refactor the installer so that these files are loaded at runtime when built in debug mode. The build script only ever warns if files are missing, and depending on debug/release mode, the get_file!() macro either panics at runtime or fails compiling. Now the installer can be built again without any files, clippy can be run directly without any envvars, and the installer runs atleast for devices that don't need those files. The orbic installer will panic at runtime if the wifi tools haven't been built. Building the installer in release mode still requires all files. Another nicety of loading these files on runtime is that the installer does not need to be recompiled when the daemon has been rebuilt. This should make things like make.sh really obsolete, which bypass the installer for speed.
107 lines
2.8 KiB
Bash
Executable File
107 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Build Rayhunter from source for development.
|
|
# Prerequisites: Rust (rustup) and Node.js (npm).
|
|
#
|
|
# Usage: ./scripts/build-dev.sh [build|frontend|check]
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
check_dependencies() {
|
|
local missing=0
|
|
|
|
if ! command -v cargo &> /dev/null; then
|
|
echo "Error: cargo not found. Install Rust via https://www.rust-lang.org/tools/install"
|
|
missing=1
|
|
fi
|
|
|
|
if ! command -v npm &> /dev/null; then
|
|
echo "Error: npm not found. Install Node.js via https://docs.npmjs.com/downloading-and-installing-node-js-and-npm"
|
|
missing=1
|
|
fi
|
|
|
|
if [ "$missing" -eq 1 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure the ARM cross-compilation target is installed
|
|
if ! rustup target list --installed | grep -q "armv7-unknown-linux-musleabihf"; then
|
|
echo "Installing ARM target (armv7-unknown-linux-musleabihf)..."
|
|
rustup target add armv7-unknown-linux-musleabihf
|
|
fi
|
|
}
|
|
|
|
build_frontend() {
|
|
echo "Building web frontend..."
|
|
pushd daemon/web > /dev/null
|
|
npm install
|
|
npm run build
|
|
popd > /dev/null
|
|
}
|
|
|
|
build_wifi_tools() {
|
|
if [ -f "tools/build-wpa-supplicant/out/wpa_supplicant" ] \
|
|
&& [ -f "tools/build-wpa-supplicant/out/wpa_cli" ] \
|
|
&& [ -f "tools/build-wpa-supplicant/out/iw" ]; then
|
|
echo "WiFi tools already built, skipping."
|
|
return
|
|
fi
|
|
|
|
if ! command -v arm-linux-musleabihf-gcc &> /dev/null; then
|
|
echo "Warning: Skipping building WiFi tools due to missing C crosscompiler."
|
|
echo "arm-linux-musleabihf-gcc not found."
|
|
echo "Install with: brew install FiloSottile/musl-cross/musl-cross"
|
|
return
|
|
fi
|
|
|
|
echo "Building WiFi tools..."
|
|
./scripts/build-wpa-supplicant.sh
|
|
}
|
|
|
|
build_daemon() {
|
|
echo "Building daemon..."
|
|
cargo build-daemon-firmware-devel
|
|
|
|
echo "Building rootshell..."
|
|
cargo build-rootshell-firmware-devel
|
|
}
|
|
|
|
COMMAND="${1:-build}"
|
|
|
|
case "$COMMAND" in
|
|
build)
|
|
check_dependencies
|
|
build_frontend
|
|
build_wifi_tools
|
|
build_daemon
|
|
echo ""
|
|
echo "Build complete! To install to a device, run:"
|
|
echo " ./scripts/install-dev.sh <device>"
|
|
echo ""
|
|
echo "Replace <device> with your device type (e.g. orbic, tplink)."
|
|
;;
|
|
frontend)
|
|
build_frontend
|
|
;;
|
|
check)
|
|
check_dependencies
|
|
;;
|
|
help|--help|-h)
|
|
echo "Usage: $0 [command]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " build Build frontend, daemon, and rootshell (default)"
|
|
echo " frontend Build only the web frontend"
|
|
echo " check Check dependencies only"
|
|
;;
|
|
*)
|
|
echo "Unknown command: $COMMAND"
|
|
echo "Run '$0 help' for usage."
|
|
exit 1
|
|
;;
|
|
esac
|