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
**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`
- 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
- 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 while maintaining compatibility with older Debian versions.
This ensures clean, maintainable installations that follow modern Python best practices across all Debian versions.
## 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.

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")
ARC=$(lscpu | grep Arch | awk '{print $2}')
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/
HBLINKTMP=/opt/tmp/hblink3
HBMONDIR=/opt/HBMonv2/
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"
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"
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"
HBGITREPO=https://github.com/ShaYmez/hblink3.git
HBGITMONREPO=https://github.com/ShaYmez/HBMonv2.git
echo ""
@ -75,14 +69,10 @@ install_docker_and_dependencies() {
local version=$1
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
# For Debian 12+, add python3-venv to dependencies (PEP 668 compliance)
if [ $version -ge 12 ]; then
apt-get install -y $DEP python3-venv
else
apt-get install -y $DEP
fi
sleep 2
# Remove old Docker versions if present
@ -262,12 +252,10 @@ echo "Installing HBMonv2 configuration....."
echo "------------------------------------------------------------------------------"
sleep 2
# Helper function to install pip packages with Debian 12+ compatibility
# Helper function to install pip packages in virtual environment
pip_install() {
local args="$@"
if [ $VERSION -ge 12 ]; then
# For Debian 12+, use virtual environment (PEP 668 compliant)
echo "Installing Python packages for Debian $VERSION: $args"
echo "Installing Python packages: $args"
if [ -z "$VIRTUAL_ENV" ]; then
echo "ERROR: Virtual environment not activated"
return 1
@ -279,25 +267,13 @@ pip_install() {
echo "ERROR: Failed to install: $args"
return 1
fi
else
# For Debian 11, use standard pip installation (pre-PEP 668)
echo "Installing Python packages for Debian $VERSION: $args"
if pip3 install $args; then
echo "Successfully installed: $args"
return 0
else
echo "ERROR: Failed to install: $args"
return 1
fi
fi
}
echo "Installing Python dependencies..."
cd $HBMONDIR
# For Debian 12+, create and use a virtual environment (modern PEP 668 compliant approach)
if [ $VERSION -ge 12 ]; then
echo "Creating Python virtual environment for Debian $VERSION..."
# Create and use a virtual environment (modern approach for all Debian versions)
echo "Creating Python virtual environment..."
# Create virtual environment
if [ ! -d "$HBMONDIR/venv" ]; then
@ -320,7 +296,6 @@ if [ $VERSION -ge 12 ]; then
if ! pip3 install --upgrade pip; then
echo "WARNING: Failed to upgrade pip in virtual environment, continuing with existing version..."
fi
fi
# Install setuptools and wheel first
if ! pip_install setuptools wheel; then
@ -401,8 +376,7 @@ LOG_NAME = 'hbmon.log'
EOF
cp utils/hbmon.service /lib/systemd/system/
# For Debian 12+, update the service file to use virtual environment
if [ $VERSION -ge 12 ]; then
# Update the service file to use virtual environment (for all Debian versions)
echo "Updating hbmon.service to use virtual environment..."
# 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
@ -420,7 +394,6 @@ EOF
else
echo "Service file already configured to use virtual environment"
fi
fi
cp utils/lastheard /etc/cron.daily/
chmod +x /etc/cron.daily/lastheard