This commit is contained in:
2026-03-08 23:36:38 +01:00
parent d4cf1558d2
commit 579290044f
2 changed files with 10 additions and 10 deletions

View File

@@ -46,8 +46,8 @@ if (isset($_GET['update_json'])) {
$settings = modules()->settings('pi_control'); $settings = modules()->settings('pi_control');
$strictHostKey = !empty($settings['terminal_strict_hostkey']); $strictHostKey = !empty($settings['terminal_strict_hostkey']);
$updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; apt-get -s upgrade 2>/dev/null | grep \"^Inst \" || true'"; $updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; if sudo apt update -qq >/dev/null 2>&1; then count=$(apt-get -s dist-upgrade | grep -c \"^Inst \"); if [ \"$count\" -gt 0 ]; then echo \"__UPDATE__=1\"; else echo \"__UPDATE__=0\"; fi; echo \"__COUNT__=$count\"; else echo \"__ERR__APT_UPDATE\"; exit 3; fi'";
$upgradeCmd = "sh -lc 'current=\"$(. /etc/os-release 2>/dev/null && echo \"$VERSION_CODENAME\")\"; if [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2; exit}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; echo \"__CURRENT__=$current\"; echo \"__LATEST__=$latest\"; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'"; $upgradeCmd = "sh -lc 'id=\"$(. /etc/os-release 2>/dev/null && echo \"${ID:-}\")\"; current=\"$(. /etc/os-release 2>/dev/null && echo \"${VERSION_CODENAME:-}\")\"; if [ \"$id\" != \"debian\" ] || [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'";
[$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20); [$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20);
$updOutStr = (string)$updOut; $updOutStr = (string)$updOut;
@@ -55,9 +55,9 @@ if (isset($_GET['update_json'])) {
$updateCount = null; $updateCount = null;
$updatePreview = ''; $updatePreview = '';
if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) { if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) {
$lines = array_values(array_filter(preg_split('/\r?\n/', $updOutStr))); if (preg_match('/^__COUNT__=(\d+)$/m', $updOutStr, $m)) {
$updateCount = count($lines); $updateCount = (int)$m[1];
$updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : ''; }
} }
[$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25); [$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);

View File

@@ -13,8 +13,8 @@ $table = fn(string $name) => module_fn($module, 'table', $name);
$settings = modules()->settings($module); $settings = modules()->settings($module);
$strictHostKey = !empty($settings['terminal_strict_hostkey']); $strictHostKey = !empty($settings['terminal_strict_hostkey']);
$updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; apt-get -s upgrade 2>/dev/null | grep \"^Inst \" || true'"; $updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; if sudo apt update -qq >/dev/null 2>&1; then count=$(apt-get -s dist-upgrade | grep -c \"^Inst \"); if [ \"$count\" -gt 0 ]; then echo \"__UPDATE__=1\"; else echo \"__UPDATE__=0\"; fi; echo \"__COUNT__=$count\"; else echo \"__ERR__APT_UPDATE\"; exit 3; fi'";
$upgradeCmd = "sh -lc 'current=\"$(. /etc/os-release 2>/dev/null && echo \"$VERSION_CODENAME\")\"; if [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2; exit}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; echo \"__CURRENT__=$current\"; echo \"__LATEST__=$latest\"; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'"; $upgradeCmd = "sh -lc 'id=\"$(. /etc/os-release 2>/dev/null && echo \"${ID:-}\")\"; current=\"$(. /etc/os-release 2>/dev/null && echo \"${VERSION_CODENAME:-}\")\"; if [ \"$id\" != \"debian\" ] || [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'";
$driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME); $driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
$nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')"; $nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')";
@@ -31,9 +31,9 @@ foreach ($hosts as $host) {
$updateCount = null; $updateCount = null;
$updatePreview = ''; $updatePreview = '';
if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) { if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) {
$lines = array_values(array_filter(preg_split('/\r?\n/', $updOutStr))); if (preg_match('/^__COUNT__=(\d+)$/m', $updOutStr, $m)) {
$updateCount = count($lines); $updateCount = (int)$m[1];
$updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : ''; }
} }
[$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25); [$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);