Tree file management strategy and file backups #3
1 changed files with 20 additions and 10 deletions
|
@ -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
|
||||
file_merge_tree "$base_files"
|
||||
log info "[merge_files] Recursing"
|
||||
merge_files "$base_files"
|
||||
if ! file_merge_tree "$base_files"; then
|
||||
merge_files "$base_files"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -19,14 +19,13 @@ 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; then
|
||||
if ! diff "$absolute_path" "$config_path" > /dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# TODO Check if files exist before acting
|
||||
file_merge_tree() {
|
||||
local base_files="$1"
|
||||
local strategy=
|
||||
|
@ -38,21 +37,32 @@ 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; then
|
||||
if diff "$absolute_path" "$config_path" > /dev/null 2>&1; 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")"
|
||||
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"
|
||||
log debug "[merge_tree] Chosen strategy: $strategy"
|
||||
|
||||
if [ "$strategy" -eq 1 ]; then
|
||||
if [ "$strategy" -eq 0 ]; then
|
||||
return 0
|
||||
elif [ "$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 0
|
||||
diff "$absolute_path" "$config_path"
|
||||
return 1
|
||||
else
|
||||
log user 'Invalid choice'
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue