kiss: Move new install method to function

This commit is contained in:
Dylan Araps 2020-04-22 09:06:43 +03:00
parent 8a49cd6911
commit c8029d6a71
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

51
kiss
View File

@ -813,6 +813,21 @@ pkg_swap() {
sed -i "$(esc "$PWD/$alt" "$2")" "../installed/$1/manifest" sed -i "$(esc "$PWD/$alt" "$2")" "../installed/$1/manifest"
} }
pkg_install_files() (
awk '{L[n++]=$0}END{while(n--)print L[n]}' "$2/$pkg_db/${2##*/}/manifest" |
while read -r line; do
perms=$(stat -c %a "$2/$line")
case $line in /etc/*) ;;
*/) [ -d "$line" ] || mkdir -m "$perms" "$line" ;;
*) test "$1" "$line" || cp -fPp "$2/$line" "${line%/*}" ;;
esac
chown -h root:root "$line"
done
)
pkg_etc() { pkg_etc() {
[ -d "$tar_dir/$pkg_name/etc" ] || return 0 [ -d "$tar_dir/$pkg_name/etc" ] || return 0
@ -1002,24 +1017,8 @@ pkg_install() {
cp -f "$sys_db/$pkg_name/manifest" "$mak_dir/m" 2>/dev/null ||: cp -f "$sys_db/$pkg_name/manifest" "$mak_dir/m" 2>/dev/null ||:
cp -f "$sys_db/$pkg_name/etcsums" "$mak_dir/c" 2>/dev/null ||: cp -f "$sys_db/$pkg_name/etcsums" "$mak_dir/c" 2>/dev/null ||:
# Ensure that the tarball's manifest is correct by checking that # Install the package's files by iterating over its manifest.
# each file and directory inside of it actually exists. pkg_install_files -z "$tar_dir/$pkg_name"
#
# The 'awk' command simply reverses the contents of the file so that
# directories are listed first.
awk '{L[n++]=$0}END{while(n--)print L[n]}' \
"$tar_dir/$pkg_name/$pkg_db/$pkg_name/manifest" |
while read -r line; do
perms=$(stat -c %a "$tar_dir/$pkg_name/$line")
case $line in /etc/*) ;;
*/) [ -d "$line" ] || mkdir -m "$perms" "$line" ;;
*) cp -Pp "$tar_dir/$pkg_name/$line" "${line%/*}" ;;
esac
chown root:root "$line"
done
# Handle /etc/ files in a special way (via a 3-way checksum) to determine # Handle /etc/ files in a special way (via a 3-way checksum) to determine
# how these files should be installed. Do we overwrite the existing file? # how these files should be installed. Do we overwrite the existing file?
@ -1060,19 +1059,9 @@ pkg_install() {
fi fi
done ||: done ||:
awk '{L[n++]=$0}END{while(n--)print L[n]}' \ # Install the package's files a second time to fix any mess caused by the
"$tar_dir/$pkg_name/$pkg_db/$pkg_name/manifest" | # above removal of the previous version of the package.
pkg_install_files -e "$tar_dir/$pkg_name"
while read -r line; do
perms=$(stat -c %a "$tar_dir/$pkg_name/$line")
case $line in /etc/*) ;;
*/) [ -d "$line" ] || mkdir -m "$perms" "$line" ;;
*) [ -e "$line" ] || cp -p "$tar_dir/$pkg_name/$line" "${line%/*}"
esac
chown root:root "$line"
done
# 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'.