Files
galahad2lcd/packaging/install.sh
T
Maksim Totmin 4c34f0bedc Initial commit: Go driver for the Lian Li Galahad II LCD
Streams H.264 to the Galahad II LCD via USB (gousb) with:
- ffmpeg CLI transcoding (no fragile FFmpeg C-ABI bindings)
- pure-Go Annex-B access-unit splitting
- framerate pacing with graceful shutdown and USB reconnect
- TOML config, cobra CLI, structured slog logging, unit tests
2026-08-19 12:03:54 +07:00

80 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Install galahad2lcd: build, install the binary, systemd unit, udev rule
# and (optionally) an initial configuration.
#
# Usage: sudo ./install.sh [/path/to/media.gif]
set -euo pipefail
APP=galahad2lcd
BINDIR=/usr/local/bin
SYSTEMD_DIR=/etc/systemd/system
UDEV_DIR=/etc/udev/rules.d
CONFIG_FILE=/etc/galahad2lcd.toml
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
info() { echo -e "\033[0;32m[+] $*\033[0m"; }
warn() { echo -e "\033[0;33m[!] $*\033[0m"; }
fail() { echo -e "\033[0;31m[-] $*\033[0m" >&2; exit 1; }
[[ $EUID -eq 0 ]] || fail "run as root (sudo $0 $*)"
if ! command -v go >/dev/null; then
fail "Go is required: sudo pacman -S go (or the equivalent for your distro)"
fi
info "building release binary"
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo dev)
go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o "${BINDIR}/${APP}" \
"${SCRIPT_DIR}/../cmd/galahad2lcd"
info "installing systemd unit"
install -m 0644 "${SCRIPT_DIR}/${APP}.service" "${SYSTEMD_DIR}/${APP}.service"
info "installing udev rule"
install -m 0644 "${SCRIPT_DIR}/99-${APP}.rules" "${UDEV_DIR}/99-${APP}.rules"
udevadm control --reload-rules 2>/dev/null || true
# Remove the legacy Rust-driver config file (/etc/default/galahad2lcd) if
# present; the new driver uses /etc/galahad2lcd.toml.
rm -f /etc/default/${APP}
if [[ ! -f "${CONFIG_FILE}" ]]; then
if [[ $# -ge 1 ]]; then
INPUT="$(realpath "$1")"
[[ -f "$INPUT" ]] || fail "file '$INPUT' does not exist"
info "writing initial configuration for $INPUT"
cat > "${CONFIG_FILE}" <<EOF
[display]
input = "${INPUT}"
rotate = 0
speed = 1.0
[usb]
vendor_id = 0x0416
product_id = 0x7395
[stream]
fps = 0
cache_path = "/tmp/galahad_cache.h264"
EOF
else
warn "no media file given; run 'sudo ${APP} set --input /path/to/media.gif' after install"
fi
fi
chmod 0644 "${CONFIG_FILE}"
info "reloading systemd and starting ${APP}"
systemctl daemon-reload
systemctl enable "${APP}"
systemctl restart "${APP}"
info "installation complete"
echo
echo " Change the media later with:"
echo " sudo ${APP} set --input /path/to/media.gif --rotate 0"
echo " Inspect USB devices with:"
echo " ${APP} list"
echo " View logs with:"
echo " journalctl -u ${APP} -f"