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