From dfdf6a550e2517eb87c7305a0457846c8bc8e69c Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 25 May 2026 23:22:31 +0200 Subject: [PATCH] install.sh: create venv and install dependencies Creates .venv/ with python3 -m venv if not present, then installs/ updates requirements.txt into it before setting up the systemd service. The service ExecStart always uses the venv Python. Co-Authored-By: Claude Sonnet 4.6 --- install.sh | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/install.sh b/install.sh index ce72c81..1c3435b 100755 --- a/install.sh +++ b/install.sh @@ -22,20 +22,29 @@ SYSTEMD_DIR="$HOME/.config/systemd/user" SERVICE_FILE="$SYSTEMD_DIR/$SERVICE_NAME.service" LOG_DIR="$SCRIPT_DIR/logs" -# Prefer project venv, fall back to system python3 -if [[ -x "$SCRIPT_DIR/.venv/bin/python" ]]; then - PYTHON="$SCRIPT_DIR/.venv/bin/python" -else - PYTHON="$(command -v python3)" -fi +VENV="$SCRIPT_DIR/.venv" +PYTHON="$VENV/bin/python" echo "==> we_monitor installer" echo " Project : $SCRIPT_DIR" -echo " Python : $PYTHON" echo " User : $USER" echo "" -# ── 1. credentials template ─────────────────────────────────────────────────── +# ── 1. virtual environment ──────────────────────────────────────────────────── +if [[ ! -x "$PYTHON" ]]; then + echo "==> Creating virtual environment : $VENV" + python3 -m venv "$VENV" +else + echo "==> Virtual environment exists : $VENV" +fi + +echo "==> Installing / updating dependencies" +"$VENV/bin/pip" install --quiet --upgrade pip +"$VENV/bin/pip" install --quiet -r "$SCRIPT_DIR/requirements.txt" +echo " Python : $PYTHON" +echo "" + +# ── 2. credentials template ─────────────────────────────────────────────────── mkdir -p "$CREDS_DIR" chmod 700 "$CREDS_DIR" @@ -55,11 +64,11 @@ else echo "==> Credentials file exists : $CREDS_FILE" fi -# ── 2. log directory ────────────────────────────────────────────────────────── +# ── 3. log directory ────────────────────────────────────────────────────────── mkdir -p "$LOG_DIR" echo "==> Log directory : $LOG_DIR" -# ── 3. systemd user service ─────────────────────────────────────────────────── +# ── 4. systemd user service ─────────────────────────────────────────────────── mkdir -p "$SYSTEMD_DIR" cat > "$SERVICE_FILE" < Installed service unit : $SERVICE_FILE" -# ── 4. enable linger (service survives logout / starts at boot) ─────────────── +# ── 5. enable linger (service survives logout / starts at boot) ─────────────── if loginctl enable-linger "$USER" 2>/dev/null; then echo "==> Linger enabled for $USER (service starts at boot)" else @@ -92,7 +101,7 @@ else echo " Run as root to fix: loginctl enable-linger $USER" fi -# ── 5. reload and enable (but do NOT start yet) ─────────────────────────────── +# ── 6. reload and enable (but do NOT start yet) ─────────────────────────────── systemctl --user daemon-reload systemctl --user enable "$SERVICE_NAME"