Files
meshcore-phone-mode/install.sh
T
zorruno 593f86e6dd Configure full MQTT topics in the private INI
Use configured topics for commands, state, availability and Last Will. Replace shared installation prefixes with generic examples. Validate configuration before stopping an existing service; add tests for custom and invalid topics.
2026-10-03 15:31:08 +13:00

38 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# Zorruno — MeshCore Phone App Mode v1.1 — 2026-10-03
# Install on the Docker host; preserves an existing credentials file and leaves the
# service stopped until you have entered credentials and explicitly started it.
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo 'Run with sudo: sudo bash install.sh' >&2
exit 1
fi
source_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
command -v docker >/dev/null
docker inspect meshcore-webui >/dev/null
apt-get update
apt-get install -y python3-venv
install -d -m 0755 /opt/meshcore-phone-mode
python3 -m venv /opt/meshcore-phone-mode/venv
/opt/meshcore-phone-mode/venv/bin/python -m pip install -r "$source_dir/requirements.txt"
if [ ! -e /etc/meshcore-phone-mode.ini ]; then
install -m 0600 "$source_dir/meshcore-phone-mode.ini.example" /etc/meshcore-phone-mode.ini
fi
# Validate with the new code before stopping or replacing an existing controller.
python3 - "$source_dir/controller.py" <<'PY'
import runpy
import sys
runpy.run_path(sys.argv[1])["load_config"]("/etc/meshcore-phone-mode.ini")
PY
if systemctl is-active --quiet meshcore-phone-mode.service; then
systemctl stop meshcore-phone-mode.service
fi
install -m 0644 "$source_dir/controller.py" /opt/meshcore-phone-mode/controller.py
install -m 0644 "$source_dir/requirements.txt" /opt/meshcore-phone-mode/requirements.txt
install -m 0644 "$source_dir/meshcore-phone-mode.service" /etc/systemd/system/meshcore-phone-mode.service
systemctl daemon-reload
echo 'Upgrading from 1.0? Add command_topic, state_topic and availability_topic under [mqtt].'
echo 'Use your existing full topics to preserve the current Home Assistant switch.'
echo 'Installed. Edit /etc/meshcore-phone-mode.ini locally, then run:'
echo 'sudo systemctl enable --now meshcore-phone-mode.service'