From 6a7cac5f867a23d06796b4dbb787c933f6f749a5 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 25 Jan 2026 17:57:08 -0500 Subject: [PATCH] Changed dependencies to use venv, installs service to opt for systemd compatibility, and added support for bazzite. --- .gitignore | 1 + install_as_service.sh | 51 ++++++++++++++++++++++++++++++++++++------- requirements.txt | 1 + run.sh | 16 ++++++++++++-- 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 1059bd4..f367725 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc fwledmonitor.service +venv/ \ No newline at end of file diff --git a/install_as_service.sh b/install_as_service.sh index eb5496a..dc9cf04 100644 --- a/install_as_service.sh +++ b/install_as_service.sh @@ -1,7 +1,31 @@ -sudo apt install python3-serial -chmod +x run.sh -rm -f fwledmonitor.service || true -cat <>./fwledmonitor.service +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +INSTALL_DIR="/opt/fw-led-monitor" + +echo "Installing to $INSTALL_DIR..." + +sudo mkdir -p "$INSTALL_DIR" +sudo cp "$SCRIPT_DIR/led_system_monitor.py" "$INSTALL_DIR/" +sudo cp "$SCRIPT_DIR/drawing.py" "$INSTALL_DIR/" +sudo cp "$SCRIPT_DIR/monitors.py" "$INSTALL_DIR/" +sudo cp "$SCRIPT_DIR/commands.py" "$INSTALL_DIR/" +sudo cp "$SCRIPT_DIR/requirements.txt" "$INSTALL_DIR/" +sudo cp "$SCRIPT_DIR/run.sh" "$INSTALL_DIR/" +sudo chmod +x "$INSTALL_DIR/run.sh" +sudo chown -R root:root "$INSTALL_DIR" + +VENV_DIR="$INSTALL_DIR/venv" +if [ ! -d "$VENV_DIR" ]; then + sudo python3 -m venv "$VENV_DIR" +fi + +sudo "$VENV_DIR/bin/pip" install --upgrade pip +sudo "$VENV_DIR/bin/pip" install -r "$INSTALL_DIR/requirements.txt" + +rm -f "$SCRIPT_DIR/fwledmonitor.service" || true +cat < "$SCRIPT_DIR/fwledmonitor.service" [Unit] Description=Framework 16 LED System Monitor After=network.service @@ -9,14 +33,25 @@ After=network.service [Service] Type=simple Restart=always -WorkingDirectory=$PWD -ExecStart=sh -c "'$PWD/run.sh'" +RestartSec=5 +WorkingDirectory=$INSTALL_DIR +ExecStart=/bin/bash $INSTALL_DIR/run.sh [Install] WantedBy=default.target EOF -sudo systemctl stop fwledmonitor -sudo cp fwledmonitor.service /lib/systemd/system +sudo systemctl stop fwledmonitor || true + +SERVICE_DIR="/etc/systemd/system" +if ! sudo cp "$SCRIPT_DIR/fwledmonitor.service" "$SERVICE_DIR" 2>/dev/null; then + SERVICE_DIR="/lib/systemd/system" + sudo cp "$SCRIPT_DIR/fwledmonitor.service" "$SERVICE_DIR" +fi + sudo systemctl daemon-reload sudo systemctl enable fwledmonitor + +echo "Installation complete. Service installed to $INSTALL_DIR" + +sudo service fwledmonitor start \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 06b9745..009a89a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pyserial numpy +psutil wmi # only for windows \ No newline at end of file diff --git a/run.sh b/run.sh index 3b39d42..695acb9 100644 --- a/run.sh +++ b/run.sh @@ -1,3 +1,15 @@ -sudo apt install python3-serial python3-numpy python3-psutil +#!/bin/bash +set -e -python3 ./led_system_monitor.py +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +VENV_DIR="$SCRIPT_DIR/venv" + +if [ ! -d "$VENV_DIR" ]; then + python3 -m venv "$VENV_DIR" +fi + +source "$VENV_DIR/bin/activate" +pip install --upgrade pip +pip install -r "$SCRIPT_DIR/requirements.txt" + +python "$SCRIPT_DIR/led_system_monitor.py"