add etrelay UDP relay + etmasters script + update README

This commit is contained in:
rmanach
2026-09-26 15:11:44 +02:00
parent 002289fd35
commit 6ab4218601
22 changed files with 1109 additions and 9 deletions
+73
View File
@@ -0,0 +1,73 @@
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
NAME := etrelay
VERSION := $(shell grep -m1 '^version' Cargo.toml | cut -d '"' -f2)
GNU := x86_64-unknown-linux-gnu
MUSL := x86_64-unknown-linux-musl
# Release artifacts: <name>-v<version>-<target triple> (+ .sha256).
DIST_DIR := $(ROOT_DIR)dist
DYNAMIC_BIN := $(DIST_DIR)/$(NAME)-v$(VERSION)-$(GNU)
STATIC_BIN := $(DIST_DIR)/$(NAME)-v$(VERSION)-$(MUSL)
# Deployment target (front server SSH host) and ET server behind the tunnel (ip:port),
# e.g. make deploy HOST=front UPSTREAM=10.0.0.2:27960
HOST ?=
UPSTREAM ?=
# Extra etrelay flags, e.g. make deploy ARGS=--debug
ARGS ?=
.PHONY: show lint format check build static release deploy logs diagrams clean
show:
@echo "$(NAME) version: $(VERSION)"
lint:
cargo clippy --fix --allow-dirty
format:
cargo fmt --all
check: lint format
# Dynamic (glibc): runs on hosts with the same or newer glibc.
build: check
cargo build --release --target $(GNU)
@$(call dist,$(GNU),$(DYNAMIC_BIN))
# Static (musl): runs on any x86_64 Linux. Pure Rust, no musl-gcc needed.
static: check
rustup target add $(MUSL)
cargo build --release --target $(MUSL)
@$(call dist,$(MUSL),$(STATIC_BIN))
release: build static
deploy: static
@test -n "$(HOST)" -a -n "$(UPSTREAM)" || (echo "usage: make deploy HOST=<ssh host> UPSTREAM=<ip:port>" && exit 1)
scp $(STATIC_BIN) $(HOST):/tmp/$(NAME)
sed -e 's#@UPSTREAM@#$(UPSTREAM)#' -e 's#@ARGS@#$(ARGS)#' $(NAME).service | ssh $(HOST) 'cat > /etc/systemd/system/$(NAME).service'
ssh $(HOST) 'install -m 755 /tmp/$(NAME) /usr/local/bin/$(NAME) && rm /tmp/$(NAME) \
&& systemctl daemon-reload && systemctl enable $(NAME) && systemctl restart $(NAME) \
&& systemctl --no-pager status $(NAME)'
logs:
@test -n "$(HOST)" || (echo "usage: make logs HOST=<ssh host>" && exit 1)
ssh $(HOST) 'journalctl -u $(NAME) -n 50 --no-pager'
# PlantUML sources (diagrams/*.puml) -> PNG next to them, used by ENGINE.md.
diagrams:
plantuml -tpng $(ROOT_DIR)diagrams/*.puml
@ls -1 $(ROOT_DIR)diagrams/*.png
clean:
cargo clean
rm -rf $(DIST_DIR)
# $(call dist,<target triple>,<artifact path>): copy the release binary to dist/ + checksum.
define dist
mkdir -p $(DIST_DIR)
cp $(ROOT_DIR)target/$(1)/release/$(NAME) $(2)
cd $(DIST_DIR) && sha256sum $(notdir $(2)) > $(notdir $(2)).sha256
ls -lh $(2)
endef