Files
shater/xrayctl/Makefile
T
omarandClaude Opus 4.8 b8cb0c4537
build / aarch64_cortex-a53 (push) Successful in 3m4s
build / x86_64 (push) Successful in 3m1s
feat(ops): backup/restore, config profiles, schema migration, xray-compat [MVP/T1/T2]
- backup.go: `backup` (tar.gz of /etc/config/shater + sub caches + manifest, to
  stdout or --file); `restore` validates the STAGED config with xray -test BEFORE
  swapping, snapshots the current config as .pre-restore, swaps atomically,
  migrates forward, and applies with commit-confirm (bad restore can't brick mgmt).
  untarInto rejects path traversal (Zip-Slip guard).
- profile.go: named config snapshots under /etc/xray/profiles/<name>.tar.gz;
  save|list|switch|delete; switch reuses the restore safety path + records active.
- migrate.go: ordered idempotent UCI schema migrations (CurrentSchemaVersion=1;
  v0→v1 folds legacy globals.kill→kill_switch); refuses a newer schema; injectable
  uciRunner for hermetic tests. ensureGlobals() creates the named globals section
  when absent so option writes never fail.
- compat.go: detect xray version vs the feature set the config uses (reality/
  vision/xhttp/observatory/fakeip) with a semver check; surfaced in status too.
- model/uci: Globals.SchemaVersion + ActiveProfile. main.go: 5 new commands.
- shater-core: migrate before reconcile (init.d/shater) + on upgrade (uci-defaults);
  config ships schema_version '1'.
- LuCI: profiles.js rewritten into Backup/Restore + Config profiles + xray
  compatibility cards; shater.uc +7 ubus methods + acl; menu retitled.
- tests: ops_test.go (backup round-trip, traversal reject, restore reject
  non-backup/newer-schema, migrate transform/idempotent/refuse-newer, semverGE,
  requiredFeatures, profile save/list/delete, sanitizeProfile).

Verified live on the 512M VM: backup→change→restore reverts loglevel (rc0,
mgmt survives); migrate 0→1 folds kill→kill_switch; profile switch tracks active;
compat reports 25.1.30 ok; all 7 ubus methods registered + return valid JSON. r13.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 15:54:36 +03:00

58 lines
1.8 KiB
Makefile

#
# OpenWrt package Makefile for xrayctl — the xray control-plane daemon.
# Cross-compiled through the OpenWrt SDK against musl (golang-package.mk).
#
# Absolute path to THIS package's directory (robust for src-link feeds), captured
# before any include changes $(MAKEFILE_LIST).
XRAYCTL_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
include $(TOPDIR)/rules.mk
PKG_NAME:=xrayctl
PKG_VERSION:=0.1.0
PKG_RELEASE:=13
PKG_MAINTAINER:=shater
PKG_LICENSE:=MIT
# Build from the source tree shipped alongside this Makefile (no remote tarball).
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
# Go import path == module name (see go.mod: `module xrayctl`).
GO_PKG:=xrayctl
PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_FLAGS:=no-mips16
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
define Package/xrayctl
SECTION:=net
CATEGORY:=Network
TITLE:=xray control-plane (UCI -> xray JSON + nft + policy-routing)
URL:=https://github.com/shater/xrayctl
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
endef
define Package/xrayctl/description
xrayctl reads the UCI desired-state (/etc/config/xray), renders an xray JSON
config, an nftables tproxy table (inet shater) and policy-routing, then applies
them atomically with commit-confirm/rollback. Subscriptions, multi-hop chains,
balancer+observatory, per-client/domain/geo routing and DNS split.
endef
# Copy the local Go sources into the build dir before compiling.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) $(XRAYCTL_DIR)*.go $(XRAYCTL_DIR)go.mod $(PKG_BUILD_DIR)/
endef
define Package/xrayctl/install
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/xrayctl $(1)/usr/bin/xrayctl
endef
$(eval $(call GoBinPackage,xrayctl))
$(eval $(call BuildPackage,xrayctl))