From 91c4f6be4c798ac5f9f5370882224aa002420d6c Mon Sep 17 00:00:00 2001 From: jutty Date: Tue, 27 Aug 2024 11:28:43 -0300 Subject: [PATCH] Scaffold file comparison structure --- src/check.sh | 1 + src/configuration.sh | 2 +- src/file/merge_base.sh | 20 ++++++++++++++++++++ src/index.sh | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/file/merge_base.sh diff --git a/src/check.sh b/src/check.sh index b0df8ff..598802a 100644 --- a/src/check.sh +++ b/src/check.sh @@ -6,4 +6,5 @@ check() { log debug "collected bkp files:\n$bkp_files" scan_packages + merge_base "$base_files" } diff --git a/src/configuration.sh b/src/configuration.sh index 71a3d5a..0a9faf3 100644 --- a/src/configuration.sh +++ b/src/configuration.sh @@ -15,7 +15,7 @@ scan_directory() { done fi - echo "$files" + printf "%b" "$files" } scan_packages() { diff --git a/src/file/merge_base.sh b/src/file/merge_base.sh new file mode 100644 index 0000000..42f9d0e --- /dev/null +++ b/src/file/merge_base.sh @@ -0,0 +1,20 @@ +merge_base() { + local base_files="$1" + local strategy= + + for file in $base_files; do + log debug "[merge-base] Processing $file" + local absolute_path="$(echo "$file" | sed 's/^base//')" + log debug "[merge-base] Absolute path: $absolute_path" + local config_path="$CONFIG_ROOT/$file" + log debug "[merge-base] Config path: $config_path" + + if diff "$absolute_path" "$config_path" > /dev/null; then + log debug "[merge-base] Files match" + else + log debug "[merge-base] Files differ" + strategy="$(ask "Configuration and system files differ" "Overwrite system,Overwrite config,Show difference")" + log debug "[merge-base] Chosen strategy: $strategy" + fi + done +} diff --git a/src/index.sh b/src/index.sh index f168b74..9899f9a 100644 --- a/src/index.sh +++ b/src/index.sh @@ -9,3 +9,5 @@ . "$TORI_ROOT/src/package/validate_input_packages.sh" . "$TORI_ROOT/src/package/package_conflict_input_parser.sh" . "$TORI_ROOT/src/package/update_package_cache.sh" + +. "$TORI_ROOT/src/file/merge_base.sh"