Skip to content

Commit ab8e1d9

Browse files
committed
changes suggested
1 parent fd53e10 commit ab8e1d9

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

src/anaconda/.devcontainer/install_vulnerable_packages.sh

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,16 @@ for ((i=0; i<rows; i++)); do
2121
packages_array[$i,1]=${parts[1]}
2222
done
2323

24-
# Function to compare semver versions
25-
compare_semver() {
26-
# Split versions into arrays
27-
IFS='.' read -r -a version1 <<< "$1"
28-
IFS='.' read -r -a version2 <<< "$2"
29-
30-
comparison=""
31-
# Compare MAJOR version
32-
if (( ${version1[0]} > ${version2[0]} )); then
33-
comparison="greater"
34-
elif (( ${version1[0]} < ${version2[0]} )); then
35-
comparison="lesser"
36-
else
37-
# Compare MINOR version
38-
if (( ${version1[1]} > ${version2[1]} )); then
39-
comparison="greater"
40-
elif (( ${version1[1]} < ${version2[1]} )); then
41-
comparison="lesser"
42-
else
43-
# Compare PATCH version
44-
if (( ${version1[2]} > ${version2[2]} )); then
45-
comparison="greater"
46-
elif (( ${version1[2]} < ${version2[2]} )); then
47-
comparison="lesser"
48-
else
49-
comparison="equal"
50-
fi
51-
fi
52-
fi
53-
54-
echo $comparison
55-
}
56-
5724
for ((i=0; i<rows; i++)); do
5825
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" | grep '^Version:' | awk '{print $2}')
5926
if [[ -z "$CURRENT_VERSION" ]]; then
6027
echo "No version for ${packages_array[$i,0]} found in upstream i.e. base image."
6128
CURRENT_VERSION="0"
6229
fi
6330
REQUIRED_VERSION="${packages_array[$i,1]}"
64-
comparison_result=$(compare_semver "${REQUIRED_VERSION}" "${CURRENT_VERSION}")
65-
# Check if the current version installed is greater or equal to the required version
66-
if [[ $comparison_result == "greater" ]]; then
31+
GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
32+
# Check if the required_version is greater than current_version
33+
if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then
6734
echo "${packages_array[$i,0]} version v${CURRENT_VERSION} installed by the base image is not greater or equal to the required: v${REQUIRED_VERSION}"
6835
# Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager
6936
channel_name="anaconda"
@@ -78,12 +45,12 @@ for ((i=0; i<rows; i++)); do
7845
echo "No version for ${packages_array[$i,0]} found in conda channel."
7946
CONDA_VERSION="0"
8047
fi
81-
comparison_result2=$(compare_semver "${REQUIRED_VERSION}" "${CONDA_VERSION}")
82-
if [[ $comparison_result2 == "lesser" ]] || [[ $comparison_result2 == "equal" ]]; then
48+
GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
49+
if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
8350
echo -e "Conda Version: ${CONDA_VERSION} is greater than or equal to the required version: ${REQUIRED_VERSION}. \n";
8451
echo "Installing ${packages_array[$i,0]} from source from conda channel for ${REQUIRED_VERSION}..."
8552
conda install "${packages_array[$i,0]}==${CONDA_VERSION}"
86-
else
53+
elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then
8754
echo -e "Required version: ${REQUIRED_VERSION} is greater than the conda version: ${CONDA_VERSION}. \n";
8855
echo "Installing ${packages_array[$i,0]} from source from pip package manager for ${REQUIRED_VERSION}..."
8956
python3 -m pip install --upgrade "${packages_array[$i,0]}==${REQUIRED_VERSION}"

0 commit comments

Comments
 (0)