Compare commits

..

No commits in common. "a0fdbe014937adce0dad19b99a278723afe6455c" and "1b9e519e05c853a21b658e628c028e9f9abcb833" have entirely different histories.

2 changed files with 12 additions and 23 deletions

View file

@ -5,9 +5,9 @@ merge_files() {
if [ "$strategy" == tree ]; then
log info "[merge_files] Merging with $strategy strategy"
if ! file_scan_tree "$base_files"; then
if ! file_merge_tree "$base_files"; then
merge_files "$base_files"
fi
file_merge_tree "$base_files"
log info "[merge_files] Recursing"
merge_files "$base_files"
fi
fi
}
@ -19,13 +19,14 @@ file_scan_tree() {
local absolute_path="$(echo "$file" | sed 's/^base//')"
local config_path="$CONFIG_ROOT/$file"
if ! diff "$absolute_path" "$config_path" > /dev/null 2>&1; then
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=
@ -37,32 +38,21 @@ file_merge_tree() {
local config_path="$CONFIG_ROOT/$file"
log debug "[merge_tree] Config path: $config_path"
if diff "$absolute_path" "$config_path" > /dev/null 2>&1; then
if diff "$absolute_path" "$config_path" > /dev/null; then
log debug "[merge_tree] Files match"
else
log debug "[merge_tree] Files differ"
local prompt_verb="Differs"
local prompt_options="Overwrite system,Overwrite configuration,Show difference"
if ! [ -f "$absolute_path" ]; then
local prompt_verb="In configuration only"
local prompt_options="Copy to system"
fi
strategy="$(ask "$prompt_verb: $(tildify "$absolute_path")" "$prompt_options")" ||
file_merge_tree "$base_files"
strategy="$(ask "Differs: $(tildify "$absolute_path")" \
"Overwrite system,Overwrite configuration,Show difference")"
log debug "[merge_tree] Chosen strategy: $strategy"
if [ "$strategy" -eq 0 ]; then
return 0
elif [ "$strategy" -eq 1 ]; then
if [ "$strategy" -eq 1 ]; then
cp -vi "$config_path" "$absolute_path"
return 1
elif [ "$strategy" -eq 2 ]; then
cp -vi "$absolute_path" "$config_path"
return 1
elif [ "$strategy" -eq 3 ]; then
echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >"
diff "$absolute_path" "$config_path"
return 1
diff "$absolute_path" "$config_path" || return 0
else
log user 'Invalid choice'
fi

View file

@ -68,15 +68,14 @@ ask() {
dialog_options="$dialog_options\n [$options_count] $option"
done;
IFS=
dialog_options="$dialog_options\n [0] Exit"
printf "%s" "$question" >&2
printf "%b" "$dialog_options" >&2
printf "\n%s" "Choose an option number: " >&2
printf "\n%s" "Choose an option [1-$options_count] " >&2
read -r read_answer
answer="$(echo "$read_answer" | xargs)"
if [ "$answer" -ge 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then
if [ "$answer" -gt 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then
echo "$answer"
else
log debug "[ask] Invalid choice"