#!/usr/bin/env bash set -euo pipefail ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" cd "$ROOT" umask 077 if [[ -f .env ]]; then # Local shell configuration. Do not source untrusted .env files. set -a # shellcheck disable=SC1091 source .env set +a fi if ! command -v cargo >/dev/null 2>&1 && [[ -x "$HOME/.cargo/bin/cargo" ]]; then export PATH="$HOME/.cargo/bin:$PATH" fi VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)" mode="${1:-run}" if [[ $# -gt 0 ]]; then shift; fi case "$mode" in help|-h|--help) cat <&2; exit 2 ;; esac case "$mode" in doctor) for tool in cargo rustc cc python3 node dpkg-deb dovecot radicale; do printf '%-10s ' "$tool"; command -v "$tool" || printf 'NOT FOUND\n' done exit 0 ;; backends) exec tools/dev/test-backends.sh "$@" ;; import-zpush) exec python3 tools/zpush-import.py "$@" ;; deb) exec scripts/build-deb.sh "$@" ;; dist) exec ./build-release.sh "$@" ;; esac if ! command -v cargo >/dev/null 2>&1; then cat >&2 <<'MISSING' Rust/Cargo is not installed or not in PATH. Install the stable toolchain from https://rustup.rs and a C linker (build-essential). This script never installs system software or runs sudo. MISSING exit 127 fi export ACTIVE_PUSH_DATA_DIR="${ACTIVE_PUSH_DATA_DIR:-$ROOT/data}" export ACTIVE_PUSH_EAS_LISTEN="${ACTIVE_PUSH_EAS_LISTEN:-127.0.0.1:8081}" export ACTIVE_PUSH_ADMIN_LISTEN="${ACTIVE_PUSH_ADMIN_LISTEN:-127.0.0.1:9091}" export RUST_LOG="${RUST_LOG:-active_push=info,warn}" export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}" mkdir -p "$ACTIVE_PUSH_DATA_DIR" case "$mode" in fmt) exec cargo fmt --all "$@" ;; check) exec cargo check --all-targets "$@" ;; test) exec cargo test --lib --bins "$@" ;; lint) cargo fmt --all -- --check cargo clippy --all-targets -- -D warnings if command -v node >/dev/null; then node --check web/app.js; fi python3 scripts/check-wbxml-names.py printf 'Lint: OK\n' exit 0 ;; release) exec cargo build --release "$@" ;; e2e) export AP_E2E_URL="${AP_E2E_URL:-http://${ACTIVE_PUSH_EAS_LISTEN}}" exec cargo test --test e2e -- --nocapture --test-threads=1 "$@" ;; esac printf 'Building ActivePush %s...\n' "$VERSION" >&2 cargo build BIN="$CARGO_TARGET_DIR/debug/active-push" case "$mode" in build) printf 'Binary: %s\n' "$BIN" ;; seed) exec "$BIN" config apply tools/dev/test-settings.json ;; probe) user="${1:?usage: ./dev.sh probe USER}" exec "$BIN" probe --url "http://${ACTIVE_PUSH_EAS_LISTEN}/Microsoft-Server-ActiveSync" --user "$user" ;; admin) exec "$BIN" admin "$@" ;; config) exec "$BIN" config "$@" ;; device) exec "$BIN" device "$@" ;; run) printf 'ActiveSync: http://%s/Microsoft-Server-ActiveSync\nPanel: http://%s/\n' "$ACTIVE_PUSH_EAS_LISTEN" "$ACTIVE_PUSH_ADMIN_LISTEN" >&2 exec "$BIN" serve "$@" ;; esac