Handle more corner cases on configuration parsing

- Handle absent configuration file
- Handle invalid installation root path
This commit is contained in:
Juno Takano 2024-07-07 21:32:41 -03:00
parent e81630490c
commit e887be09c5
2 changed files with 22 additions and 6 deletions

View file

@ -1 +1,2 @@
0.1.0 2024-07-07: Added configuration parsing
0.1.1 2024-07-07: Handle missing configuration file and invalid installation root

View file

@ -7,7 +7,7 @@ main() {
CONFIG_ROOT="$HOME/.config/tori"
TMP_DIR="/tmp/tori"
read_config_paths
check_core_paths
. "$TORI_ROOT/src/index.sh"
@ -45,11 +45,26 @@ main() {
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" \
)"
check_core_paths() {
local tori_conf="$CONFIG_ROOT/tori.conf"
if [ -f "$tori_conf" ]; then
local tori_root_value
tori_root_value="$(grep -i '^tori_root' "$CONFIG_ROOT/tori.conf" \
| cut -d '=' -f 2 | xargs \
| sed "s*~*$HOME*" | sed "s*\$HOME*$HOME*g" \
)"
if [ -n "$tori_root_value" ]; then
TORI_ROOT="$tori_root_value"
fi
fi
if ! [ -f "$TORI_ROOT/src/index.sh" ]; then
echo "No valid tori installation found at $TORI_ROOT"
exit 1
fi
[ -n "$DEBUG" ] && echo "TORI_ROOT: $TORI_ROOT"
}