Skip to content

Commit

Permalink
apk-autoupdate: Skip packages using apk upgrade --ignore
Browse files Browse the repository at this point in the history
This also switches `apk add -u` to `apk upgrade`.

Closes jirutka#12
  • Loading branch information
fossdd committed Nov 14, 2024
1 parent 717998a commit a59bd3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
1 change: 0 additions & 1 deletion man/autoupdate.conf.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ The following functions may be overridden by the user to customize apk-autoupdat
This function is called for each outdated package to decide whether it should be upgraded or not.
+
The default implementation calls function *default_can_upgrade* that filters packages based on *packages_blacklist*.
If the package or any dependency pulled by it is listed in *packages_blacklist*, then this function returns _1_.
+
*Arguments*:

Expand Down
37 changes: 10 additions & 27 deletions src/apk-autoupdate.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,15 @@ has_update() {
}

# Returns 0 if the specified package can be upgraded, otherwise returns 1.
# Package "apk-tools" is handled specially as self-upgrade.
#
# XXX: This is quite flawed, we need proper support for upgrade --exclude in
# apk to make it more reliable.
#
# $1: package name
default_can_upgrade() {
local pkgname="$1"
local affected apk_args

case_match "$_packages_blacklist" "$pkgname" && return 1

case "$pkgname" in
apk-tools) apk_args='upgrade --self-upgrade-only';;
*) apk_args='add --upgrade';;
esac

affected=$(_apk $apk_args --simulate "$pkgname" \
| sed -En 's/\([0-9/]+\) \w+ing ([[:alnum:]+_-]+) \(.*\)/\1/p')
case_match "$_packages_blacklist" $affected && return 1

return 0
case_match "$_packages_blacklist" "$1" && return 1 || return 0
}

# Upgrades specified package(s), unless $DRY_RUN.
# $@: package name(s)
upgrade() {
_apk add --upgrade ${DRY_RUN:+"--simulate"} "$@"
# Upgrades all available package(s) except the ones specified, unless $DRY_RUN.
# $@: ignored package name(s)
upgrade_all_except() {
_apk upgrade ${DRY_RUN:+"--simulate"} --ignore $@
}

# Runs apk self-upgrade, i.e. upgrades apk-tools and other essential packages.
Expand Down Expand Up @@ -328,6 +309,7 @@ edebug "Sourcing config $_config"
_packages_blacklist=$(case_patt "$packages_blacklist")
_upgrades_avail=''
_pkgs_upgrade=''
_pkgs_skip=''

_packages_skipped=''
_packages_upgraded=''
Expand Down Expand Up @@ -359,7 +341,7 @@ if has_update 'apk-tools'; then
after_upgrade 'apk-tools'
else
ewarn 'Skipping apk self-upgrade'
_packages_skipped='apk-tools'
_pkgs_skip='apk-tools'
fi
fi

Expand All @@ -382,7 +364,7 @@ for item in $_upgrades_avail; do
edebug "Checking whether upgrade $item"
can_upgrade $item \
&& _pkgs_upgrade="$_pkgs_upgrade ${item%% *}" \
|| _packages_skipped="$_packages_skipped ${item%% *}"
|| _pkgs_skip="$_pkgs_skip ${item%% *}"
done
if [ -z "$_pkgs_upgrade" ]; then
edebug 'Executing finalize hook'
Expand All @@ -396,8 +378,9 @@ edebug 'Executing before_upgrade hook'
before_upgrade "$_pkgs_upgrade"

einfo "Upgrading packages: $_pkgs_upgrade"
upgrade $_pkgs_upgrade
upgrade_all_except $_pkgs_skip
_packages_upgraded="$_pkgs_upgrade"
_packages_skipped="$_pkgs_skip"

edebug 'Executing after_upgrade hook'
after_upgrade "$_packages_upgraded"
Expand Down

0 comments on commit a59bd3c

Please sign in to comment.