From af5512c55fd258dffead5d5624040b3267d69777 Mon Sep 17 00:00:00 2001 From: Enderson Isai Date: Thu, 8 Aug 2024 02:52:22 -0400 Subject: [PATCH 1/2] refactor check-version.sh --- install/check-version.sh | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/install/check-version.sh b/install/check-version.sh index f5389e22..7f27f007 100644 --- a/install/check-version.sh +++ b/install/check-version.sh @@ -1,27 +1,21 @@ #!/bin/bash -# Function to check if running on Ubuntu 24.04 or higher -check_ubuntu_version() { - if [ -f /etc/os-release ]; then - . /etc/os-release - if [ "$ID" = "ubuntu" ]; then - if awk -v ver="$VERSION_ID" 'BEGIN {exit !(ver >= 24.04)}'; then - return 0 - else - echo "Error: Ubuntu version must be 24.04 or higher. Current version: $VERSION_ID" >&2 - return 1 - fi - else - echo "Error: This script must be run on Ubuntu. Current OS: $ID" >&2 - return 1 - fi - else - echo "Error: Unable to determine OS. /etc/os-release file not found." >&2 - return 1 - fi -} +if [ ! -f /etc/os-release ]; then + echo "$(tput setaf 1)Error: Unable to determine OS. /etc/os-release file not found." + echo "Installation stopped." + exit 1 +fi + +. /etc/os-release + +# returns 1 if true and returns 0 if false +correct_version=$(echo "$VERSION_ID >= 24.04" | bc) -if ! check_ubuntu_version; then - echo "Script execution failed due to system requirements not being met." >&2 - exit 1 +# Check if running on Ubuntu 24.04 or higher +if [ "$ID" != "ubuntu" ] || [ $correct_version != 1 ]; then + echo "$(tput setaf 1)Error: OS requirement not met" + echo "You are currently running: $ID $VERSION_ID" + echo "OS required: ubuntu 24.04 or higher" + echo "Installation stopped." + exit 1 fi From 8044368fb6a3fda5b65f66c886b91d3ba4aea0c2 Mon Sep 17 00:00:00 2001 From: Enderson Isai Date: Tue, 13 Aug 2024 16:33:52 -0400 Subject: [PATCH 2/2] move version check to conditional --- install/check-version.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/install/check-version.sh b/install/check-version.sh index 7f27f007..8fc2e0c3 100644 --- a/install/check-version.sh +++ b/install/check-version.sh @@ -8,11 +8,8 @@ fi . /etc/os-release -# returns 1 if true and returns 0 if false -correct_version=$(echo "$VERSION_ID >= 24.04" | bc) - # Check if running on Ubuntu 24.04 or higher -if [ "$ID" != "ubuntu" ] || [ $correct_version != 1 ]; then +if [ "$ID" != "ubuntu" ] || [ $(echo "$VERSION_ID >= 24.04" | bc) != 1 ]; then echo "$(tput setaf 1)Error: OS requirement not met" echo "You are currently running: $ID $VERSION_ID" echo "OS required: ubuntu 24.04 or higher"