Files
oculog/clients/ubuntu/debian/postinst
2026-02-12 14:52:37 -06:00

56 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -e
# Post-installation script
echo "Configuring Oculog client..."
# Create directories
mkdir -p /var/log/oculog
mkdir -p /etc/oculog
# Install Python dependencies using system-managed approach
# Try to install via apt first (for newer Ubuntu versions)
if apt-cache show python3-psutil >/dev/null 2>&1 && apt-cache show python3-requests >/dev/null 2>&1; then
apt-get update -qq
if apt-get install -y -qq python3-psutil python3-requests >/dev/null 2>&1; then
PYTHON_BIN="/usr/bin/python3"
else
USE_VENV=1
fi
else
USE_VENV=1
fi
# If apt packages aren't available, use a virtual environment
if [ "$USE_VENV" = "1" ]; then
apt-get update -qq
apt-get install -y -qq python3-venv python3-pip >/dev/null 2>&1 || true
# Create virtual environment
python3 -m venv /opt/oculog/venv
# Install packages in virtual environment
/opt/oculog/venv/bin/pip install --quiet --upgrade pip
/opt/oculog/venv/bin/pip install --quiet psutil==5.9.6 requests==2.31.0
PYTHON_BIN="/opt/oculog/venv/bin/python3"
# Update shebang in client script
sed -i "1s|.*|#!${PYTHON_BIN}|" /opt/oculog/client.py
# Update systemd service to use venv Python
sed -i "s|ExecStart=.*|ExecStart=${PYTHON_BIN} /opt/oculog/client.py|" /etc/systemd/system/oculog-client.service
fi
# Enable and start service if config exists
if [ -f /etc/oculog/client.conf ]; then
systemctl daemon-reload
systemctl enable oculog-client.service 2>/dev/null || true
systemctl start oculog-client.service 2>/dev/null || true
fi
echo "Oculog client installed successfully!"
echo "Please configure /etc/oculog/client.conf before starting the service."
exit 0