forked from kiss-community/kiss
kiss: move install check to functions
also some clean up
This commit is contained in:
parent
4396d34fcc
commit
8f0bf83897
83
kiss
83
kiss
@ -583,6 +583,15 @@ pkg_manifest() (
|
|||||||
sort -r | sed '/^\.\/$/d;ss.ss' > "$PWD/$pkg_db/$1/manifest"
|
sort -r | sed '/^\.\/$/d;ss.ss' > "$PWD/$pkg_db/$1/manifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pkg_manifest_validate() {
|
||||||
|
log "$1" "Checking if manifest valid"
|
||||||
|
|
||||||
|
while read -r line; do
|
||||||
|
[ -h "./$line" ] || [ -e "./$line" ] ||
|
||||||
|
die "File $line missing from tarball but mentioned in manifest"
|
||||||
|
done < "$pkg_db/$1/manifest"
|
||||||
|
}
|
||||||
|
|
||||||
pkg_etcsums() {
|
pkg_etcsums() {
|
||||||
# Generate checksums for each configuration file in the package's /etc/
|
# Generate checksums for each configuration file in the package's /etc/
|
||||||
# directory for use in "smart" handling of these files.
|
# directory for use in "smart" handling of these files.
|
||||||
@ -1150,30 +1159,27 @@ pkg_etc() (
|
|||||||
|
|
||||||
pkg_removable() {
|
pkg_removable() {
|
||||||
# Check if a package is removable and die if it is not.
|
# Check if a package is removable and die if it is not.
|
||||||
# A package is removable when it has no dependents or
|
# A package is removable when it has no dependents.
|
||||||
# when KISS_FORCE is set to 1.
|
log "$1" "Checking if package removable"
|
||||||
|
|
||||||
# Intended behavior.
|
cd "$sys_db"
|
||||||
# shellcheck disable=2030,2031
|
set +f
|
||||||
case ${KISS_FORCE:=0} in 0)
|
|
||||||
log "$1" "Checking if package removable"
|
|
||||||
|
|
||||||
cd "$sys_db"
|
! grep -lFx -- "$1" */depends ||
|
||||||
set +f
|
die "$1" "Not removable, has dependents"
|
||||||
|
|
||||||
! grep -lFx -- "$1" */depends ||
|
set -f
|
||||||
die "$1" "Not removable, has dependents"
|
cd "$OLDPWD"
|
||||||
|
|
||||||
set -f
|
|
||||||
cd "$OLDPWD"
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_remove() {
|
pkg_remove() {
|
||||||
# Remove a package and all of its files. The '/etc' directory is handled
|
# Remove a package and all of its files. The '/etc' directory is handled
|
||||||
# differently and configuration files are *not* overwritten.
|
# differently and configuration files are *not* overwritten.
|
||||||
pkg_list "$1" >/dev/null || return
|
pkg_list "$1" >/dev/null || return
|
||||||
pkg_removable "$1"
|
|
||||||
|
# Intended behavior.
|
||||||
|
# shellcheck disable=2030,2031
|
||||||
|
[ "${KISS_FORCE:=0}" = 1 ] || pkg_removable "$1"
|
||||||
|
|
||||||
# Block being able to abort the script with 'Ctrl+C' during removal.
|
# Block being able to abort the script with 'Ctrl+C' during removal.
|
||||||
# Removes all risk of the user aborting a package removal leaving an
|
# Removes all risk of the user aborting a package removal leaving an
|
||||||
@ -1198,6 +1204,34 @@ pkg_remove() {
|
|||||||
log "$1" "Removed successfully"
|
log "$1" "Removed successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pkg_installable() {
|
||||||
|
# Check if a package is removable and die if it is not.
|
||||||
|
# A package is removable when all of its dependencies
|
||||||
|
# are satisfied.
|
||||||
|
log "$1" "Checking if package installable"
|
||||||
|
|
||||||
|
! [ -f "$2" ] ||
|
||||||
|
|
||||||
|
while read -r dep dep_type || [ "$dep" ]; do
|
||||||
|
case $dep-$dep_type in
|
||||||
|
*-\#)
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
|
||||||
|
*-)
|
||||||
|
pkg_list "$dep" >/dev/null 2>&1 || {
|
||||||
|
printf '%s %s\n' "$dep" "$dep_type"
|
||||||
|
set -- "$1" "$2" "$(($3 + 1))"
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done < "$2"
|
||||||
|
|
||||||
|
case ${3:-0} in [1-9]*)
|
||||||
|
die "$1" "Package not installable, missing $3 package(s)"
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
pkg_install() {
|
pkg_install() {
|
||||||
# Install a built package tarball.
|
# Install a built package tarball.
|
||||||
#
|
#
|
||||||
@ -1255,24 +1289,9 @@ pkg_install() {
|
|||||||
# fine assumption to make in 99.99% of cases.
|
# fine assumption to make in 99.99% of cases.
|
||||||
[ -f "./$pkg_db/$pkg_name/manifest" ] || die "Not a valid KISS package"
|
[ -f "./$pkg_db/$pkg_name/manifest" ] || die "Not a valid KISS package"
|
||||||
|
|
||||||
# Ensure that the tarball's manifest is correct by checking that each file
|
|
||||||
# and directory inside of it actually exists.
|
|
||||||
[ "$KISS_FORCE" = 1 ] || {
|
[ "$KISS_FORCE" = 1 ] || {
|
||||||
log "$pkg_name" "Checking that manifest is valid"
|
pkg_manifest_validate "$pkg_name"
|
||||||
while read -r line; do
|
pkg_installable "$pkg_name" "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends"
|
||||||
[ -h "./$line" ] || [ -e "./$line" ] ||
|
|
||||||
die "File $line missing from tarball but mentioned in manifest"
|
|
||||||
done < "$pkg_db/$pkg_name/manifest"
|
|
||||||
|
|
||||||
log "$pkg_name" "Checking that all dependencies are installed"
|
|
||||||
[ -f "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends" ] &&
|
|
||||||
while read -r dep dep_type || [ "$dep" ]; do
|
|
||||||
[ "${dep##\#*}" ] || continue
|
|
||||||
[ "$dep_type" ] || pkg_list "$dep" >/dev/null ||
|
|
||||||
install_dep="$install_dep'$dep', "
|
|
||||||
done < "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends"
|
|
||||||
|
|
||||||
[ "$install_dep" ] && die "$1" "Package requires ${install_dep%, }"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_hook pre-install "$pkg_name" "$tar_dir/$pkg_name"
|
run_hook pre-install "$pkg_name" "$tar_dir/$pkg_name"
|
||||||
|
Loading…
Reference in New Issue
Block a user