kiss: make pkg_install operate on a single package at a time

This commit is contained in:
Dylan Araps 2019-09-11 08:25:13 +03:00
parent be3aa8928e
commit 857f03fd88

200
kiss
View File

@ -642,134 +642,132 @@ pkg_remove() {
pkg_install() { pkg_install() {
# Install a built package tar-ball. # Install a built package tar-ball.
for pkg; do # Install can also take the full path to a tar-ball.
# Install can also take the full path to a tar-ball. # We don't need to check the repository if this is the case.
# We don't need to check the repository if this is the case. if [ -f "$1" ] && [ -z "${1%%*.tar.gz}" ] ; then
if [ -f "$pkg" ] && [ -z "${pkg%%*.tar.gz}" ] ; then tar_file=$1
tar_file=$pkg
else else
# Read the version information to name the package. # Read the version information to name the package.
read -r version release < "$(pkg_find "$pkg")/version" read -r version release < "$(pkg_find "$1")/version"
# Construct the name of the package tarball. # Construct the name of the package tarball.
tar_name=$pkg\#$version-$release.tar.gz tar_name=$1\#$version-$release.tar.gz
[ -f "$bin_dir/$tar_name" ] || [ -f "$bin_dir/$tar_name" ] ||
die "Package '$pkg' has not been built" \ die "Package '$1' has not been built" \
"Run 'kiss build $pkg'" "Run 'kiss build $1'"
tar_file=$bin_dir/$tar_name tar_file=$bin_dir/$tar_name
fi fi
# Figure out which package the tar-ball installs by checking for # Figure out which package the tar-ball installs by checking for
# a database entry inside the tar-ball. If no database entry exists, # a database entry inside the tar-ball. If no database entry exists,
# exit here as the tar-ball is *most likely* not a KISS package. # exit here as the tar-ball is *most likely* not a KISS package.
pkg_name=$(tar tf "$tar_file" | grep -x "\./$pkg_db/.*/version") || pkg_name=$(tar tf "$tar_file" | grep -x "\./$pkg_db/.*/version") ||
die "'${tar_file##*/}' is not a valid KISS package" die "'${tar_file##*/}' is not a valid KISS package"
pkg_name=${pkg_name%/*} pkg_name=${pkg_name%/*}
pkg_name=${pkg_name##*/} pkg_name=${pkg_name##*/}
pkg_conflicts "$tar_file" "$pkg_name" pkg_conflicts "$tar_file" "$pkg_name"
mkdir -p "$tar_dir/$pkg_name" mkdir -p "$tar_dir/$pkg_name"
# Extract the tar-ball to catch any errors before installation begins. # Extract the tar-ball to catch any errors before installation begins.
tar pxf "$tar_file" -C "$tar_dir/$pkg_name" || tar pxf "$tar_file" -C "$tar_dir/$pkg_name" ||
die "[$pkg_name] Failed to extract tar-ball" die "[$pkg_name] Failed to extract tar-ball"
log "[$pkg_name] Checking that all dependencies are installed" log "[$pkg_name] Checking that all dependencies are installed"
# Make sure that all run-time dependencies are installed prior to # Make sure that all run-time dependencies are installed prior to
# installing the package. # installing the package.
[ -f "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends" ] && [ -f "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends" ] &&
while read -r dep dep_type; do while read -r dep dep_type; do
[ "${dep##\#*}" ] || continue [ "${dep##\#*}" ] || continue
[ "$dep_type" ] || pkg_list "$dep" >/dev/null || [ "$dep_type" ] || pkg_list "$dep" >/dev/null ||
install_dep="$install_dep'$dep', " install_dep="$install_dep'$dep', "
done < "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends" done < "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends"
[ "$install_dep" ] && die "[$1] Package requires ${install_dep%, }" [ "$install_dep" ] && die "[$1] Package requires ${install_dep%, }"
log "[$pkg_name] Installing package" log "[$pkg_name] Installing package"
# Block being able to abort the script with Ctrl+C during installation. # Block being able to abort the script with Ctrl+C during installation.
# Removes all risk of the user aborting a package installation leaving # Removes all risk of the user aborting a package installation leaving
# an incomplete package installed. # an incomplete package installed.
trap '' INT trap '' INT
# If the package is already installed (and this is an upgrade) make a # If the package is already installed (and this is an upgrade) make a
# backup of the manifest file. # backup of the manifest file.
if [ -f "$sys_db/$pkg_name/manifest" ]; then if [ -f "$sys_db/$pkg_name/manifest" ]; then
old_manifest=$(cat "$sys_db/$pkg_name/manifest") old_manifest=$(cat "$sys_db/$pkg_name/manifest")
else else
old_manifest= old_manifest=
fi fi
# This is repeated multiple times. Better to make it a function. # This is repeated multiple times. Better to make it a function.
pkg_rsync() { pkg_rsync() {
rsync --chown=root:root -HKav --exclude etc -- \ rsync --chown=root:root -HKav --exclude etc -- \
"$tar_dir/$pkg_name/" "$KISS_ROOT/" "$tar_dir/$pkg_name/" "$KISS_ROOT/"
} }
# Install the package by using 'rsync' and overwrite any existing files # Install the package by using 'rsync' and overwrite any existing files
# (excluding '/etc/'). # (excluding '/etc/').
pkg_rsync pkg_rsync
# If '/etc/' exists in the package, install it but don't overwrite. # If '/etc/' exists in the package, install it but don't overwrite.
[ -d "$tar_dir/$pkg_name/etc" ] && [ -d "$tar_dir/$pkg_name/etc" ] &&
rsync --chown=root:root -HKav --ignore-existing \ rsync --chown=root:root -HKav --ignore-existing \
"$tar_dir/$pkg_name/etc" "$KISS_ROOT/" "$tar_dir/$pkg_name/etc" "$KISS_ROOT/"
# Remove any leftover files if this is an upgrade. # Remove any leftover files if this is an upgrade.
[ "$old_manifest" ] && { [ "$old_manifest" ] && {
printf '%s\n' "$old_manifest" | printf '%s\n' "$old_manifest" |
grep -vFxf "$sys_db/$pkg_name/manifest" - | grep -vFxf "$sys_db/$pkg_name/manifest" - |
while read -r file; do while read -r file; do
# Skip deleting some leftover files. # Skip deleting some leftover files.
case $file in case $file in
/etc/*|*bin/rm|*bin/busybox|*bin/rsync) continue ;; /etc/*|*bin/rm|*bin/busybox|*bin/rsync) continue ;;
esac esac
file=$KISS_ROOT/$file file=$KISS_ROOT/$file
# Remove files. # Remove files.
if [ -f "$file" ] && [ ! -L "$file" ]; then if [ -f "$file" ] && [ ! -L "$file" ]; then
rm -f "$file" rm -f "$file"
# Remove file symlinks. # Remove file symlinks.
elif [ -L "$file" ] && [ ! -d "$file" ]; then elif [ -L "$file" ] && [ ! -d "$file" ]; then
unlink "$file" ||: unlink "$file" ||:
# Skip directory symlinks. # Skip directory symlinks.
elif [ -L "$file" ] && [ -d "$file" ]; then elif [ -L "$file" ] && [ -d "$file" ]; then
: :
# Remove directories if empty. # Remove directories if empty.
elif [ -d "$file" ]; then elif [ -d "$file" ]; then
rmdir "$file" 2>/dev/null ||: rmdir "$file" 2>/dev/null ||:
fi fi
done ||: done ||:
} }
# Install the package again to fix any non-leftover files being # Install the package again to fix any non-leftover files being
# removed above. # removed above.
pkg_rsync ||: pkg_rsync ||:
pkg_rsync ||: pkg_rsync ||:
# Reset 'trap' to its original value. Installation is done so # Reset 'trap' to its original value. Installation is done so
# we no longer need to block 'Ctrl+C'. # we no longer need to block 'Ctrl+C'.
trap pkg_clean EXIT INT trap pkg_clean EXIT INT
[ -x "$sys_db/$pkg_name/post-install" ] && { [ -x "$sys_db/$pkg_name/post-install" ] && {
log "[$pkg_name] Running post-install script" log "[$pkg_name] Running post-install script"
"$sys_db/$pkg_name/post-install" ||: "$sys_db/$pkg_name/post-install" ||:
} }
log "[$pkg_name] Installed successfully" log "[$pkg_name] Installed successfully"
done
} }
pkg_updates() { pkg_updates() {
@ -961,7 +959,9 @@ args() {
esac esac
done done
pkg_install $install_pkgs for pkg in $install_pkgs; do
pkg_install "$pkg"
done
;; ;;
r|remove) r|remove)