forked from kiss-community/kiss
kiss: simplify pkg_etc
This commit is contained in:
parent
cb3d826bf0
commit
2356a2bc78
73
kiss
73
kiss
@ -954,10 +954,13 @@ pkg_install_files() {
|
||||
|
||||
# Copy files and create directories (preserving permissions),
|
||||
# skipping anything located in /etc/.
|
||||
#
|
||||
# The 'test' will run with '-e' for no-overwrite and '-z'
|
||||
# for overwrite.
|
||||
case $line in /etc/*) ;;
|
||||
case $line in
|
||||
/etc/?*[!/])
|
||||
# Handle file in /etc/.
|
||||
[ -d "$KISS_ROOT/$line" ] || test "$1" "$KISS_ROOT/$line" ||
|
||||
pkg_etc_file "$2" "${line#/}"
|
||||
;;
|
||||
|
||||
*/)
|
||||
# Skip directories if they already exist in the file system.
|
||||
# (Think /usr/bin, /usr/lib, etc).
|
||||
@ -977,6 +980,8 @@ pkg_install_files() {
|
||||
}
|
||||
esac
|
||||
done ||:
|
||||
|
||||
pkg_etc_cnt=0
|
||||
}
|
||||
|
||||
pkg_remove_files() {
|
||||
@ -1011,25 +1016,16 @@ pkg_remove_files() {
|
||||
done ||:
|
||||
}
|
||||
|
||||
pkg_etc() (
|
||||
[ -d "$tar_dir/$pkg/etc" ] || return 0
|
||||
pkg_etc_file() {
|
||||
pkg_etc_cnt=$((pkg_etc_cnt + 1))
|
||||
|
||||
cd "$tar_dir/$pkg"
|
||||
log "$pkg" "Doing 3-way handshake for $2"
|
||||
|
||||
# Create all directories beforehand.
|
||||
find etc -type d | while read -r dir; do
|
||||
mkdir -p "$KISS_ROOT/$dir"
|
||||
done
|
||||
sum_new=$(sh256 "$1/$2") 2>/dev/null ||:
|
||||
sum_sys=$(cd "$KISS_ROOT/"; sh256 "$2") 2>/dev/null ||:
|
||||
sum_old=$(awk "NR == $pkg_etc_cnt" "$mak_dir/c") 2>/dev/null ||:
|
||||
echo $pkg_etc_cnt
|
||||
|
||||
# Handle files in /etc/ based on a 3-way checksum check.
|
||||
find etc -type f | sort | while read -r file; do
|
||||
i=$((i + 1))
|
||||
|
||||
{ sum_new=$(sh256 "$file")
|
||||
sum_sys=$(cd "$KISS_ROOT/"; sh256 "$file")
|
||||
sum_old=$(awk "NR == $i" "$mak_dir/c"); } 2>/dev/null ||:
|
||||
|
||||
log "$pkg" "Doing 3-way handshake for $file"
|
||||
printf '%s\n' "Previous: ${sum_old:-null}"
|
||||
printf '%s\n' "System: ${sum_sys:-null}"
|
||||
printf '%s\n' "New: ${sum_new:-null}"
|
||||
@ -1039,8 +1035,8 @@ pkg_etc() (
|
||||
case ${sum_old:-null}${sum_sys:-null}${sum_new} in
|
||||
# old = Y, sys = X, new = Y
|
||||
"${sum_new}${sum_sys}${sum_old}")
|
||||
log "Skipping $file"
|
||||
continue
|
||||
log "Skipping $2"
|
||||
return 0
|
||||
;;
|
||||
|
||||
# old = X, sys = X, new = X
|
||||
@ -1049,21 +1045,20 @@ pkg_etc() (
|
||||
"${sum_old}${sum_old}${sum_old}"|\
|
||||
"${sum_old:-null}${sum_sys}${sum_sys}"|\
|
||||
"${sum_sys}${sum_old}"*)
|
||||
log "Installing $file"
|
||||
log "Installing $2"
|
||||
new=
|
||||
;;
|
||||
|
||||
# All other cases.
|
||||
*)
|
||||
war "$pkg" "saving /$file as /$file.new"
|
||||
war "$pkg" "saving /$2 as /$2.new"
|
||||
new=.new
|
||||
;;
|
||||
esac
|
||||
|
||||
cp -fPp "$file" "$KISS_ROOT/${file}${new}"
|
||||
chown root:root "$KISS_ROOT/${file}${new}" 2>/dev/null
|
||||
done ||:
|
||||
)
|
||||
cp -fPp "$1/$2" "$KISS_ROOT/${2}${new}"
|
||||
chown root:root "$KISS_ROOT/${2}${new}" 2>/dev/null
|
||||
}
|
||||
|
||||
pkg_remove() {
|
||||
# Remove a package and all of its files. The '/etc' directory is handled
|
||||
@ -1174,8 +1169,6 @@ pkg_install() {
|
||||
run_hook pre-install "$pkg" "$tar_dir/$pkg"
|
||||
pkg_conflicts "$pkg"
|
||||
|
||||
log "$pkg" "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.
|
||||
@ -1186,17 +1179,9 @@ pkg_install() {
|
||||
cp -f "$sys_db/$pkg/manifest" "$mak_dir/m" 2>/dev/null ||:
|
||||
cp -f "$sys_db/$pkg/etcsums" "$mak_dir/c" 2>/dev/null ||:
|
||||
|
||||
# Install the package's files by iterating over its manifest.
|
||||
log "$pkg" "Installing package"
|
||||
pkg_install_files -z "$tar_dir/$pkg"
|
||||
|
||||
# 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
|
||||
|
||||
# This is the aforementioned step removing any files from the old version of
|
||||
# the package if the installation is an update. Each file type has to be
|
||||
# specially handled to ensure no system breakage occurs.
|
||||
@ -1211,8 +1196,6 @@ pkg_install() {
|
||||
log "$pkg" "Verifying installation"
|
||||
pkg_install_files -e "$tar_dir/$pkg"
|
||||
|
||||
# Reset 'trap' to its original value. Installation is done so we no longer
|
||||
# need to block 'Ctrl+C'.
|
||||
trap pkg_clean EXIT INT
|
||||
|
||||
if [ -x "$sys_db/$pkg/post-install" ]; then
|
||||
@ -1383,15 +1366,19 @@ args() {
|
||||
case $action in
|
||||
b|build|c|checksum|d|download|i|install|r|remove)
|
||||
[ "$1" ] || {
|
||||
# Intentional.
|
||||
# shellcheck disable=2031
|
||||
export KISS_PATH=${PWD%/*}:$KISS_PATH
|
||||
set -- "${PWD##*/}"
|
||||
}
|
||||
|
||||
case "$*" in
|
||||
for arg do
|
||||
case $arg in
|
||||
*'*'*|*'!'*|*'['*|*']'*|*' '*|*' '*)
|
||||
die "Arguments contain invalid characters: '!*[ \t]'"
|
||||
die "Argument contains: '!*[ \t]' ($arg)"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user