Extract configuration file scanning to functions
This commit is contained in:
parent
b2d2557a27
commit
0079047ab6
3 changed files with 24 additions and 9 deletions
25
check
25
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"
|
||||
|
|
|
@ -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.
|
7
docs/user-files.md
Normal file
7
docs/user-files.md
Normal file
|
@ -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.
|
Loading…
Reference in a new issue