Skip to content

Commit

Permalink
Modifications in cpan modules installation in the airgapped installer…
Browse files Browse the repository at this point in the history
… script (#2021)
  • Loading branch information
ShivanshGahlot authored Dec 3, 2024
1 parent ee4cc05 commit b6e0880
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions installer_scripts/install-voyager-airgapped.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ install_perl_module() {
local requirement_type="$2"
local required_version="$3"
local package="$4"

echo "Installing module $module_name..."

# Check if the module is already installed and meets the version requirements
check_perl_module_version "$module_name" "$requirement_type" "$required_version" "true"
if [[ $? -eq 0 ]]; then
return
fi

# Extract the package
tar -xzvf "$package" 1>&2 || { echo "Error: Failed to extract $package"; exit 1; }
Expand Down Expand Up @@ -183,35 +187,56 @@ install_perl_module() {
# Return to the original directory
cd ..

# Verification and version check
# Verification of the installed module
check_perl_module_version "$module_name" "$requirement_type" "$required_version" "false"
if [[ $? -ne 0 ]]; then
exit 1
fi
}

check_perl_module_version() {
local module_name="$1"
local requirement_type="$2"
local required_version="$3"
local check_only="$4" # If "true", suppress error messages and exit silently

# Get installed version
local installed_version
installed_version=$(perl -M"$module_name" -e 'print $'"$module_name"'::VERSION' 2> /dev/null)

if [[ -z "$installed_version" ]]; then
echo "Error: $module_name could not be loaded or found."
exit 1
if [[ "$check_only" != "true" ]]; then
echo "Error: $module_name could not be loaded or found."
fi
return 1
fi

# Version comparison based on requirement type
if [[ "$requirement_type" == "min" ]]; then
# Check if installed version is at least the required version
if [[ $(echo -e "$installed_version\n$required_version" | sort -V | head -n1) != "$required_version" ]]; then
if [[ $(echo -e "$installed_version\n$required_version" | sort -V | head -n1) == "$required_version" ]]; then
return 0
fi
if [[ "$check_only" != "true" ]]; then
echo "Error: Installed version of $module_name ($installed_version) does not meet the minimum required version ($required_version)."
exit 1
fi
return 1
elif [[ "$requirement_type" == "exact" ]]; then
# Check if installed version matches the required version exactly
if [[ "$installed_version" != "$required_version" ]]; then
if [[ "$installed_version" == "$required_version" ]]; then
return 0
fi
if [[ "$check_only" != "true" ]]; then
echo "Error: Installed version of $module_name ($installed_version) does not match the exact required version ($required_version)."
exit 1
fi
return 1
else
echo "Error: Unknown requirement type '$requirement_type' for $module_name."
exit 1
fi

echo ""
}


check_binutils_version() {
min_required_version='2.25'

Expand Down Expand Up @@ -428,9 +453,6 @@ centos_main() {
echo ""
echo -e "\e[33mYum packages:\e[0m"
print_dependencies "${centos_yum_package_requirements[@]}"
echo ""
echo -e "\e[33mCPAN modules:\e[0m"
print_dependencies "${cpan_modules_requirements[@]}"
print_steps_to_install_oic_on_centos
exit 0
fi
Expand Down Expand Up @@ -609,9 +631,6 @@ ubuntu_main() {
echo ""
echo -e "\e[33mApt packages:\e[0m"
print_dependencies "${ubuntu_apt_package_requirements[@]}"
echo ""
echo -e "\e[33mCPAN modules:\e[0m"
print_dependencies "${cpan_modules_requirements[@]}"
print_steps_to_install_oic_on_ubuntu
exit 0
fi
Expand Down

0 comments on commit b6e0880

Please sign in to comment.