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

149
kiss
View File

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