kiss: update clean up

- Update hooks now fire for non-Git repositories. This allows hooks
  to add support for other update methods.

- Foundational work to explore other update methods in the package
  manager itself.

- Added 'U|upgrade' to update the system without pulling new changes
  from remotes.

- Other minor changes.
This commit is contained in:
Dylan Araps 2021-07-24 12:42:30 +03:00
parent cb73d80ccb
commit dfd000e9c5
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C

109
kiss
View File

@ -1545,62 +1545,66 @@ pkg_update() {
# Update each repository in '$KISS_PATH'.
for repo do
ok "$repo" || continue
repo_type=null repo_sig=false
[ -d "$repo" ] || {
log "$repo" " "
printf 'Skipping repository, not a directory\n'
if git -C "$repo" remote >/dev/null 2>&1; then
repo_type=git
# Display whether or not signature verification is enabled.
repo_sig=$(git -C "$repo" config --get merge.verifySignatures) || :
# Get the Git repository root directory.
subm=$(git -C "$repo" rev-parse --show-superproject-working-tree)
repo=$(git -C "${subm:-"$repo"}" rev-parse --show-toplevel)
elif ! [ -d "$repo" ]; then
continue
fi
pkg_update_repo "$repo" "$repo_type" "${repo_sig:-false}"
done
pkg_upgrade
}
cd "$repo"
pkg_update_repo() {
cd "$1" || die "Repository '$1' inaccessible"
git remote >/dev/null 2>&1 || {
log "$repo" " "
printf 'Skipping git pull, not a repository\n'
continue
}
# Go to the repository's root directory.
git_root=$(git rev-parse --show-toplevel)
cd "${git_root:?"failed to find git root for '$PWD'"}"
# Go to the real root directory if this is a submodule.
git_root=$(git rev-parse --show-superproject-working-tree)
cd "${git_root:-"$PWD"}"
# NULL function for unsupported repository types.
pkg_update_null() { log "$PWD" "Repository has no remote"; }
contains "$repos" "$PWD" || {
repos="$repos $PWD"
log "$PWD" "[verify: $3]"
# arg1: pre-update
# env: PWD is path to repository
run_hook pre-update
# Display whether or not signature verification is enabled.
_sig=$(git config --get --default false merge.verifySignatures)
log "$PWD" "[verify: $_sig]"
if ! am_owner "$PWD"; then
log "$PWD" "Need '$user' to update"
as_user git pull
as_user git submodule update --remote --init -f
else
git pull
git submodule update --remote --init -f
fi
"pkg_update_$2"
# arg1: post-update
# env: PWD is path to repository
run_hook post-update
}
done
}
pkg_update_git() {
am_owner "$PWD" || {
log "$PWD" "Need '$user' to update"
set -- as_user
}
"$@" git pull
"$@" git submodule update --remote --init -f
}
pkg_upgrade() {
log "Checking for new package versions"
set +f
set +f --
for pkg in "$sys_db/"*; do
for pkg in "$sys_db/"*; do set -f
pkg_find_version "${pkg##*/}" "" "" "$sys_db"
pkg_find_version "${pkg##*/}"
@ -1612,21 +1616,20 @@ pkg_update() {
# Compare installed packages to repository packages.
equ "$ver_pre-$rel_pre" "$repo_ver-$repo_rel" || {
printf '%s\n' "${pkg##*/} $ver_pre-$rel_pre ==> $repo_ver-$repo_rel"
set -- "$@" "${pkg##*/}"
printf '%s %s => %s\n' \
"${pkg##*/}" "$ver_pre-$rel_pre" "$repo_ver-$repo_rel"
}
done
log "Checking for orphaned repository packages"
case $_repo_orp in *?*)
war "Packages without repository$_repo_orp"
war "Installed packages without repository$_repo_orp"
esac
set -f
pkg_update=1
case " $* " in
*" kiss "*)
! contains "$*" kiss || {
log "Detected package manager update"
log "The package manager will be updated first"
@ -1635,25 +1638,24 @@ pkg_update() {
log "Updated the package manager"
log "Re-run 'kiss update' to update your system"
;;
return 0
}
" ")
log "Everything is up to date"
;;
*)
log "Packages to update: $*"
prompt
for _ do
pkg_order "$@"
# Intentional, globbing disabled.
# shellcheck disable=2046,2086
pkg_build_all $order
set -- $order
log "Packages to update ($#): $*"
prompt
pkg_build_all "$@"
log "Updated all packages"
;;
esac
return 0
done
log "Nothing to do"
}
pkg_clean() {
@ -1787,6 +1789,7 @@ args() {
r|remove) for pkg in $redro; do pkg_remove "$pkg"; done ;;
s|search) for pkg do pkg_find "$pkg" all; done ;;
u|update) pkg_update ;;
U|upgrade) pkg_upgrade ;;
v|version) printf '5.5.18\n' ;;
'')