#!/bin/bash set -euo pipefail cd "$(dirname "$0")" NO_START=0 for arg in "$@"; do case "$arg" in --no-start) NO_START=1 ;; -h|--help) echo 'Usage: sudo ./install.sh [--no-start]'; exit 0 ;; *) echo "ERROR: unknown option: $arg (hardware is installed separately)" >&2; exit 2 ;; esac done for required in app/pigway_pi_control.py app/plugin_api.py app/pigway_pi_control_api.py web/index.html config/pigway-pi-control.conf systemd/pigway-pi-control.service systemd/pigway-pi-control-api.service; do [ -f "$required" ] || { echo "ERROR: required file missing: $required" >&2; exit 1; } done [ "$(id -u)" -eq 0 ] || { echo 'ERROR: run installer as root' >&2; exit 1; } # The monitor has no I2C, GPIO, Pillow, smbus2 or cooling-board requirement. command -v python3 >/dev/null || { apt-get update; apt-get install -y python3; } mkdir -p /usr/local/share/pigway-pi-control/web install -m 0644 app/plugin_api.py /usr/local/share/pigway-pi-control/plugin_api.py install -m 0644 web/index.html /usr/local/share/pigway-pi-control/web/index.html install -m 0755 app/pigway_pi_control.py /usr/local/sbin/pigway-pi-control install -m 0755 app/pigway_pi_control_api.py /usr/local/sbin/pigway-pi-control-api if [ -f /etc/pigway-pi-control.conf ]; then cp /etc/pigway-pi-control.conf "/etc/pigway-pi-control.conf.bak.$(date +%Y%m%d-%H%M%S)" else install -m 0644 config/pigway-pi-control.conf /etc/pigway-pi-control.conf fi # Legacy hardware sections are deliberately preserved for explicit migration, # but ignored by the monitor and never exposed as monitor configuration. python3 - <<'PY' from pathlib import Path import configparser p=Path('/etc/pigway-pi-control.conf');c=configparser.ConfigParser();c.read(p) with p.open('a') as f: for section,values in {'device':{'identifier':'auto','name':'auto'},'hosts':{},'plugins':{},'api':{'bind':'0.0.0.0','port':'6001','log_limit':'200'}}.items(): if not c.has_section(section): f.write('\n['+section+']\n'+''.join(k+' = '+v+'\n' for k,v in values.items())) PY if [ ! -s /etc/pigway-pi-control-api.token ]; then (umask 077; python3 -c 'import secrets; print(secrets.token_urlsafe(32))' > /etc/pigway-pi-control-api.token) fi chmod 0600 /etc/pigway-pi-control-api.token install -m 0644 systemd/pigway-pi-control.service /etc/systemd/system/ install -m 0644 systemd/pigway-pi-control-api.service /etc/systemd/system/ systemctl daemon-reload if [ "$NO_START" -eq 0 ]; then systemctl enable pigway-pi-control.service pigway-pi-control-api.service >/dev/null systemctl restart pigway-pi-control.service pigway-pi-control-api.service systemctl is-active --quiet pigway-pi-control.service systemctl is-active --quiet pigway-pi-control-api.service fi echo 'Monitor installed. Hardware plugins are installed and connected separately.' echo 'Config: /etc/pigway-pi-control.conf' echo 'API token: sudo cat /etc/pigway-pi-control-api.token'