80 lines
2.1 KiB
Bash
80 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
CRATE_MANIFEST="$ROOT_DIR/traffic_core/Cargo.toml"
|
|
TARGET_BIN="$ROOT_DIR/traffic_core/target/release/awg2-harness"
|
|
|
|
AUTO_INSTALL=false
|
|
SKIP_FMT=false
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--install) AUTO_INSTALL=true ;;
|
|
--skip-fmt) SKIP_FMT=true ;;
|
|
*) echo "Unknown arg: $arg"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
require_cmd() {
|
|
command -v "$1" >/dev/null 2>&1 || { echo "Missing command: $1"; exit 1; }
|
|
}
|
|
|
|
if [[ -f /etc/os-release ]]; then
|
|
# shellcheck disable=SC1091
|
|
source /etc/os-release
|
|
case "${ID:-}" in
|
|
debian|ubuntu) ;;
|
|
*) echo "Unsupported OS: ${ID:-unknown}. Only Debian/Ubuntu are supported."; exit 1 ;;
|
|
esac
|
|
fi
|
|
|
|
ARCH="$(uname -m)"
|
|
if [[ "$ARCH" != "x86_64" && "$ARCH" != "amd64" ]]; then
|
|
echo "Unsupported arch: $ARCH. Only amd64/x86_64 is supported."
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v cargo >/dev/null 2>&1; then
|
|
echo "cargo not found. Install rustup first: https://rustup.rs"
|
|
exit 1
|
|
fi
|
|
|
|
for cmd in gcc pkg-config; do
|
|
require_cmd "$cmd"
|
|
done
|
|
|
|
if [[ "$SKIP_FMT" != true ]]; then
|
|
cargo fmt --manifest-path "$CRATE_MANIFEST" --all --check
|
|
fi
|
|
|
|
cargo clippy --manifest-path "$CRATE_MANIFEST" --all-targets -- -D warnings
|
|
cargo test --manifest-path "$CRATE_MANIFEST" --release
|
|
cargo build --manifest-path "$CRATE_MANIFEST" --release
|
|
|
|
require_cmd file
|
|
require_cmd ldd
|
|
|
|
file "$TARGET_BIN"
|
|
ldd "$TARGET_BIN" || true
|
|
"$TARGET_BIN" --help >/dev/null
|
|
|
|
sha256sum "$TARGET_BIN"
|
|
ls -lh "$TARGET_BIN"
|
|
|
|
if [[ "$AUTO_INSTALL" == true ]]; then
|
|
require_cmd install
|
|
sudo install -m 0755 "$TARGET_BIN" /usr/local/bin/awg2-harness
|
|
sudo mkdir -p /etc/awg2-harness
|
|
if [[ ! -f /etc/awg2-harness/config.toml ]]; then
|
|
echo "Missing /etc/awg2-harness/config.toml"
|
|
echo "Refusing to install example config as production config."
|
|
echo "Create config manually from $ROOT_DIR/config.example.toml and re-run with --install."
|
|
exit 1
|
|
fi
|
|
sudo install -m 0644 "$ROOT_DIR/awg2-harness.service" /etc/systemd/system/awg2-harness.service
|
|
sudo systemctl daemon-reload
|
|
fi
|
|
|
|
echo "Build completed: $TARGET_BIN"
|