chore: add Makefile and Debian packaging

This commit is contained in:
2026-05-24 18:53:11 +03:00
parent 2c49e7e427
commit 4a4aaee884
7 changed files with 183 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
BINARY := ezcoo-usb-control
VERSION ?= 0.1.0
CMD := ./cmd/$(BINARY)
BUILD_DIR := build
DIST_DIR := dist
DEB_TARGETS := arm64 armhf amd64
.PHONY: build deb-all $(addprefix deb-,$(DEB_TARGETS)) clean deps prepare lint
deps:
go mod tidy
prepare: deps
go mod download
go generate ./...
lint: prepare
gofmt -w -s .
goimports -w .
go vet ./...
golangci-lint run --color always
build: prepare
mkdir -p $(BUILD_DIR)
go build -o $(BUILD_DIR)/$(BINARY) $(CMD)
# ── Per-architecture .deb builder ─────────────────────────────────────────────
# $(1) = Debian arch (arm64 / armhf / amd64)
# $(2) = GOARCH (arm64 / arm / amd64)
# $(3) = GOARM (7 for armhf, empty otherwise)
define make_deb
$(eval BIN := $(BUILD_DIR)/$(BINARY)-$(1))
$(eval PKG_DIR := $(BUILD_DIR)/pkg-$(1))
$(eval DEB_OUT := $(DIST_DIR)/$(BINARY)_$(VERSION)_$(1).deb)
$(eval GO_ENV := GOOS=linux GOARCH=$(2)$(if $(3), GOARM=$(3),))
mkdir -p $(BUILD_DIR) $(DIST_DIR)
$(GO_ENV) go build -o $(BIN) $(CMD)
rm -rf $(PKG_DIR)
install -D -m 0755 $(BIN) $(PKG_DIR)/usr/bin/$(BINARY)
install -D -m 0640 cmd/ezcoo-usb-control/config.example.yaml $(PKG_DIR)/etc/$(BINARY)/config.yaml
install -D -m 0644 packaging/systemd/$(BINARY).service $(PKG_DIR)/lib/systemd/system/$(BINARY).service
install -d $(PKG_DIR)/DEBIAN
sed -e 's/VERSION_PLACEHOLDER/$(VERSION)/' \
-e 's/ARCH_PLACEHOLDER/$(1)/' \
packaging/DEBIAN/control > $(PKG_DIR)/DEBIAN/control
install -m 0644 packaging/DEBIAN/conffiles $(PKG_DIR)/DEBIAN/conffiles
install -m 0755 packaging/DEBIAN/postinst $(PKG_DIR)/DEBIAN/postinst
install -m 0755 packaging/DEBIAN/prerm $(PKG_DIR)/DEBIAN/prerm
install -m 0755 packaging/DEBIAN/postrm $(PKG_DIR)/DEBIAN/postrm
dpkg-deb --build --root-owner-group $(PKG_DIR) $(DEB_OUT)
rm -rf $(PKG_DIR)
@echo "$(DEB_OUT)"
endef
deb-arm64:
$(call make_deb,arm64,arm64,)
deb-armhf:
$(call make_deb,armhf,arm,7)
deb-amd64:
$(call make_deb,amd64,amd64,)
deb-all: $(addprefix deb-,$(DEB_TARGETS))
@echo ""
@echo "Built packages:"
@ls -lh $(DIST_DIR)/$(BINARY)_$(VERSION)_*.deb
clean:
rm -rf $(BUILD_DIR) $(DIST_DIR)
+1
View File
@@ -0,0 +1 @@
/etc/ezcoo-usb-control/config.yaml
+14
View File
@@ -0,0 +1,14 @@
Package: ezcoo-usb-control
Version: VERSION_PLACEHOLDER
Architecture: ARCH_PLACEHOLDER
Maintainer: Oleksandr Berezovskyi <claude.ai@berezovskyi.dev>
Depends: adduser
Recommends: mosquitto-clients
Description: MQTT bridge for EZCOO HDMI matrix switches
Controls an EZCOO EZ-MX42HAS-ARC (4-in 2-out) HDMI matrix via USB-UART
and exposes it to Home Assistant as two select entities through MQTT
auto-discovery.
.
Communicates with the matrix using the EZCOO ASCII serial protocol and
periodically polls routing state to detect external changes (front panel,
IR remote).
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
set -e
case "$1" in
configure)
# Create system user if it doesn't exist.
if ! id -u ezcoo > /dev/null 2>&1; then
adduser --system --no-create-home --shell /usr/sbin/nologin \
--group --gecos "EZCOO HDMI matrix bridge" ezcoo
fi
# Ensure the user is in the dialout group for serial access.
if getent group dialout > /dev/null 2>&1; then
adduser ezcoo dialout
fi
# Lock down the config directory so only ezcoo can read credentials.
chown -R root:ezcoo /etc/ezcoo-usb-control
chmod 750 /etc/ezcoo-usb-control
chmod 640 /etc/ezcoo-usb-control/config.yaml
;;
esac
if [ -d /run/systemd/system ]; then
systemctl daemon-reload
systemctl enable ezcoo-usb-control.service
# Only start automatically on fresh installs, not upgrades.
if [ "$1" = "configure" ] && [ -z "$2" ]; then
systemctl start ezcoo-usb-control.service || true
fi
fi
#DEBHELPER#
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
set -e
case "$1" in
purge)
rm -rf /etc/ezcoo-usb-control
if id -u ezcoo > /dev/null 2>&1; then
deluser --quiet ezcoo || true
fi
if getent group ezcoo > /dev/null 2>&1; then
delgroup --quiet ezcoo || true
fi
if [ -d /run/systemd/system ]; then
systemctl daemon-reload
fi
;;
esac
#DEBHELPER#
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
set -e
case "$1" in
remove|upgrade|deconfigure)
if [ -d /run/systemd/system ]; then
systemctl stop ezcoo-usb-control.service || true
systemctl disable ezcoo-usb-control.service || true
fi
;;
esac
#DEBHELPER#
@@ -0,0 +1,26 @@
[Unit]
Description=EZCOO HDMI Matrix MQTT bridge
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/ezcoo-usb-control --config /etc/ezcoo-usb-control/config.yaml
Restart=on-failure
RestartSec=5
User=ezcoo
SupplementaryGroups=dialout
# Allow reading an optional environment file for secrets.
# EnvironmentFile=-/etc/ezcoo-usb-control/env
# Hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
DeviceAllow=char-ttyUSB rw
DeviceAllow=char-ttyACM rw
[Install]
WantedBy=multi-user.target