-
Notifications
You must be signed in to change notification settings - Fork 591
Expand file tree
/
Copy pathinstall_python310_setuptools_vulnerability.sh
More file actions
116 lines (99 loc) · 3.81 KB
/
install_python310_setuptools_vulnerability.sh
File metadata and controls
116 lines (99 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
FAILED=()
echoStderr()
{
echo "$@" 1>&2
}
check-version-ge() {
LABEL=$1
CURRENT_VERSION=$2
REQUIRED_VERSION=$3
shift
echo -e "\n🧪 Testing $LABEL: '$CURRENT_VERSION' is >= '$REQUIRED_VERSION'"
local GREATER_VERSION=$((echo ${CURRENT_VERSION}; echo ${REQUIRED_VERSION}) | sort -V | tail -1)
if [ "${CURRENT_VERSION}" == "${GREATER_VERSION}" ]; then
echo "✅ Passed!"
return 0
else
echoStderr "❌ $LABEL check failed."
FAILED+=("$LABEL")
return 1
fi
}
checkPythonPackageVersion()
{
PACKAGE=$1
REQUIRED_VERSION=$2
current_version=$(python -c "import importlib.metadata; print(importlib.metadata.version('${PACKAGE}'))")
check-version-ge "${PACKAGE}-requirement" "${current_version}" "${REQUIRED_VERSION}"
}
checkPythonPackageVersion "setuptools" "65.5.1"
# Check that tools can execute - make sure something didn't get messed up in this scenario
check "autopep8" autopep8 --version
check "black" black --version
check "yapf" yapf --version
check "bandit" bandit --version
check "flake8" flake8 --version
check "mypy" mypy --version
check "pycodestyle" pycodestyle --version
check "pydocstyle" pydocstyle --version
check "pylint" pylint --version
check "pytest" pytest --version
check "uv" uv --version
check "setuptools" pip list | grep setuptools
# Check paths in settings
check "which autopep8" bash -c "which autopep8 | grep /usr/local/py-utils/bin/autopep8"
check "which black" bash -c "which black | grep /usr/local/py-utils/bin/black"
check "which yapf" bash -c "which yapf | grep /usr/local/py-utils/bin/yapf"
check "which bandit" bash -c "which bandit | grep /usr/local/py-utils/bin/bandit"
check "which flake8" bash -c "which flake8 | grep /usr/local/py-utils/bin/flake8"
check "which mypy" bash -c "which mypy | grep /usr/local/py-utils/bin/mypy"
check "which pycodestyle" bash -c "which pycodestyle | grep /usr/local/py-utils/bin/pycodestyle"
check "which pydocstyle" bash -c "which pydocstyle | grep /usr/local/py-utils/bin/pydocstyle"
check "which pylint" bash -c "which pylint | grep /usr/local/py-utils/bin/pylint"
check "which pytest" bash -c "which pytest | grep /usr/local/py-utils/bin/pytest"
check "which uv" bash -c "which uv | grep /usr/local/py-utils/bin/uv"
checkVulnerableFile_OR_DIR()
{
for arg in "$@"; do
if [[ -e $arg ]]; then
echo -e "\n✅ Vulnerable:- ${arg} - exists in v3.10 as Vulnerability Patching has been skipped."
else
echo -e "\n❌ Vulnerable:- ${arg} - don't exist in v3.10 as Vulnerability Patching has not been skipped."
fi
done
}
# print setuptools
check "Show All Files/Folders which include setuptools" bash -c 'find / -name "*setuptools*"'
# only for 3.10
checkVulnerableFile_OR_DIR "/usr/local/py-utils/shared/lib/python3.10/site-packages/setuptools-65.5.0.dist-info" "/usr/local/lib/python3.10/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl"
# Function to check if a package is installed
checkPackageInstalled() {
if python -c "import $1" &>/dev/null; then
echo -e "\n✅ Passed! \n$1 is installed"
else
echo -e "$1 is NOT installed\n"
echoStderr "❌ check failed."
fi
}
# Function to install a package using pip
installPackage() {
python3 -m pip install "$1"
}
checkPipWorkingCorrectly() {
echo -e "\n🧪 Testing whether pip install works fine \n"
# List of packages to install via pip
packages=("numpy" "requests" "matplotlib")
# Install packages and check if installation was successful
for package in "${packages[@]}"; do
echo -e "\n🧪 Testing pip install $package\n"
installPackage "$package"
checkPackageInstalled "$package"
done
}
checkPipWorkingCorrectly
# Report result
reportResults