From f0a31c4b7ee8eef7264e7afa76e3405d9c4b5e32 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Wed, 5 Feb 2020 08:56:24 +0000 Subject: kiss: 3-way etc checksums thing FossilOrigin-Name: f168ab3f1a87cb0da10c99f96751368a51650a3d385a09e14f0357e4035c4d21 --- kiss | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 7 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index 8735766..898dbce 100755 --- a/kiss +++ b/kiss @@ -421,6 +421,18 @@ pkg_manifest() ( sort -r | sed '/^\.\/$/d;ss.ss' > "$pkg_dir/$1/$pkg_db/$1/manifest" ) +pkg_etcsums() ( + # Generate checksums for each configuration file in the package's + # /etc/ directory for use in "smart" handling of these files. + log "$1" "Generating etcsums" + + # This funcion runs as a sub-shell to avoid having to 'cd' back to the + # prior directory before being able to continue. + cd "$pkg_dir/$1" + + find etc -type f -exec sha256sum {} + > "$pkg_dir/$1/$pkg_db/$1/etcsums" +) + pkg_tar() { # Create a tar-ball from the built package's files. # This tar-ball also contains the package's database entry. @@ -579,10 +591,16 @@ pkg_build() { # This ensure that the manifest is added to the manifest... : > "$pkg_dir/$pkg/$pkg_db/$pkg/manifest" + # If the package contains '/etc', add a file called + # 'etcsums' to the manifest. See comment directly above. + [ -d "$pkg_dir/$pkg/etc" ] && + : > "$pkg_dir/$pkg/$pkg_db/$pkg/etcsums" + pkg_strip "$pkg" pkg_fixdeps "$pkg" pkg_junk "$pkg" pkg_manifest "$pkg" + pkg_etcsums "$pkg" pkg_tar "$pkg" # Install only dependencies of passed packages. @@ -911,7 +929,7 @@ pkg_install() { # This is repeated multiple times. Better to make it a function. pkg_rsync() { rsync --chown=root:root --chmod=Du-s,Dg-s,Do-s \ - -WhHKa --no-compress "$1" --exclude /etc \ + -WhHKa --no-compress --exclude /etc "$1" \ "$tar_dir/$pkg_name/" "$KISS_ROOT/" } @@ -919,10 +937,40 @@ pkg_install() { # (excluding '/etc/'). pkg_rsync --info=progress2 - # If '/etc/' exists in the package, install it but don't overwrite. - [ -d "$tar_dir/$pkg_name/etc" ] && - rsync --chown=root:root -WhHKa --no-compress --ignore-existing \ - "$tar_dir/$pkg_name/etc" "$KISS_ROOT/" + [ -d "$tar_dir/$pkg_name/etc" ] && ( + cd "$tar_dir/$pkg_name" + + # Handle files in /etc/ based on a 3-way checksum check. + find etc -type f | while read -r file; do + { + sum_new=$(sha256sum "$file") + sum_sys=$(cd /; sha256sum "$file") + sum_old=$("$grep" "$file$" "$sys_db/$pkg_name/etcsums") + } 2>/dev/null ||: + + # Use a case statement to easily compare three strings at + # the same time. Pretty nifty. + case ${sum_old:-null}${sum_sys}${sum_new} in + # old = X, sys = X, new = X + # old = X, sys = Y, new = Y + # old = X, sys = X, new = Y + ${sum_old}${sum_old}${sum_old}|\ + ${sum_old}${sum_sys}${sum_sys}|\ + ${sum_sys}${sum_old}*) + cp -af "$file" "/$file" + chown root:root "/$file" + ;; + + # All other cases. + *) + log "$pkg_name" "WARN: saving $file as $file.new" + + cp -af "$file" "/$file.new" + chown root:root "/$file.new" + ;; + esac ||: + done + ) # Remove any leftover files if this is an upgrade. [ "$old_manifest" ] && { @@ -957,8 +1005,7 @@ pkg_install() { # Install the package again to fix any non-leftover files being # removed above. - pkg_rsync -v ||: - pkg_rsync -v ||: + { pkg_rsync --; pkg_rsync --; } ||: # Reset 'trap' to its original value. Installation is done so # we no longer need to block 'Ctrl+C'. -- cgit v1.2.3 From 7ce9e6b347cfcb3f0416f11a1091e0e71e988736 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Wed, 5 Feb 2020 09:07:05 +0000 Subject: kiss: Still work without etcsums FossilOrigin-Name: 03a827b2b0a6197b42d3a8bed2f33f721cba5d7672162aff2454d77cd9b4ec2f --- kiss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kiss') diff --git a/kiss b/kiss index 898dbce..87315d6 100755 --- a/kiss +++ b/kiss @@ -955,7 +955,7 @@ pkg_install() { # old = X, sys = Y, new = Y # old = X, sys = X, new = Y ${sum_old}${sum_old}${sum_old}|\ - ${sum_old}${sum_sys}${sum_sys}|\ + ${sum_old:-null}${sum_sys}${sum_sys}|\ ${sum_sys}${sum_old}*) cp -af "$file" "/$file" chown root:root "/$file" -- cgit v1.2.3 From f7fcfbed3ce5db3138c438adb929ee5c91f87843 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Wed, 5 Feb 2020 09:14:14 +0000 Subject: kiss: Only run etcsums if /etc exists in package FossilOrigin-Name: 94f1b9889796a2ff2689e4e250de7e2e50df6632a88d8708c8cf7204644ce87e --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index 87315d6..6761066 100755 --- a/kiss +++ b/kiss @@ -428,7 +428,7 @@ pkg_etcsums() ( # This funcion runs as a sub-shell to avoid having to 'cd' back to the # prior directory before being able to continue. - cd "$pkg_dir/$1" + cd "$pkg_dir/$1/etc" 2>/dev/null || return; cd .. find etc -type f -exec sha256sum {} + > "$pkg_dir/$1/$pkg_db/$1/etcsums" ) @@ -600,7 +600,7 @@ pkg_build() { pkg_fixdeps "$pkg" pkg_junk "$pkg" pkg_manifest "$pkg" - pkg_etcsums "$pkg" + pkg_etcsums "$pkg" ||: pkg_tar "$pkg" # Install only dependencies of passed packages. -- cgit v1.2.3 From 95a7d4c583a5d0839dc4972396f87b59755c42b7 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Wed, 5 Feb 2020 09:16:50 +0000 Subject: kiss: Only run etcsums if /etc exists in package FossilOrigin-Name: 563eebec57c7621da98f709f3c9e2b9b90a7a9b635d3ab7c0a3c2b5e9ef84c4c --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index 6761066..1b2e249 100755 --- a/kiss +++ b/kiss @@ -428,7 +428,7 @@ pkg_etcsums() ( # This funcion runs as a sub-shell to avoid having to 'cd' back to the # prior directory before being able to continue. - cd "$pkg_dir/$1/etc" 2>/dev/null || return; cd .. + cd "$pkg_dir/$1/etc" 2>/dev/null || return 0; cd .. find etc -type f -exec sha256sum {} + > "$pkg_dir/$1/$pkg_db/$1/etcsums" ) @@ -600,7 +600,7 @@ pkg_build() { pkg_fixdeps "$pkg" pkg_junk "$pkg" pkg_manifest "$pkg" - pkg_etcsums "$pkg" ||: + pkg_etcsums "$pkg" pkg_tar "$pkg" # Install only dependencies of passed packages. -- cgit v1.2.3 From b36a8775e5e0ccbc51269bacf22a51c8c54c01f8 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Wed, 5 Feb 2020 09:22:59 +0000 Subject: kiss: Added KISS_ROOT to etcsums FossilOrigin-Name: 45f939057dd9bcb84c6c56ea38fd34abc99c51467831c0758911a1897c511a09 --- kiss | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index 1b2e249..e490341 100755 --- a/kiss +++ b/kiss @@ -944,7 +944,7 @@ pkg_install() { find etc -type f | while read -r file; do { sum_new=$(sha256sum "$file") - sum_sys=$(cd /; sha256sum "$file") + sum_sys=$(cd "$KISS_ROOT/"; sha256sum "$file") sum_old=$("$grep" "$file$" "$sys_db/$pkg_name/etcsums") } 2>/dev/null ||: @@ -956,20 +956,18 @@ pkg_install() { # old = X, sys = X, new = Y ${sum_old}${sum_old}${sum_old}|\ ${sum_old:-null}${sum_sys}${sum_sys}|\ - ${sum_sys}${sum_old}*) - cp -af "$file" "/$file" - chown root:root "/$file" - ;; + ${sum_sys}${sum_old}*) ;; # All other cases. - *) - log "$pkg_name" "WARN: saving $file as $file.new" + *) log "$pkg_name" "WARN: saving $file as $file.new" + new=.new + esac - cp -af "$file" "/$file.new" - chown root:root "/$file.new" - ;; - esac ||: - done + cp -af "$file" "$KISS_ROOT/${file}${new}" + chown root:root "$KISS_ROOT/${file}${new}" + + new= + done ||: ) # Remove any leftover files if this is an upgrade. -- cgit v1.2.3 From c4980f8145e270680f31f9a4f69b15148220c2f5 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Wed, 5 Feb 2020 09:30:29 +0000 Subject: kiss: clean up FossilOrigin-Name: 8f271022bfbfd9a553cd8e028d28fd77ec7bedba78ed205941ceed1f415cf952 --- kiss | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index e490341..7fc7545 100755 --- a/kiss +++ b/kiss @@ -956,7 +956,7 @@ pkg_install() { # old = X, sys = X, new = Y ${sum_old}${sum_old}${sum_old}|\ ${sum_old:-null}${sum_sys}${sum_sys}|\ - ${sum_sys}${sum_old}*) ;; + ${sum_sys}${sum_old}*) new= ;; # All other cases. *) log "$pkg_name" "WARN: saving $file as $file.new" @@ -965,8 +965,6 @@ pkg_install() { cp -af "$file" "$KISS_ROOT/${file}${new}" chown root:root "$KISS_ROOT/${file}${new}" - - new= done ||: ) -- cgit v1.2.3