feat: make plugin integration opt-in
This commit is contained in:
+18
-1
@@ -3,11 +3,14 @@ set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
NO_START=0
|
||||
IMPORT=''
|
||||
INTEGRATION=''
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--enable-integration) INTEGRATION=true; shift ;;
|
||||
--disable-integration) INTEGRATION=false; shift ;;
|
||||
--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 ;;
|
||||
-h|--help) echo 'Usage: sudo ./install.sh [--no-start] [--enable-integration|--disable-integration] [--import-monitor-config /etc/pigway-pi-control.conf]'; exit 0 ;;
|
||||
*) echo "ERROR: unknown option: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
@@ -24,6 +27,13 @@ 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
|
||||
if [ -z "$INTEGRATION" ]; then
|
||||
INTEGRATION=false
|
||||
if [ -t 0 ]; then
|
||||
read -r -p 'Allow local monitor integration? [y/N] ' answer
|
||||
case "$answer" in y|Y|yes|YES) INTEGRATION=true ;; esac
|
||||
fi
|
||||
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/
|
||||
@@ -35,6 +45,13 @@ 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
|
||||
INTEGRATION="$INTEGRATION" PYTHONDONTWRITEBYTECODE=1 python3 - <<'PYCFG'
|
||||
import os,sys
|
||||
from pathlib import Path
|
||||
sys.path.insert(0,'app')
|
||||
from settings import load,save
|
||||
p=Path('/etc/pigway-cooling-hat.conf');c=load(p);c['integration']['enabled']=os.environ['INTEGRATION'];save(p,c)
|
||||
PYCFG
|
||||
install -m 0644 systemd/pigway-cooling-hat.service /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
if [ "$NO_START" -eq 0 ]; then
|
||||
|
||||
Reference in New Issue
Block a user