Compare commits
2 commits
91c4f6be4c
...
1b9e519e05
Author | SHA1 | Date | |
---|---|---|---|
1b9e519e05 | |||
e0e1920b0b |
5 changed files with 76 additions and 24 deletions
|
@ -6,5 +6,5 @@ check() {
|
|||
log debug "collected bkp files:\n$bkp_files"
|
||||
|
||||
scan_packages
|
||||
merge_base "$base_files"
|
||||
merge_files "$base_files"
|
||||
}
|
||||
|
|
61
src/file/file_merge.sh
Normal file
61
src/file/file_merge.sh
Normal file
|
@ -0,0 +1,61 @@
|
|||
merge_files() {
|
||||
local base_files="$1"
|
||||
local strategy="${2:-tree}"
|
||||
|
||||
if [ "$strategy" == tree ]; then
|
||||
log info "[merge_files] Merging with $strategy strategy"
|
||||
if ! file_scan_tree "$base_files"; then
|
||||
file_merge_tree "$base_files"
|
||||
log info "[merge_files] Recursing"
|
||||
merge_files "$base_files"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
file_scan_tree() {
|
||||
local base_files="$1"
|
||||
|
||||
for file in $base_files; do
|
||||
local absolute_path="$(echo "$file" | sed 's/^base//')"
|
||||
local config_path="$CONFIG_ROOT/$file"
|
||||
|
||||
if ! diff "$absolute_path" "$config_path" > /dev/null; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# TODO Check if files exist before acting
|
||||
file_merge_tree() {
|
||||
local base_files="$1"
|
||||
local strategy=
|
||||
|
||||
for file in $base_files; do
|
||||
log debug "[merge_tree] Processing $file"
|
||||
local absolute_path="$(echo "$file" | sed 's/^base//')"
|
||||
log debug "[merge_tree] Absolute path: $absolute_path"
|
||||
local config_path="$CONFIG_ROOT/$file"
|
||||
log debug "[merge_tree] Config path: $config_path"
|
||||
|
||||
if diff "$absolute_path" "$config_path" > /dev/null; then
|
||||
log debug "[merge_tree] Files match"
|
||||
else
|
||||
log debug "[merge_tree] Files differ"
|
||||
strategy="$(ask "Differs: $(tildify "$absolute_path")" \
|
||||
"Overwrite system,Overwrite configuration,Show difference")"
|
||||
log debug "[merge_tree] Chosen strategy: $strategy"
|
||||
|
||||
if [ "$strategy" -eq 1 ]; then
|
||||
cp -vi "$config_path" "$absolute_path"
|
||||
elif [ "$strategy" -eq 2 ]; then
|
||||
cp -vi "$absolute_path" "$config_path"
|
||||
elif [ "$strategy" -eq 3 ]; then
|
||||
echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >"
|
||||
diff "$absolute_path" "$config_path" || return 0
|
||||
else
|
||||
log user 'Invalid choice'
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -10,4 +10,4 @@
|
|||
. "$TORI_ROOT/src/package/package_conflict_input_parser.sh"
|
||||
. "$TORI_ROOT/src/package/update_package_cache.sh"
|
||||
|
||||
. "$TORI_ROOT/src/file/merge_base.sh"
|
||||
. "$TORI_ROOT/src/file/file_merge.sh"
|
||||
|
|
|
@ -72,8 +72,19 @@ ask() {
|
|||
printf "%s" "$question" >&2
|
||||
printf "%b" "$dialog_options" >&2
|
||||
printf "\n%s" "Choose an option [1-$options_count] " >&2
|
||||
read -r answer
|
||||
read -r read_answer
|
||||
answer="$(echo "$read_answer" | xargs)"
|
||||
|
||||
if [ "$answer" -gt 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then
|
||||
echo "$answer"
|
||||
else
|
||||
log debug "[ask] Invalid choice"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
tildify() {
|
||||
echo "$1" | sed "s*$HOME*~*"
|
||||
}
|
||||
|
||||
set_opts() {
|
||||
|
|
Loading…
Reference in a new issue