Skip to content
Merged
Prev Previous commit
Next Next commit
changes acc. to review comments..
  • Loading branch information
gauravsaini04 committed Jun 5, 2024
commit 13aac296e35d4b506fb4a13f9a307c7428b3baf0
18 changes: 7 additions & 11 deletions src/anaconda/.devcontainer/install_vulnerable_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ for ((i=0; i<rows; i++)); do
done

for ((i=0; i<rows; i++)); do
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" | grep '^Version:' | awk '{print $2}')
if [[ -z "$CURRENT_VERSION" ]]; then
echo "No version for ${packages_array[$i,0]} found in upstream i.e. base image."
CURRENT_VERSION="0"
fi
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
REQUIRED_VERSION="${packages_array[$i,1]}"
GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
# Check if the required_version is greater than current_version
if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then
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}"
# Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager
channel_name="anaconda"
CONDA_VERSION=$(conda search "${packages_array[$i,0]}" -c "$channel_name" | \
CONDA_VERSION=$(conda search --override-channels "${packages_array[$i,0]}" -c "$channel_name" | \
grep -E '^[[:alnum:]]' | \
awk '{print $2}' | \
sort -V | \
Expand All @@ -47,13 +43,13 @@ for ((i=0; i<rows; i++)); do
fi
GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
echo -e "Conda Version: ${CONDA_VERSION} is greater than or equal to the required version: ${REQUIRED_VERSION}. \n";
echo "Installing ${packages_array[$i,0]} from source from conda channel for ${REQUIRED_VERSION}..."
echo -e "Found Version v${CONDA_VERSION} in the Conda channel which is greater than or equal to the required version: v${REQUIRED_VERSION}. \n";
echo "Installing ${packages_array[$i,0]} from source from conda channel for v${REQUIRED_VERSION}..."
conda install "${packages_array[$i,0]}==${CONDA_VERSION}"
elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then
echo -e "Required version: ${REQUIRED_VERSION} is greater than the conda version: ${CONDA_VERSION}. \n";
echo "Installing ${packages_array[$i,0]} from source from pip package manager for ${REQUIRED_VERSION}..."
python3 -m pip install --upgrade "${packages_array[$i,0]}==${REQUIRED_VERSION}"
echo -e "Required version: v${REQUIRED_VERSION} is greater than the version found in the Conda channel v${CONDA_VERSION}. \n";
echo "Installing ${packages_array[$i,0]} from source from pip package manager for v${REQUIRED_VERSION}..."
python3 -m pip install --upgrade --no-cache-dir "${packages_array[$i,0]}==${REQUIRED_VERSION}"
fi
fi
done