From 0079047ab61bec016ccb435824e65d5fc9f5455f Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 26 Jun 2024 16:43:35 -0300 Subject: [PATCH] Extract configuration file scanning to functions --- check | 25 ++++++++++++++++--------- docs/{data.md => user-data.md} | 1 + docs/user-files.md | 7 +++++++ 3 files changed, 24 insertions(+), 9 deletions(-) rename docs/{data.md => user-data.md} (91%) create mode 100644 docs/user-files.md diff --git a/check b/check index fb7a3fe..0d3fdf9 100755 --- a/check +++ b/check @@ -5,6 +5,8 @@ TORI_ROOT="$HOME/.config/tori" # global state files= +base_files= +bkp_files= # application logic @@ -18,19 +20,24 @@ log() { } -traverse() { +scan_directory() { local target="$1" + local files= + local escaped_config_root="$(echo $TORI_ROOT | sed 's/\//\\\//g')" - log debug "traversing $target" if [ -d "$target" ]; then - log debug "found dir: $target" - files="$(find "$target" -type f)\n$files" + scan="$(find "$target" -type f)" + for line in $scan; do + line="$(echo $line | sed "s/$escaped_config_root\///")" + files="$line\n$files" + done fi - log debug "collected files:\n$files" + echo "$files" } -cd "$TORI_ROOT" -for item in $TORI_ROOT/*; do - traverse "$item" -done +base_files="$(scan_directory "$TORI_ROOT/base")" +bkp_files="$(scan_directory "$TORI_ROOT/bkp")" + +log debug "collected base files:\n$base_files" +log debug "collected bkp files:\n$bkp_files" diff --git a/docs/data.md b/docs/user-data.md similarity index 91% rename from docs/data.md rename to docs/user-data.md index b787837..1c14b24 100644 --- a/docs/data.md +++ b/docs/user-data.md @@ -26,3 +26,4 @@ Both of these directories mimic the file structure found from the root of the fi └── .shrc ``` +`tori` will look only for regular files inside your configuration directory and currently will ignore symbolic link and any other filetype when scanning it. diff --git a/docs/user-files.md b/docs/user-files.md new file mode 100644 index 0000000..bbdd130 --- /dev/null +++ b/docs/user-files.md @@ -0,0 +1,7 @@ +`tori` can track if a given file in the configuration directory is present and matches the content of the corresponding file on the system level. + +However, if a file changed on the system level is not in the configuration directory, `tori` can only alert you to that if the operating system provides some way to compare the present state of the system to the original one prior to user intervention. + +One example would be FreeBSD's intrusion detection system, which provides a way to know which files have been changed. Another way would be by relying on a file system that provides the ability to compare differences between snapshots, such as ZFS. A third way would be if the operating system's package manager provides a command line interface to read the contents of packages and has packages that correspond to the core system, such as Void Linux's package manager, `xbps`. + +The resource-intensiveness of each of these methods will vary greatly and therefore checking the whole system for changes can be time-consuming or provide overwhelming output. For this reason, `tori` by default operates in a more minimal fashion where you take responsibility for adding the files you would like to track to your configuration and only get warnings of untracked files when explicitly asked.