mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-05 06:23:22 +00:00
agents: use apt-get simulation for Ubuntu 18 compatibility; fix installer log path
This commit is contained in:
@@ -550,21 +550,24 @@ get_apt_packages() {
|
|||||||
local -n packages_ref=$1
|
local -n packages_ref=$1
|
||||||
local -n first_ref=$2
|
local -n first_ref=$2
|
||||||
|
|
||||||
# Update package lists
|
# Update package lists (use apt-get for older distros; quieter output)
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
|
|
||||||
# Get upgradable packages
|
# Determine upgradable packages using apt-get simulation (compatible with Ubuntu 18.04)
|
||||||
local upgradable=$(apt list --upgradable 2>/dev/null | grep -v "WARNING")
|
# Example line format:
|
||||||
|
# Inst bash [4.4.18-2ubuntu1] (4.4.18-2ubuntu1.2 Ubuntu:18.04/bionic-updates [amd64])
|
||||||
|
local upgradable_sim=$(apt-get -s -o Debug::NoLocking=1 upgrade 2>/dev/null | grep "^Inst ")
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
if [[ "$line" =~ ^([^/]+)/([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+.*[[:space:]]([^[:space:]]+)[[:space:]]*(\[.*\])? ]]; then
|
# Extract package name, current version (in brackets), and available version (first token inside parentheses)
|
||||||
|
if [[ "$line" =~ ^Inst[[:space:]]+([^[:space:]]+)[[:space:]]+\[([^\]]+)\][[:space:]]+\(([^[:space:]]+) ]]; then
|
||||||
local package_name="${BASH_REMATCH[1]}"
|
local package_name="${BASH_REMATCH[1]}"
|
||||||
local current_version="${BASH_REMATCH[4]}"
|
local current_version="${BASH_REMATCH[2]}"
|
||||||
local available_version="${BASH_REMATCH[3]}"
|
local available_version="${BASH_REMATCH[3]}"
|
||||||
local is_security_update=false
|
local is_security_update=false
|
||||||
|
|
||||||
# Check if it's a security update
|
# Mark as security update if the line references a security pocket
|
||||||
if echo "$line" | grep -q "security"; then
|
if echo "$line" | grep -qiE "(-|/)security"; then
|
||||||
is_security_update=true
|
is_security_update=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -576,7 +579,7 @@ get_apt_packages() {
|
|||||||
|
|
||||||
packages_ref+="{\"name\":\"$package_name\",\"currentVersion\":\"$current_version\",\"availableVersion\":\"$available_version\",\"needsUpdate\":true,\"isSecurityUpdate\":$is_security_update}"
|
packages_ref+="{\"name\":\"$package_name\",\"currentVersion\":\"$current_version\",\"availableVersion\":\"$available_version\",\"needsUpdate\":true,\"isSecurityUpdate\":$is_security_update}"
|
||||||
fi
|
fi
|
||||||
done <<< "$upgradable"
|
done <<< "$upgradable_sim"
|
||||||
|
|
||||||
# Get installed packages that are up to date
|
# Get installed packages that are up to date
|
||||||
local installed=$(dpkg-query -W -f='${Package} ${Version}\n' | head -100)
|
local installed=$(dpkg-query -W -f='${Package} ${Version}\n' | head -100)
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ fi
|
|||||||
echo " • Config directory: /etc/patchmon/"
|
echo " • Config directory: /etc/patchmon/"
|
||||||
echo " • Credentials file: /etc/patchmon/credentials"
|
echo " • Credentials file: /etc/patchmon/credentials"
|
||||||
echo " • Automatic updates: Every $UPDATE_INTERVAL minutes via crontab"
|
echo " • Automatic updates: Every $UPDATE_INTERVAL minutes via crontab"
|
||||||
echo " • View logs: tail -f /var/log/patchmon-agent.sh"
|
echo " • View logs: tail -f /var/log/patchmon-agent.log"
|
||||||
echo ""
|
echo ""
|
||||||
echo "🔧 Manual commands:"
|
echo "🔧 Manual commands:"
|
||||||
echo " • Test connection: patchmon-agent.sh test"
|
echo " • Test connection: patchmon-agent.sh test"
|
||||||
|
|||||||
Reference in New Issue
Block a user