podman-verify-packages.sh/podman-update-packages.sh reported every package as "not installed" right after a genuinely successful install. Root cause: /var/log/packages is itself a symlink on Unraid (-> ../lib/pkgtools/packages), and GNU find's default -P mode doesn't descend into a symlinked starting path at all without -L — confirmed live by running the exact same find both with and without -L against a host where the packages had just installed successfully. Fixing that alone surfaced a second, previously-masked bug: "podman"'s own glob also matches podman-compose's file (a literal prefix collision), and find's unsorted output let podman-compose's record silently win podman's own check. Both fixed once via a new shared podman_find_installed_package_record() helper in podman-common.sh, rather than separately in each caller. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
140 lines
5.3 KiB
Bash
Executable File
140 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# plugin/sbin/podman-update-packages.sh
|
|
#
|
|
# "Pakete aktualisieren" — reconciles installed packages with what the
|
|
# currently installed plugin version expects, per
|
|
# /usr/local/share/unraid-podman/installed-versions.env (written by
|
|
# plugin/podman.plg's postinstall — see podman-verify-packages.sh for the
|
|
# same manifest used the other direction, to *check* rather than *fix*).
|
|
#
|
|
# This is intentionally idempotent and safe to run any time, not just
|
|
# during a plugin update: if every package already matches, it's a no-op.
|
|
# It exists as a separate script (rather than being inline in podman.plg)
|
|
# for two reasons:
|
|
# 1. plugin/podman.plg's own <FILE Run="upgradepkg"> blocks handle the
|
|
# *normal* update path (new .txz already downloaded by the plg,
|
|
# installed as part of the same transaction) — this script is the
|
|
# *repair* path for when that didn't fully complete (e.g. Unraid was
|
|
# rebooted mid-update), and can be re-run safely from the command line
|
|
# or from a future WebUI "check for package issues" action.
|
|
# 2. It calls podman-backup.sh snapshot-config first, since any package
|
|
# swap is exactly the moment a config schema migration might be
|
|
# needed — see docs/ARCHITECTURE.md section 13.1.
|
|
#
|
|
# Usage:
|
|
# podman-update-packages.sh # reconcile all 11 packages
|
|
# podman-update-packages.sh podman # reconcile a single package
|
|
# =============================================================================
|
|
|
|
set -u
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=./podman-common.sh
|
|
. "$SCRIPT_DIR/podman-common.sh"
|
|
|
|
INSTALLED_VERSIONS_FILE="/usr/local/share/unraid-podman/installed-versions.env"
|
|
ALL_PACKAGES="podman conmon crun netavark aardvark-dns passt fuse-overlayfs catatonit nftables podman-compose unraid-podman"
|
|
|
|
if [ ! -f "$INSTALLED_VERSIONS_FILE" ]; then
|
|
podman_log_error "update-packages: $INSTALLED_VERSIONS_FILE missing — plugin install metadata not found"
|
|
exit 1
|
|
fi
|
|
# shellcheck source=/dev/null
|
|
. "$INSTALLED_VERSIONS_FILE"
|
|
|
|
if [ -z "${PLUGIN_VERSION:-}" ]; then
|
|
podman_log_error "update-packages: PLUGIN_VERSION not recorded in $INSTALLED_VERSIONS_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
targets="${*:-$ALL_PACKAGES}"
|
|
|
|
podman_require_command upgradepkg
|
|
podman_require_command installpkg
|
|
|
|
updated=0
|
|
already_current=0
|
|
errors=0
|
|
|
|
for name in $targets; do
|
|
entity_prefix=$(echo "$name" | tr '[:lower:]-' '[:upper:]_')
|
|
expected_version_var="${entity_prefix}_INSTALLED_VERSION"
|
|
expected_version="${!expected_version_var:-}"
|
|
|
|
if [ -z "$expected_version" ]; then
|
|
podman_log_error "update-packages: no expected version recorded for '$name', skipping"
|
|
errors=$((errors + 1))
|
|
continue
|
|
fi
|
|
|
|
# See podman-common.sh's podman_find_installed_package_record() for why
|
|
# this isn't just a plain `find ... -name "$name-*" | head -n1` — note
|
|
# it's given $ALL_PACKAGES (not $targets), since prefix-collision
|
|
# detection needs the full component universe even when only updating
|
|
# a subset of it.
|
|
installed_record=$(podman_find_installed_package_record "$name" $ALL_PACKAGES)
|
|
installed_basename=$(basename "${installed_record:-__none__}")
|
|
|
|
case "$installed_basename" in
|
|
"${name}-${expected_version}-"*)
|
|
podman_log "update-packages: $name already at expected version $expected_version"
|
|
already_current=$((already_current + 1))
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
# The package for the currently expected version was downloaded straight
|
|
# into its backup slot by podman.plg (grouped by PLUGIN_VERSION, since a
|
|
# rollback targets "this plugin release" — see podman-backup.sh's header
|
|
# comment for why that's also where we install FROM.
|
|
txz=$(find "$PODMAN_BACKUP_DIR/packages/$PLUGIN_VERSION" -maxdepth 1 -name "${name}-*.txz" 2> /dev/null | head -n1)
|
|
if [ -z "$txz" ]; then
|
|
podman_log_error "update-packages: no package file found for $name (expected version $expected_version) in $PODMAN_BACKUP_DIR/packages/$PLUGIN_VERSION/"
|
|
errors=$((errors + 1))
|
|
continue
|
|
fi
|
|
|
|
podman_log "update-packages: installing $name -> $expected_version ($txz)"
|
|
|
|
# Snapshot config once, before the first actual package change — a
|
|
# version bump is exactly when a schema migration might be needed (see
|
|
# file header). Only do this once per run, not once per package.
|
|
if [ "$updated" -eq 0 ]; then
|
|
"$SCRIPT_DIR/podman-backup.sh" snapshot-config > /dev/null
|
|
fi
|
|
|
|
if [ -n "$installed_record" ]; then
|
|
if upgradepkg --install-new "$txz"; then
|
|
updated=$((updated + 1))
|
|
else
|
|
podman_log_error "update-packages: upgradepkg failed for $name ($txz)"
|
|
errors=$((errors + 1))
|
|
fi
|
|
else
|
|
if installpkg "$txz"; then
|
|
updated=$((updated + 1))
|
|
else
|
|
podman_log_error "update-packages: installpkg failed for $name ($txz)"
|
|
errors=$((errors + 1))
|
|
fi
|
|
fi
|
|
done
|
|
|
|
podman_log "update-packages: done (updated=$updated already-current=$already_current errors=$errors)"
|
|
|
|
if [ "$errors" -gt 0 ]; then
|
|
podman_notify "Podman package update had errors" \
|
|
"$errors package(s) failed to update — see $PODMAN_PLUGIN_LOG." \
|
|
"alert"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$updated" -gt 0 ]; then
|
|
podman_notify "Podman packages updated" \
|
|
"$updated package(s) updated. Run 'rc.podman restart' to apply." \
|
|
"normal"
|
|
fi
|
|
|
|
exit 0
|