From 4b2082298698b81d620bf6e38b41723306906658 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 5 Feb 2020 10:56:25 +0200 Subject: [PATCH 1/6] kiss: 3-way etc checksums thing --- kiss | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 7 deletions(-) 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'. From 4a9f60afbd6414f954490f2984e224606912f99a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 5 Feb 2020 11:07:06 +0200 Subject: [PATCH 2/6] kiss: Still work without etcsums --- kiss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From e8ead378d73d6f149de24634ac09b29ee21c13f0 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 5 Feb 2020 11:14:15 +0200 Subject: [PATCH 3/6] kiss: Only run etcsums if /etc exists in package --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. From 0df093f7291ba8277aebc5bada888d95e1956131 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 5 Feb 2020 11:16:51 +0200 Subject: [PATCH 4/6] kiss: Only run etcsums if /etc exists in package --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. From 98d5aaab7998e8474db60d5c6afc1c924dd571a3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 5 Feb 2020 11:23:00 +0200 Subject: [PATCH 5/6] kiss: Added KISS_ROOT to etcsums --- kiss | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) 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. From 24e97f2a008c29cac231a7b995aee42094bca11a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 5 Feb 2020 11:30:29 +0200 Subject: [PATCH 6/6] kiss: clean up --- kiss | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 ||: )