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 Aug 15, 2024
1 parent 1704b28 commit 54b68ed
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions src/apk-autoupdate.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,16 @@ 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)
# $1: package name(s)
# ${@:2}: additional argument(s) to apk
upgrade() {
_apk add --upgrade ${DRY_RUN:+"--simulate"} "$@"
_apk upgrade ${DRY_RUN:+"--simulate"} ${@:2} "$1"
}

# Runs apk self-upgrade, i.e. upgrades apk-tools and other essential packages.
Expand Down Expand Up @@ -328,6 +310,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 +342,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 +365,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,7 +379,7 @@ edebug 'Executing before_upgrade hook'
before_upgrade "$_pkgs_upgrade"

einfo "Upgrading packages: $_pkgs_upgrade"
upgrade $_pkgs_upgrade
upgrade "$_pkgs_upgrade" --ignore "$_pkgs_skip"
_packages_upgraded="$_pkgs_upgrade"

edebug 'Executing after_upgrade hook'
Expand Down

0 comments on commit 54b68ed

Please sign in to comment.