Simplify installer for modern approach - remove version-specific duplications

Co-authored-by: ShaYmez <76499782+ShaYmez@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-14 00:41:08 +00:00
parent 0246fe7c27
commit 73cceaf444
2 changed files with 55 additions and 84 deletions

View File

@ -146,15 +146,13 @@ Within this installation includes the new HBMonv2 by Weldek SP2ONG
### Technical Details - Python Package Management ### Technical Details - Python Package Management
**Debian 12+ (Bookworm/Trixie):** The installer uses modern Python package management following PEP 668 standards: The installer uses modern Python package management following PEP 668 standards for all supported Debian versions:
- HBMonv2 runs in an isolated Python virtual environment at `/opt/HBMonv2/venv` - HBMonv2 runs in an isolated Python virtual environment at `/opt/HBMonv2/venv`
- All Python dependencies are installed within this virtual environment, avoiding system-wide package conflicts - All Python dependencies are installed within this virtual environment, avoiding system-wide package conflicts
- The systemd service automatically uses the virtual environment's Python interpreter - The systemd service automatically uses the virtual environment's Python interpreter
- This approach eliminates "externally-managed-environment" errors and conflicts with system packages - This approach eliminates "externally-managed-environment" errors and conflicts with system packages
**Debian 11:** Standard pip installation to system Python is used for backward compatibility, as PEP 668 restrictions don't apply to Debian 11. This ensures clean, maintainable installations that follow modern Python best practices across all Debian versions.
This ensures clean, maintainable installations that follow modern Python best practices while maintaining compatibility with older Debian versions.
## Easy Installation And Upgrade ## Easy Installation And Upgrade
The installation can be upgraded either by the use of a future scripts or by manually backing up your configuration and re-running the install script. Also the ability and really cool feature of docker-compose is that its easy to update the container with fresh images! Run by a simple command. Make sure you are in the /etc/hblink3 dir. The installation can be upgraded either by the use of a future scripts or by manually backing up your configuration and re-running the install script. Also the ability and really cool feature of docker-compose is that its easy to update the container with fresh images! Run by a simple command. Make sure you are in the /etc/hblink3 dir.

View File

@ -53,17 +53,11 @@ LOCAL_IP=$(ip a | grep inet | grep "eth0\|en" | awk '{print $2}' | tr '/' ' ' |
EXTERNAL_IP=$(curl -s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null || echo "Unable to detect") EXTERNAL_IP=$(curl -s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null || echo "Unable to detect")
ARC=$(lscpu | grep Arch | awk '{print $2}') ARC=$(lscpu | grep Arch | awk '{print $2}')
VERSION=$(sed 's/\..*//' /etc/debian_version) VERSION=$(sed 's/\..*//' /etc/debian_version)
ARMv7l=https://get.docker.com | sh
ARMv8l=https://get.docker.com | sh
X32=https://get.docker.com | sh
X64=https://get.docker.com | sh
INSDIR=/opt/tmp/ INSDIR=/opt/tmp/
HBLINKTMP=/opt/tmp/hblink3 HBLINKTMP=/opt/tmp/hblink3
HBMONDIR=/opt/HBMonv2/ HBMONDIR=/opt/HBMonv2/
HBDIR=/etc/hblink3/ HBDIR=/etc/hblink3/
DEP="wget curl git sudo python3 python3-dev python3-pip libffi-dev libssl-dev conntrack sed cargo apache2 php snapd figlet ca-certificates gnupg lsb-release" DEP="wget curl git sudo python3 python3-dev python3-pip python3-venv libffi-dev libssl-dev conntrack sed cargo apache2 php snapd figlet ca-certificates gnupg lsb-release"
DEP1="wget curl git sudo python3 python3-dev python3-pip libffi-dev libssl-dev conntrack sed cargo apache2 php snapd figlet ca-certificates gnupg lsb-release"
DEP2="wget sudo curl git python3 python3-dev python3-pip libffi-dev libssl-dev conntrack sed cargo apache2 php php-mysqli snapd figlet ca-certificates gnupg lsb-release"
HBGITREPO=https://github.com/ShaYmez/hblink3.git HBGITREPO=https://github.com/ShaYmez/hblink3.git
HBGITMONREPO=https://github.com/ShaYmez/HBMonv2.git HBGITMONREPO=https://github.com/ShaYmez/HBMonv2.git
echo "" echo ""
@ -75,14 +69,10 @@ install_docker_and_dependencies() {
local version=$1 local version=$1
echo "Detected Debian version: $version" echo "Detected Debian version: $version"
# Install base dependencies # Install base dependencies (python3-venv is included for all versions for consistency)
echo "Installing dependencies..."
apt-get update apt-get update
# For Debian 12+, add python3-venv to dependencies (PEP 668 compliance) apt-get install -y $DEP
if [ $version -ge 12 ]; then
apt-get install -y $DEP python3-venv
else
apt-get install -y $DEP
fi
sleep 2 sleep 2
# Remove old Docker versions if present # Remove old Docker versions if present
@ -262,64 +252,49 @@ echo "Installing HBMonv2 configuration....."
echo "------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------"
sleep 2 sleep 2
# Helper function to install pip packages with Debian 12+ compatibility # Helper function to install pip packages in virtual environment
pip_install() { pip_install() {
local args="$@" local args="$@"
if [ $VERSION -ge 12 ]; then echo "Installing Python packages: $args"
# For Debian 12+, use virtual environment (PEP 668 compliant) if [ -z "$VIRTUAL_ENV" ]; then
echo "Installing Python packages for Debian $VERSION: $args" echo "ERROR: Virtual environment not activated"
if [ -z "$VIRTUAL_ENV" ]; then return 1
echo "ERROR: Virtual environment not activated" fi
return 1 if pip3 install $args; then
fi echo "Successfully installed: $args"
if pip3 install $args; then return 0
echo "Successfully installed: $args"
return 0
else
echo "ERROR: Failed to install: $args"
return 1
fi
else else
# For Debian 11, use standard pip installation (pre-PEP 668) echo "ERROR: Failed to install: $args"
echo "Installing Python packages for Debian $VERSION: $args" return 1
if pip3 install $args; then
echo "Successfully installed: $args"
return 0
else
echo "ERROR: Failed to install: $args"
return 1
fi
fi fi
} }
echo "Installing Python dependencies..." echo "Installing Python dependencies..."
cd $HBMONDIR cd $HBMONDIR
# For Debian 12+, create and use a virtual environment (modern PEP 668 compliant approach) # Create and use a virtual environment (modern approach for all Debian versions)
if [ $VERSION -ge 12 ]; then echo "Creating Python virtual environment..."
echo "Creating Python virtual environment for Debian $VERSION..."
# Create virtual environment # Create virtual environment
if [ ! -d "$HBMONDIR/venv" ]; then if [ ! -d "$HBMONDIR/venv" ]; then
python3 -m venv "$HBMONDIR/venv" || { echo "ERROR: Failed to create virtual environment"; exit 1; } python3 -m venv "$HBMONDIR/venv" || { echo "ERROR: Failed to create virtual environment"; exit 1; }
echo "Virtual environment created successfully at $HBMONDIR/venv" echo "Virtual environment created successfully at $HBMONDIR/venv"
else else
echo "Virtual environment already exists at $HBMONDIR/venv" echo "Virtual environment already exists at $HBMONDIR/venv"
fi fi
# Activate virtual environment # Activate virtual environment
source "$HBMONDIR/venv/bin/activate" || { echo "ERROR: Failed to activate virtual environment"; exit 1; } source "$HBMONDIR/venv/bin/activate" || { echo "ERROR: Failed to activate virtual environment"; exit 1; }
# Verify activation by checking VIRTUAL_ENV is set # Verify activation by checking VIRTUAL_ENV is set
if [ -z "$VIRTUAL_ENV" ]; then if [ -z "$VIRTUAL_ENV" ]; then
echo "ERROR: Virtual environment activation failed - VIRTUAL_ENV not set" echo "ERROR: Virtual environment activation failed - VIRTUAL_ENV not set"
exit 1 exit 1
fi fi
echo "Virtual environment activated" echo "Virtual environment activated"
# Upgrade pip in the virtual environment # Upgrade pip in the virtual environment
if ! pip3 install --upgrade pip; then if ! pip3 install --upgrade pip; then
echo "WARNING: Failed to upgrade pip in virtual environment, continuing with existing version..." echo "WARNING: Failed to upgrade pip in virtual environment, continuing with existing version..."
fi
fi fi
# Install setuptools and wheel first # Install setuptools and wheel first
@ -401,25 +376,23 @@ LOG_NAME = 'hbmon.log'
EOF EOF
cp utils/hbmon.service /lib/systemd/system/ cp utils/hbmon.service /lib/systemd/system/
# For Debian 12+, update the service file to use virtual environment # Update the service file to use virtual environment (for all Debian versions)
if [ $VERSION -ge 12 ]; then echo "Updating hbmon.service to use virtual environment..."
echo "Updating hbmon.service to use virtual environment..." # Update ExecStart to use venv Python (only if not already using venv)
# Update ExecStart to use venv Python (only if not already using venv) if ! grep -q "$HBMONDIR/venv/bin/python3" /lib/systemd/system/hbmon.service; then
if ! grep -q "$HBMONDIR/venv/bin/python3" /lib/systemd/system/hbmon.service; then # Replace common Python interpreter paths with venv path
# Replace common Python interpreter paths with venv path sed -i "s|ExecStart=/usr/bin/python3|ExecStart=$HBMONDIR/venv/bin/python3|g" /lib/systemd/system/hbmon.service
sed -i "s|ExecStart=/usr/bin/python3|ExecStart=$HBMONDIR/venv/bin/python3|g" /lib/systemd/system/hbmon.service sed -i "s|ExecStart=python3 |ExecStart=$HBMONDIR/venv/bin/python3 |g" /lib/systemd/system/hbmon.service
sed -i "s|ExecStart=python3 |ExecStart=$HBMONDIR/venv/bin/python3 |g" /lib/systemd/system/hbmon.service
# Verify the service file was updated correctly # Verify the service file was updated correctly
if grep -q "ExecStart=$HBMONDIR/venv/bin/python3" /lib/systemd/system/hbmon.service; then if grep -q "ExecStart=$HBMONDIR/venv/bin/python3" /lib/systemd/system/hbmon.service; then
echo "Service file updated to use virtual environment" echo "Service file updated to use virtual environment"
else
echo "WARNING: Service file update may not have completed correctly"
echo "Please manually verify /lib/systemd/system/hbmon.service uses $HBMONDIR/venv/bin/python3"
fi
else else
echo "Service file already configured to use virtual environment" echo "WARNING: Service file update may not have completed correctly"
echo "Please manually verify /lib/systemd/system/hbmon.service uses $HBMONDIR/venv/bin/python3"
fi fi
else
echo "Service file already configured to use virtual environment"
fi fi
cp utils/lastheard /etc/cron.daily/ cp utils/lastheard /etc/cron.daily/