mirror of
https://codeberg.org/kiss-community/kiss
synced 2024-12-23 07:30:16 -07:00
kiss: handle etc in pkg_install_files
This commit is contained in:
parent
f5764dfc2d
commit
ddbefa66b7
103
kiss
103
kiss
@ -1157,7 +1157,18 @@ pkg_install_files() {
|
|||||||
#
|
#
|
||||||
# The 'test' will run with '-e' for no-overwrite and '-z'
|
# The 'test' will run with '-e' for no-overwrite and '-z'
|
||||||
# for overwrite.
|
# for overwrite.
|
||||||
case $file in /etc/*) ;;
|
case $file in
|
||||||
|
/etc/*[!/])
|
||||||
|
# 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? Do we install it as $file.new to avoid
|
||||||
|
# deleting user configuration? etc.
|
||||||
|
#
|
||||||
|
# This is more or less similar to Arch Linux's Pacman with the
|
||||||
|
# user manually handling the .new files when and if they appear.
|
||||||
|
test "$1" "$_file" || pkg_etc "$file" "$_tmp_file_pre_pre"
|
||||||
|
;;
|
||||||
|
|
||||||
*/)
|
*/)
|
||||||
# Skip directories if they already exist in the file system.
|
# Skip directories if they already exist in the file system.
|
||||||
# (Think /usr/bin, /usr/lib, etc).
|
# (Think /usr/bin, /usr/lib, etc).
|
||||||
@ -1194,6 +1205,8 @@ pkg_install_files() {
|
|||||||
fi
|
fi
|
||||||
esac || return 1
|
esac || return 1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
unset _etc_cnt
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_remove_files() {
|
pkg_remove_files() {
|
||||||
@ -1238,59 +1251,46 @@ pkg_remove_files() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_etc() (
|
pkg_etc() {
|
||||||
[ -d "$tar_dir/$1/etc" ] || return 0
|
_etc_cnt=$((_etc_cnt + 1))
|
||||||
|
|
||||||
cd "$tar_dir/$1"
|
# Generate checksums from tarball.
|
||||||
|
sh256 "$tar_dir/$_pkg$1" >/dev/null
|
||||||
|
sum_new=$hash
|
||||||
|
|
||||||
# Create all directories beforehand.
|
# Generate checksums from system.
|
||||||
find etc -type d | while read -r dir; do
|
sh256 "$KISS_ROOT$1" >/dev/null
|
||||||
mkdir -p "$KISS_ROOT/$dir"
|
sum_sys=$hash
|
||||||
done
|
|
||||||
|
|
||||||
# Handle files in /etc/ based on a 3-way checksum check.
|
# Extract checksums from system etcsums.
|
||||||
find etc ! -type d | sort | while read -r file; do
|
sum_old=$(awk "NR == $_etc_cnt" "$2") >/dev/null 2>&1 ||:
|
||||||
i=$((i + 1))
|
|
||||||
|
|
||||||
{ sh256 "$file"; sum_new=$hash
|
# Compare the three checksums to determine what to do.
|
||||||
sh256 "$KISS_ROOT/$file"; sum_sys=$hash
|
case ${sum_old:-null}${sum_sys:-null}${sum_new} in
|
||||||
sum_old=$(awk "NR == $i" "$2"); } >/dev/null 2>&1 || :
|
# old = Y, sys = X, new = Y
|
||||||
|
"${sum_new}${sum_sys}${sum_old}")
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
|
||||||
log "$1" "Doing 3-way handshake for $file"
|
# old = X, sys = X, new = X
|
||||||
printf '%s\n' "Previous: ${sum_old:-null}"
|
# old = X, sys = Y, new = Y
|
||||||
printf '%s\n' "System: ${sum_sys:-null}"
|
# old = X, sys = X, new = Y
|
||||||
printf '%s\n' "New: ${sum_new:-null}"
|
"${sum_old}${sum_old}${sum_old}"|\
|
||||||
|
"${sum_old:-null}${sum_sys}${sum_sys}"|\
|
||||||
|
"${sum_sys}${sum_old}"*)
|
||||||
|
new=
|
||||||
|
;;
|
||||||
|
|
||||||
# Use a case statement to easily compare three strings at
|
# All other cases.
|
||||||
# the same time. Pretty nifty.
|
*)
|
||||||
case ${sum_old:-null}${sum_sys:-null}${sum_new} in
|
war "$1" "saving /$1 as /$1.new"
|
||||||
# old = Y, sys = X, new = Y
|
new=.new
|
||||||
"${sum_new}${sum_sys}${sum_old}")
|
;;
|
||||||
log "Skipping $file"
|
esac
|
||||||
continue
|
|
||||||
;;
|
|
||||||
|
|
||||||
# old = X, sys = X, new = X
|
cp -fPp "$tar_dir/$_pkg/$1" "$KISS_ROOT$1$new"
|
||||||
# old = X, sys = Y, new = Y
|
chown root:root "$KISS_ROOT$1$new" 2>/dev/null ||:
|
||||||
# old = X, sys = X, new = Y
|
}
|
||||||
"${sum_old}${sum_old}${sum_old}"|\
|
|
||||||
"${sum_old:-null}${sum_sys}${sum_sys}"|\
|
|
||||||
"${sum_sys}${sum_old}"*)
|
|
||||||
log "Installing $file"
|
|
||||||
new=
|
|
||||||
;;
|
|
||||||
|
|
||||||
# All other cases.
|
|
||||||
*)
|
|
||||||
war "$1" "saving /$file as /$file.new"
|
|
||||||
new=.new
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
cp -fPp "$file" "$KISS_ROOT/${file}${new}"
|
|
||||||
chown root:root "$KISS_ROOT/${file}${new}" 2>/dev/null
|
|
||||||
done || :
|
|
||||||
)
|
|
||||||
|
|
||||||
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.
|
||||||
@ -1461,15 +1461,6 @@ pkg_install() {
|
|||||||
# Install the package's files by iterating over its manifest.
|
# Install the package's files by iterating over its manifest.
|
||||||
pkg_install_files -z "$PWD" < "$_tmp_file" &&
|
pkg_install_files -z "$PWD" < "$_tmp_file" &&
|
||||||
|
|
||||||
# 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? Do we install it as $file.new to avoid deleting user
|
|
||||||
# configuration? etc.
|
|
||||||
#
|
|
||||||
# This is more or less similar to Arch Linux's Pacman with the user
|
|
||||||
# manually handling the .new files when and if they appear.
|
|
||||||
pkg_etc "$_pkg" "$_tmp_file_pre_pre" &&
|
|
||||||
|
|
||||||
# This is the aforementioned step removing any files from the old
|
# This is the aforementioned step removing any files from the old
|
||||||
# version of the package if the installation is an update. Each file
|
# version of the package if the installation is an update. Each file
|
||||||
# type has to be specially handled to ensure no system breakage occurs.
|
# type has to be specially handled to ensure no system breakage occurs.
|
||||||
|
Loading…
Reference in New Issue
Block a user