Files
lgtv/install.sh
T
Mortdecai 1699276e8e feat: consolidate LG TV bridge — cached IP discovery, robust WoL, systemd deploy
Rework the MQTT bridge into a single deployable unit:
- Drop the self-SSH hop; run locally on steel141 (on the TV's LAN, has
  bscpylgtv, effectively always-on).
- Cache last-known TV IP and probe it directly; /24 ping-sweep only on a
  cache miss. Stops the 30s HA state poll from flapping/spamming the net.
- WoL now unicast (last-known IP) + broadcast, ports 9/7, 3 bursts.
- systemd unit (User=seth, EnvironmentFile for MQTT_PASSWORD), install.sh,
  env template, .gitignore. Removes the half-finished lgtv.sh.new.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 19:29:01 -04:00

28 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Deploy the LG TV bridge on steel141. Idempotent — safe to re-run.
# Run as a user with sudo. Reads MQTT password from $HOMELAB_PASSWORD.
set -euo pipefail
cd "$(dirname "$0")"
echo "Installing control script + bridge to /usr/local/bin ..."
sudo install -m 0755 lgtv.sh /usr/local/bin/lgtv.sh
sudo install -m 0755 lgtv_mqtt.py /usr/local/bin/lgtv_mqtt.py
echo "Writing /etc/lgtv/lgtv.env (root:root 0600) ..."
sudo mkdir -p /etc/lgtv
if [[ -z "${HOMELAB_PASSWORD:-}" ]]; then
echo " WARNING: \$HOMELAB_PASSWORD not set — leaving existing env untouched." >&2
[[ -f /etc/lgtv/lgtv.env ]] || { echo " ERROR: no /etc/lgtv/lgtv.env exists; set HOMELAB_PASSWORD and re-run." >&2; exit 1; }
else
printf 'MQTT_PASSWORD=%s\n' "$HOMELAB_PASSWORD" | sudo tee /etc/lgtv/lgtv.env >/dev/null
sudo chmod 600 /etc/lgtv/lgtv.env
fi
echo "Installing systemd unit ..."
sudo install -m 0644 lgtv-mqtt.service /etc/systemd/system/lgtv-mqtt.service
sudo systemctl daemon-reload
sudo systemctl enable --now lgtv-mqtt.service
echo "Done. Status:"
systemctl --no-pager --full status lgtv-mqtt.service | head -12