Compare commits

..

2 commits

12 changed files with 127 additions and 53 deletions

4
docs/usage/backups.md Normal file
View file

@ -0,0 +1,4 @@
tori creates a backup directory called `bkp` that contains two top-level directories:
- `canonical`: Canonical backups are created the first time tori is told to modify a given file. If there is already a canonical backup, it defers to the cretaion of an ephemeral one. If tori is running against a recently-instaled system, the canonical backups should be close to the original state of the system as of its installation.
- `ephemeral`: Ephemeral backups are timestamped backups created every time tori has to modify a file. This is mainly meant as a safety net against undesired consequences when using non-interactive options.

View file

@ -0,0 +1,47 @@
tori looks for configuration in `~/.config/tori`.
In this directory, you can create the following files and directories:
- `tori.conf`: configures options that will determine how tori itself behaves
- `packages`: a list of packages containing one package name per line
- blank lines and lines beginning with a `#` are ignored
- `base`: a directory containing any number of files you can tell tori to copy to specific locations
## Configuration options
The `tori.conf` file must use the following format:
```conf
tori_root = ~/.local/apps/my-tori-installation
```
The following configuration options can be used to specify how you want tori to behave:
- `tori_root`
Configuration options are case insensitive. The spaces around the `=` character are optional. Blank lines and lines beginning with a `#` are ignored.
You can use `~` and `$HOME` to represent your home directory. `$HOME` will be replaced in every occasion with your home directory, while `~` will only be replaced for the first occasion it appears in the configuration value.
Configuration values must _not_ contain the character `*`.
## Package lists
tori will read the `packages` file and check if it matches the currently installed packages. If it does not match, it will ask you how to proceed.
If you would prefer not to be asked how to proceed, you can configure a default action to be taken for package mismatch resolution.
## Base files
tori will go through the contents of the `base` directory and take different actions depending on how they are laid out.
If you have top-level directories inside `base` that match the directories starting from your system's root (for example, a `base/etc` directory), tori will recursively inspect this directory for files and compare them to the contents of the matching directories in the system.
If any of the files differ from their counterparts on the actual system, tori will ask you how to proceed. If you do not want to be asked every time, you can configure tori to take a specific action without asking.
If you decide to do so, bear in mind important files may get overwritten without warning. tori will create backups in the `bkp` directory every time a file is modified or overwritten.
If you would rather not replicate the system directory hierarchy in your `base`directory, you can also place the files inside `base` itself or in any other structure you desire.
In this case, you will have to manually specify if you want these files to be matched against any system-level files, and, if so, where those files are.

View file

@ -1,34 +1,41 @@
# configuration processing functions
scan_directory() {
local target="$1"
local files=
local escaped_config_root="$(echo $CONFIG_ROOT | sed 's/\//\\\//g')"
local target="$1"
local files=
local escaped_config_root
if [ -d "$target" ]; then
scan="$(find "$target" -type f)"
for line in $scan; do
line="$(echo $line | sed "s/$escaped_config_root\///")"
files="$line\n$files"
done
fi
escaped_config_root="$(echo "$CONFIG_ROOT" | sed 's/\//\\\//g')"
echo "$files"
if [ -d "$target" ]; then
scan="$(find "$target" -type f)"
for line in $scan; do
line="$(echo "$line" | sed "s/$escaped_config_root\///")"
files="$line\n$files"
done
fi
echo "$files"
}
scan_packages() {
system_packages="$(get_system_packages)"
user_packages="$(get_user_packages)"
if ! [ -f "$CONFIG_ROOT/packages" ]; then
log debug "No packages file found in $CONFIG_ROOT"
return 1
fi
if [ "$system_packages" = "$user_packages" ]; then
log debug "packages match"
else
log debug "packages mismatch"
log debug "system: $system_packages"
log debug "user: $user_packages"
system_packages="$(get_system_packages)"
user_packages="$(get_user_packages)"
log user "System and configuration packages differ"
resolve_packages
fi
if [ "$system_packages" = "$user_packages" ]; then
log debug "packages match"
else
log debug "packages mismatch"
log debug "system: $system_packages"
log debug "user: $user_packages"
log user "System and configuration packages differ"
resolve_packages
fi
}

View file

@ -6,8 +6,8 @@ get_operating_system() {
/etc/os-release | grep '^ID=' | sed 's/ID=//')"
log debug "uname OS: $uname_output"
log debug "os-release OS name: $os_release_name"
log debug "os-release OS ID: $os_release_id"
log debug "os-release name: $os_release_name"
log debug "os-release ID: $os_release_id"
if [ "$os_release_name" = FreeBSD ]; then
echo "FreeBSD"

View file

@ -1,40 +1,56 @@
#! /usr/bin/env sh
# paths
VERSION="0.0.4 2024-06-30"
TORI_ROOT="$HOME/tori"
CONFIG_ROOT="$HOME/.config/tori"
TMP_DIR="/tmp/tori"
main() {
# paths
VERSION="0.0.4 2024-06-30"
TORI_ROOT="$HOME/.local/share/tori"
CONFIG_ROOT="$HOME/.config/tori"
TMP_DIR="/tmp/tori"
. "$TORI_ROOT/src/index.sh"
read_config_paths
# state
. "$TORI_ROOT/src/index.sh"
## user input
argument="$1"
parameter="$2"
# state
set_opts -
DEBUG=$DEBUG
## global constants
OS="$(get_operating_system)"
## user input
argument="$1"
parameter="$2"
## global state
base_files=
bkp_files=
user_packages=
system_packages=
set_opts -
# entry point
## global constants
OS="$(get_operating_system)"
prepare_directories
## global state
base_files=
bkp_files=
user_packages=
system_packages=
if [ "$argument" = check ]; then
check
elif [ "$argument" = version ] || [ "$argument" = -v ] || [ "$argument" = --version ]; then
echo "$VERSION"
elif [ "$argument" = help ] || [ "$argument" = -h ] || [ "$argument" = --help ]; then
print_help
else
echo "Use 'tori help' for usage instructions"
fi
# entry point
prepare_directories
if [ "$argument" = check ]; then
check
elif [ "$argument" = version ] || [ "$argument" = -v ] || [ "$argument" = --version ]; then
echo "$VERSION"
elif [ "$argument" = help ] || [ "$argument" = -h ] || [ "$argument" = --help ]; then
print_help
else
echo "Use 'tori help' for usage instructions"
fi
}
read_config_paths() {
TORI_ROOT="$(grep -i '^tori_root' "$CONFIG_ROOT/tori.conf" \
| cut -d '=' -f 2 | xargs \
| sed "s*~*$HOME*" | sed "s*\$HOME*$HOME*g" \
)"
[ -n "$DEBUG" ] && echo "TORI_ROOT: $TORI_ROOT"
}
main "$1" "$2"