kiss: unify all version logic

This commit is contained in:
Dylan Araps 2021-07-17 13:58:36 +03:00
parent 9404f699f0
commit 7416bd3b5e
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C
1 changed files with 25 additions and 31 deletions

56
kiss
View File

@ -215,10 +215,17 @@ pkg_lint() {
}
pkg_find_version() {
pkg_find_die "$1"
ver_pre=$repo_ver
rel_pre=$repo_rel
pkg_find "$@"
read -r repo_ver repo_rel 2>/dev/null < "$repo_dir/version" ||
die "$1" "Failed to read version file ($repo_dir/version)"
}
pkg_find_version_split() {
pkg_find_version "$@"
# Split the version on '.+-_' to obtain individual components.
IFS=.+-_ read -r repo_major repo_minor repo_patch repo_ident <<EOF
@ -226,10 +233,6 @@ $repo_ver
EOF
}
pkg_find_die() {
pkg_find "$@" || die "Package '$1' not in any repository"
}
pkg_find() {
# Figure out which repository a package belongs to by searching for
# directories matching the package name in $KISS_PATH/*.
@ -250,13 +253,13 @@ pkg_find() {
# Show all search results if called from 'kiss search', else store the
# values in variables. If there are 4 arguments, no package has been found.
case $2-$# in
*-4) return 1 ;;
*-4) die "'$1' not found" ;;
-*) repo_dir=$5 repo_name=${5##*/} ;;
*) shift 4; printf '%s\n' "$@"
esac
}
pkg_list() {
pkg_list_version() {
# List installed packages. As the format is files and directories, this
# just involves a simple for loop and file read.
@ -266,15 +269,9 @@ pkg_list() {
# Loop over each package and print its name and version.
for _list_pkg do
_list_pkg=$sys_db/${_list_pkg##*/}
pkg_find_version "${_list_pkg##*/}" "" "" "$sys_db"
[ -d "$_list_pkg" ] || {
log "${_list_pkg##*/}" "not installed"
return 1
}
read -r version 2>/dev/null < "$_list_pkg/version" || version=null
printf '%s\n' "${_list_pkg##*/} $version"
printf '%s\n' "$repo_name $repo_ver-$repo_rel"
done
}
@ -350,7 +347,7 @@ pkg_source_resolve() {
pkg_source() {
# Download any remote package sources. The existence of local files is
# also checked.
pkg_find_version "$1"
pkg_find_version_split "$1"
# Support packages without sources. Simply do nothing.
[ -f "$repo_dir/sources" ] || return 0
@ -476,7 +473,7 @@ pkg_depends() {
contains "$deps" "$1" || {
# Filter out non-explicit, already installed packages.
[ -z "$3" ] || [ "$2" ] || contains "$explicit" "$1" ||
! pkg_list "$1" >/dev/null 2>&1 || return
! [ -d "$sys_db/$1" ] || return
# Detect circular dependencies and bail out.
# Looks for multiple repeating patterns of (dep dep_parent) (5 is max).
@ -830,7 +827,7 @@ pkg_build_all() {
for pkg do
log "$pkg" "Building package ($((_build_cur+=1))/${_build_tot:=$#})"
pkg_find_version "$pkg"
pkg_find_version_split "$pkg"
# arg1: queue-status
# arg2: package name
@ -1099,12 +1096,12 @@ pkg_conflicts() {
pkg_swap() {
# Swap between package alternatives.
pkg_list "$1" >/dev/null
[ -d "$sys_db/$1" ] || die "'$1' not found"
fnr "$1$2" '/' '>'
[ -f "$sys_ch/$_fnr" ] || [ -h "$sys_ch/$_fnr" ] ||
die "Alternative '$1 $2' doesn't exist"
die "Alternative '$1 ${2:-null}' doesn't exist"
if [ -f "$KISS_ROOT$2" ]; then
# Figure out which package owns the file we are going to swap in the
@ -1316,7 +1313,6 @@ pkg_removable() {
pkg_remove() {
# Remove a package and all of its files. The '/etc' directory is handled
# differently and configuration files are *not* overwritten.
pkg_list "$1" >/dev/null || return
# Intended behavior.
# shellcheck disable=2030,2031
@ -1363,7 +1359,7 @@ pkg_installable() {
;;
*-)
pkg_list "$dep" >/dev/null 2>&1 || {
[ -d "$sys_db/$dep" ] || {
printf '%s %s\n' "$dep" "$dep_type"
set -- "$1" "$2" "$(($3 + 1))"
}
@ -1599,9 +1595,7 @@ pkg_update() {
set +f --
for pkg in "$sys_db/"*; do
read -r db_ver db_rel < "$pkg/version" ||
die "${pkg##*/}" "Failed to read installed version"
pkg_find_version "${pkg##*/}" "" "" "$sys_db"
pkg_find_version "${pkg##*/}"
# Detect repository orphans (installed packages with no
@ -1611,8 +1605,8 @@ pkg_update() {
esac
# Compare installed packages to repository packages.
[ "$db_ver-$db_rel" = "$repo_ver-$repo_rel" ] || {
printf '%s\n' "${pkg##*/} $db_ver-$db_rel ==> $repo_ver-$repo_rel"
[ "$ver_pre-$rel_pre" = "$repo_ver-$repo_rel" ] || {
printf '%s\n' "${pkg##*/} $ver_pre-$rel_pre ==> $repo_ver-$repo_rel"
set -- "$@" "${pkg##*/}"
}
done
@ -1767,7 +1761,7 @@ args() {
c|checksum)
for pkg do pkg_source "$pkg" c; done
for pkg do
pkg_find_version "$pkg"
pkg_find_version_split "$pkg"
[ -f "$repo_dir/sources" ] || {
log "$pkg" "No sources file, skipping checksums"
@ -1789,9 +1783,9 @@ args() {
i|install) for pkg do pkg_install "$pkg"; done ;;
b|build) pkg_build_all "${@:?No packages installed}" ;;
d|download) for pkg do pkg_source "$pkg"; done ;;
l|list) pkg_list "$@" ;;
l|list) pkg_list_version "$@" ;;
r|remove) for pkg in $redro; do pkg_remove "$pkg"; done ;;
s|search) for pkg do pkg_find_die "$pkg" all; done ;;
s|search) for pkg do pkg_find "$pkg" all; done ;;
u|update) pkg_update ;;
v|version) printf '5.5.6\n' ;;
@ -1840,7 +1834,7 @@ args() {
;;
*)
pkg_find_die "kiss-$action*" "" -x "$PATH"
pkg_find "kiss-$action*" "" -x "$PATH"
"$repo_dir" "$@"
;;
esac