feat: add standalone capability-based cooling plugin
This commit is contained in:
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
NO_START=0
|
||||
IMPORT=''
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--no-start) NO_START=1; shift ;;
|
||||
--import-monitor-config) [ "$#" -ge 2 ] || exit 2; IMPORT="$2"; shift 2 ;;
|
||||
-h|--help) echo 'Usage: sudo ./install.sh [--no-start] [--import-monitor-config /etc/pigway-pi-control.conf]'; exit 0 ;;
|
||||
*) echo "ERROR: unknown option: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
for f in app/migrate.py app/service.py app/runtime.py app/settings.py app/drivers/yahboom.py app/oled_font_5x7.bin config/pigway-cooling-hat.conf systemd/pigway-cooling-hat.service; do
|
||||
[ -f "$f" ] || { echo "ERROR: required file missing: $f" >&2; exit 1; }
|
||||
done
|
||||
[ "$(id -u)" -eq 0 ] || { echo 'ERROR: run as root' >&2; exit 1; }
|
||||
[ -e /dev/i2c-1 ] || { echo 'ERROR: /dev/i2c-1 missing; configure I2C before installing this driver' >&2; exit 1; }
|
||||
# Never stop unrelated I2C users. A previous plugin instance is allowed on upgrade.
|
||||
owner="$(systemctl show -p MainPID --value pigway-cooling-hat.service 2>/dev/null || true)"
|
||||
for pid in $(fuser /dev/i2c-1 2>/dev/null || true); do
|
||||
[ "$pid" = "$owner" ] || { echo "ERROR: I2C already owned by PID $pid" >&2; exit 1; }
|
||||
done
|
||||
python3 -c 'import smbus2, PIL' 2>/dev/null || { apt-get update; apt-get install -y python3 python3-smbus2 python3-pil; }
|
||||
# Validate a possible migration before changing installed files.
|
||||
if [ -n "$IMPORT" ]; then PYTHONDONTWRITEBYTECODE=1 python3 app/migrate.py "$IMPORT" --check; fi
|
||||
getent group pigway-hardware >/dev/null || groupadd --system pigway-hardware
|
||||
mkdir -p /usr/local/lib/pigway-cooling-hat/drivers
|
||||
install -m 0644 app/*.py app/oled_font_5x7.bin /usr/local/lib/pigway-cooling-hat/
|
||||
install -m 0644 app/drivers/*.py /usr/local/lib/pigway-cooling-hat/drivers/
|
||||
if [ ! -f /etc/pigway-cooling-hat.conf ]; then
|
||||
install -m 0640 -g pigway-hardware config/pigway-cooling-hat.conf /etc/pigway-cooling-hat.conf
|
||||
fi
|
||||
if [ -n "$IMPORT" ]; then
|
||||
cp /etc/pigway-cooling-hat.conf "/etc/pigway-cooling-hat.conf.bak.$(date +%Y%m%d-%H%M%S)"
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 app/migrate.py "$IMPORT" --output /etc/pigway-cooling-hat.conf
|
||||
fi
|
||||
install -m 0644 systemd/pigway-cooling-hat.service /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
if [ "$NO_START" -eq 0 ]; then
|
||||
systemctl enable pigway-cooling-hat.service >/dev/null
|
||||
systemctl restart pigway-cooling-hat.service
|
||||
systemctl is-active --quiet pigway-cooling-hat.service
|
||||
fi
|
||||
echo 'Hardware plugin installed independently. No monitor service was changed.'
|
||||
echo 'Start if needed: sudo systemctl start pigway-cooling-hat.service'
|
||||
echo 'Discover and connect from the monitor Web hardware plugins page.'
|
||||
Reference in New Issue
Block a user