From 9508e07ece3f43e8a568dff14fb6faa9d716fd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Iwanicki?= Date: Mon, 25 Aug 2025 14:36:04 +0200 Subject: [PATCH] dts-functions: parse_config: move error printing to function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To remove unnecessary code duplication Signed-off-by: MichaƂ Iwanicki --- include/dts-functions.sh | 41 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/include/dts-functions.sh b/include/dts-functions.sh index 388491b..a2c30c2 100644 --- a/include/dts-functions.sh +++ b/include/dts-functions.sh @@ -313,16 +313,7 @@ board_config() { fi ;; "NV4xPZ") - parse_config "$SYSTEM_VENDOR" "$SYSTEM_MODEL" "$BOARD_MODEL" - result=$? - if [ $result -eq 1 ]; then - print_error "Vendor $VENDOR is currently not supported!" - return 1 - elif [ $result -eq 2 ]; then - print_error "System model $SYSTEM_MODEL is currently not supported!" - return 1 - elif [ $result -eq 3 ]; then - print_error "Board model $BOARD_MODEL is currently now supported" + if ! parse_config "$SYSTEM_VENDOR" "$SYSTEM_MODEL" "$BOARD_MODEL"; then return 1 fi @@ -622,16 +613,7 @@ board_config() { esac ;; "PC Engines") - parse_config "$SYSTEM_VENDOR" "$SYSTEM_MODEL" "$BOARD_MODEL" - result=$? - if [ $result -eq 1 ]; then - print_error "Vendor $VENDOR is currently not supported!" - return 1 - elif [ $result -eq 2 ]; then - print_error "System model $SYSTEM_MODEL is currently not supported!" - return 1 - elif [ $result -eq 3 ]; then - print_error "Board model $BOARD_MODEL is currently now supported" + if ! parse_config "$SYSTEM_VENDOR" "$SYSTEM_MODEL" "$BOARD_MODEL"; then return 1 fi @@ -641,16 +623,7 @@ board_config() { "HARDKERNEL") case "$SYSTEM_MODEL" in "ODROID-H4") - parse_config "$SYSTEM_VENDOR" "$SYSTEM_MODEL" "$BOARD_MODEL" - result=$? - if [ $result -eq 1 ]; then - print_error "Vendor $VENDOR is currently not supported!" - return 1 - elif [ $result -eq 2 ]; then - print_error "System model $SYSTEM_MODEL is currently not supported!" - return 1 - elif [ $result -eq 3 ]; then - print_error "Board model $BOARD_MODEL is currently now supported" + if ! parse_config "$SYSTEM_VENDOR" "$SYSTEM_MODEL" "$BOARD_MODEL"; then return 1 fi ;; @@ -1922,6 +1895,7 @@ parse_config() { # shellcheck disable=SC2046 output=$(jq -r 'to_entries[] | select(.key != "models") | "\(.key | ascii_upcase)=\"\(.value|tostring)\""' $json_file 2>>"$ERR_LOG_FILE") if [ -z "$output" ]; then + print_error "Vendor $vendor is currently not supported!" return 1 fi eval "$output" @@ -1944,7 +1918,8 @@ parse_config() { | "\(.key | ascii_upcase)=\"\(.value|tostring)\"" ' $json_file 2>>"$ERR_LOG_FILE") if [ -z "$output" ]; then - return 2 + print_error "System model $system_model is currently not supported!" + return 1 fi eval "$output" @@ -1968,10 +1943,10 @@ parse_config() { | "\(.key | ascii_upcase)=\"\(.value|tostring)\"" ' $json_file 2>>"$ERR_LOG_FILE") if [ -z "$output" ]; then - return 3 + print_error "Board model $board_model is currently not supported" + return 1 fi eval "$output" fi return 0 - }