#!/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}" <