From e887be09c514ccb580bcbdd3c6ac4fd8d90fd81d Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 7 Jul 2024 21:32:41 -0300 Subject: [PATCH] Handle more corner cases on configuration parsing - Handle absent configuration file - Handle invalid installation root path --- CHANGELOG | 1 + src/tori | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9f56e68..1851b04 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/src/tori b/src/tori index 96d7932..d540aec 100755 --- a/src/tori +++ b/src/tori @@ -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" }