Fixed dnf and issues for almalinux / rhel dervied systems, added bc as a prerequisite

This commit is contained in:
Muhammad Ibrahim
2025-10-01 12:50:55 +01:00
parent 42f882c1c6
commit d13469ce33
2 changed files with 67 additions and 15 deletions

View File

@@ -644,16 +644,31 @@ get_yum_packages() {
fi fi
# Get upgradable packages # Get upgradable packages
local upgradable=$($package_manager check-update 2>/dev/null | grep -v "^$" | grep -v "^Loaded" | grep -v "^Last metadata" | tail -n +2) local upgradable=$($package_manager check-update 2>/dev/null | grep -v "^$" | grep -v "^Loaded" | grep -v "^Last metadata" | grep -v "^Security" | tail -n +2)
while IFS= read -r line; do while IFS= read -r line; do
# Skip empty lines and lines with special characters
[[ -z "$line" ]] && continue
[[ "$line" =~ ^[[:space:]]*$ ]] && continue
if [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+) ]]; then if [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+) ]]; then
local package_name="${BASH_REMATCH[1]}" local package_name="${BASH_REMATCH[1]}"
local available_version="${BASH_REMATCH[2]}" local available_version="${BASH_REMATCH[2]}"
local repo="${BASH_REMATCH[3]}" local repo="${BASH_REMATCH[3]}"
# Sanitize package name and versions (remove any control characters)
package_name=$(echo "$package_name" | tr -d '[:cntrl:]' | sed 's/[^a-zA-Z0-9._+-]//g')
available_version=$(echo "$available_version" | tr -d '[:cntrl:]' | sed 's/[^a-zA-Z0-9._+-]//g')
repo=$(echo "$repo" | tr -d '[:cntrl:]')
# Skip if package name is empty after sanitization
[[ -z "$package_name" ]] && continue
# Get current version # Get current version
local current_version=$($package_manager list installed "$package_name" 2>/dev/null | grep "^$package_name" | awk '{print $2}') local current_version=$($package_manager list installed "$package_name" 2>/dev/null | grep "^$package_name" | awk '{print $2}' | tr -d '[:cntrl:]' | sed 's/[^a-zA-Z0-9._+-]//g')
# Skip if we couldn't get current version
[[ -z "$current_version" ]] && current_version="unknown"
local is_security_update=false local is_security_update=false
if echo "$repo" | grep -q "security"; then if echo "$repo" | grep -q "security"; then
@@ -674,10 +689,22 @@ get_yum_packages() {
local installed=$($package_manager list installed 2>/dev/null | grep -v "^Loaded" | grep -v "^Installed" | head -100) local installed=$($package_manager list installed 2>/dev/null | grep -v "^Loaded" | grep -v "^Installed" | head -100)
while IFS= read -r line; do while IFS= read -r line; do
# Skip empty lines
[[ -z "$line" ]] && continue
[[ "$line" =~ ^[[:space:]]*$ ]] && continue
if [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+) ]]; then if [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+) ]]; then
local package_name="${BASH_REMATCH[1]}" local package_name="${BASH_REMATCH[1]}"
local version="${BASH_REMATCH[2]}" local version="${BASH_REMATCH[2]}"
# Sanitize package name and version
package_name=$(echo "$package_name" | tr -d '[:cntrl:]' | sed 's/[^a-zA-Z0-9._+-]//g')
version=$(echo "$version" | tr -d '[:cntrl:]' | sed 's/[^a-zA-Z0-9._+-]//g')
# Skip if package name is empty after sanitization
[[ -z "$package_name" ]] && continue
[[ -z "$version" ]] && version="unknown"
# Check if this package is not in the upgrade list # Check if this package is not in the upgrade list
if ! echo "$upgradable" | grep -q "^$package_name "; then if ! echo "$upgradable" | grep -q "^$package_name "; then
if [[ "$first_ref" == true ]]; then if [[ "$first_ref" == true ]]; then

View File

@@ -129,31 +129,56 @@ echo ""
# Install required dependencies # Install required dependencies
info "📦 Installing required dependencies..." info "📦 Installing required dependencies..."
echo ""
# Detect package manager and install jq and curl # Detect package manager and install jq and curl
if command -v apt-get >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1; then
# Debian/Ubuntu # Debian/Ubuntu
info "Detected apt-get (Debian/Ubuntu)"
echo ""
info "Updating package lists..."
apt-get update apt-get update
apt-get install jq curl -y echo ""
elif command -v yum info "Installing jq, curl, and bc..."
apt-get install jq curl bc -y
elif command -v yum >/dev/null 2>&1; then
# CentOS/RHEL 7 # CentOS/RHEL 7
yum install -y jq curl info "Detected yum (CentOS/RHEL 7)"
elif command -v dnf echo ""
info "Installing jq, curl, and bc..."
yum install -y jq curl bc
elif command -v dnf >/dev/null 2>&1; then
# CentOS/RHEL 8+/Fedora # CentOS/RHEL 8+/Fedora
dnf install -y jq curl info "Detected dnf (CentOS/RHEL 8+/Fedora)"
elif command -v zypper echo ""
info "Installing jq, curl, and bc..."
dnf install -y jq curl bc
elif command -v zypper >/dev/null 2>&1; then
# openSUSE # openSUSE
zypper install -y jq curl info "Detected zypper (openSUSE)"
elif command -v pacman echo ""
info "Installing jq, curl, and bc..."
zypper install -y jq curl bc
elif command -v pacman >/dev/null 2>&1; then
# Arch Linux # Arch Linux
pacman -S --noconfirm jq curl info "Detected pacman (Arch Linux)"
elif command -v apk echo ""
info "Installing jq, curl, and bc..."
pacman -S --noconfirm jq curl bc
elif command -v apk >/dev/null 2>&1; then
# Alpine Linux # Alpine Linux
apk add --no-cache jq curl info "Detected apk (Alpine Linux)"
echo ""
info "Installing jq, curl, and bc..."
apk add --no-cache jq curl bc
else else
warning "Could not detect package manager. Please ensure 'jq' and 'curl' are installed manually." warning "Could not detect package manager. Please ensure 'jq', 'curl', and 'bc' are installed manually."
fi fi
echo ""
success "Dependencies installation completed"
echo ""
# Step 1: Handle existing configuration directory # Step 1: Handle existing configuration directory
info "📁 Setting up configuration directory..." info "📁 Setting up configuration directory..."
@@ -322,7 +347,7 @@ echo ""
echo -e "${GREEN}📋 Installation Summary:${NC}" echo -e "${GREEN}📋 Installation Summary:${NC}"
echo " • Configuration directory: /etc/patchmon" echo " • Configuration directory: /etc/patchmon"
echo " • Agent installed: /usr/local/bin/patchmon-agent.sh" echo " • Agent installed: /usr/local/bin/patchmon-agent.sh"
echo " • Dependencies installed: jq, curl" echo " • Dependencies installed: jq, curl, bc"
echo " • Crontab configured for automatic updates" echo " • Crontab configured for automatic updates"
echo " • API credentials configured and tested" echo " • API credentials configured and tested"