Compare commits

...

2 commits

Author SHA1 Message Date
67de45f5ba Update strings for v0.6.0 2024-09-03 12:09:51 -03:00
e94e68540f Make file operations more permission-aware 2024-09-03 12:09:40 -03:00
5 changed files with 29 additions and 13 deletions

View file

@ -1,3 +1,7 @@
0.6.0 2024-09-03: File management with the tree strategy
File backups
Extract authorization command to top level
ask and tildify utility functions
0.5.0 2024-07-18: "Decide in editor" package conflict resolution strategy 0.5.0 2024-07-18: "Decide in editor" package conflict resolution strategy
Drop pipefail shell option for dash compatibility Drop pipefail shell option for dash compatibility
Add numerical debug levels to the log utility function Add numerical debug levels to the log utility function

View file

@ -2,7 +2,7 @@
tori is a tool to track your personal systems' configurations and replicate them. tori is a tool to track your personal systems' configurations and replicate them.
If you'd like a more detailed description of what it is, its purpose, origins and goals, see the [announcement blog post](https://blog.jutty.dev/posts/introducing-tori.html). If you'd like a more detailed description of what it is, its purpose, origins and goals, see the [announcement blog post](https://blog.jutty.dev/posts/introducing-tori/).
Refer to the [project website](https://tori.jutty.dev) for updates and access to [documentation](https://tori.jutty.dev/docs). Refer to the [project website](https://tori.jutty.dev) for updates and access to [documentation](https://tori.jutty.dev/docs).

View file

@ -1,4 +1,4 @@
# takes a list of space-separated absolute paths # takes a list of newline-separated absolute paths
# backs each path up, creating canonical or ephemeral copies as needed # backs each path up, creating canonical or ephemeral copies as needed
backup_paths() { backup_paths() {
local paths="$1" local paths="$1"
@ -15,14 +15,26 @@ backup_paths() {
mkdir -p "$(dirname "$ephemeral_path")" mkdir -p "$(dirname "$ephemeral_path")"
if [ -f "$ephemeral_path" ]; then if [ -f "$ephemeral_path" ]; then
log debug "[backup] Overwriting ephemeral copy for $path" log debug "[backup] Overwriting ephemeral copy for $path"
cp -f "$path" "$ephemeral_path" if [ -r "$path" ]; then
cp -f "$path" "$ephemeral_path"
else
$AUTHORIZE_COMMAND cp -f "$path" "$ephemeral_path"
fi
else else
cp "$path" "$ephemeral_path" if [ -r "$path" ]; then
cp "$path" "$ephemeral_path"
else
$AUTHORIZE_COMMAND cp "$path" "$ephemeral_path"
fi
fi fi
else else
log debug "[backup] Creating canonical copy for $path" log debug "[backup] Creating canonical copy for $path"
mkdir -p "$(dirname "$canonical_path")" mkdir -p "$(dirname "$canonical_path")"
cp "$path" "$canonical_path" if [ -r "$path" ]; then
cp "$path" "$canonical_path"
else
$AUTHORIZE_COMMAND cp "$path" "$canonical_path"
fi
fi fi
done done
} }

View file

@ -28,7 +28,7 @@ file_scan_tree() {
file_merge_tree() { file_merge_tree() {
local base_files="$1" local base_files="$1"
local strategy= local overwrite_choice=
for file in $base_files; do for file in $base_files; do
log debug "[merge_tree] Processing $file" log debug "[merge_tree] Processing $file"
@ -47,12 +47,12 @@ file_merge_tree() {
local prompt_verb="In configuration only" local prompt_verb="In configuration only"
local prompt_options="Copy to system" local prompt_options="Copy to system"
fi fi
strategy="$(ask "$prompt_verb: $(tildify "$absolute_path")" "$prompt_options")" overwrite_choice="$(ask "$prompt_verb: $(tildify "$absolute_path")" "$prompt_options")"
log debug "[merge_tree] Chosen strategy: $strategy" log debug "[merge_tree] Overwrite choice: $overwrite_choice"
if [ "$strategy" -eq 0 ]; then if [ "$overwrite_choice" -eq 0 ]; then
return 0 return 0
elif [ "$strategy" -eq 1 ]; then elif [ "$overwrite_choice" -eq 1 ]; then
backup_paths "$absolute_path" backup_paths "$absolute_path"
if [ -r "$config_path" ] && [ -w "$absolute_path" ]; then if [ -r "$config_path" ] && [ -w "$absolute_path" ]; then
cp -vi "$config_path" "$absolute_path" cp -vi "$config_path" "$absolute_path"
@ -60,7 +60,7 @@ file_merge_tree() {
$AUTHORIZE_COMMAND cp -vi "$config_path" "$absolute_path" $AUTHORIZE_COMMAND cp -vi "$config_path" "$absolute_path"
fi fi
return 1 return 1
elif [ "$strategy" -eq 2 ]; then elif [ "$overwrite_choice" -eq 2 ]; then
backup_paths "$config_path" backup_paths "$config_path"
if [ -r "$absolute_path" ] && [ -w "$config_path" ]; then if [ -r "$absolute_path" ] && [ -w "$config_path" ]; then
cp -vi "$absolute_path" "$config_path" cp -vi "$absolute_path" "$config_path"
@ -68,7 +68,7 @@ file_merge_tree() {
$AUTHORIZE_COMMAND cp -vi "$absolute_path" "$config_path" $AUTHORIZE_COMMAND cp -vi "$absolute_path" "$config_path"
fi fi
return 1 return 1
elif [ "$strategy" -eq 3 ]; then elif [ "$overwrite_choice" -eq 3 ]; then
echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >" echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >"
if [ -r "$absolute_path" ] && [ -r "$config_path" ]; then if [ -r "$absolute_path" ] && [ -r "$config_path" ]; then
diff "$absolute_path" "$config_path" diff "$absolute_path" "$config_path"

2
tori
View file

@ -2,7 +2,7 @@
main() { main() {
# paths # paths
VERSION="0.5.0 2024-07-18" VERSION="0.6.0 2024-09-03"
TORI_ROOT="$HOME/.local/share/tori" TORI_ROOT="$HOME/.local/share/tori"
CONFIG_ROOT="$HOME/.config/tori" CONFIG_ROOT="$HOME/.config/tori"
BACKUP_ROOT="$HOME/.local/state/tori/backup" BACKUP_ROOT="$HOME/.local/state/tori/backup"