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