Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ VENV_DIR="${VENV_DIR:-/opt/deepops/env}" # Path to python virtual environ

# Set distro-specific variables
. /etc/os-release
DEPS_DEB=(git virtualenv python3-virtualenv sshpass wget)
DEPS_EL7=(git libselinux-python3 python-virtualenv python3-virtualenv sshpass wget)
DEPS_EL8=(git python3-libselinux python3-virtualenv sshpass wget)
DEPS_DEB=(git virtualenv python3-virtualenv sshpass wget jq)
DEPS_EL7=(git libselinux-python3 python-virtualenv python3-virtualenv sshpass wget jq)
DEPS_EL8=(git python3-libselinux python3-virtualenv sshpass wget jq)
EPEL_VERSION="$(echo ${VERSION_ID} | sed 's/^[^0-9]*//;s/[^0-9].*$//')"
EPEL_URL="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${EPEL_VERSION}.noarch.rpm"
PROXY_USE=`grep -v ^# ${SCRIPT_DIR}/deepops/proxy.sh 2>/dev/null | grep -v ^$ | wc -l`
Expand Down Expand Up @@ -87,6 +87,35 @@ case "$ID" in
;;
esac

# Check Local Python and Ansible Compatibility
PYVER=$($PYTHON_BIN -V 2>&1 | grep -oP '[0-9]+\.[0-9]+(\.[0-9]+)?')
JSON=$(wget -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json")
[[ -z "$JSON" || "$JSON" == *"Not Found"* ]] && { echo "Not found: Ansible $ANSIBLE_VERSION"; exit 1; }
Comment on lines +92 to +93
Copy link

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Relying on response content to detect a missing package can be brittle. Consider checking the HTTP status code (e.g., with wget --server-response or using curl -s -o /dev/null -w '%{http_code}') before parsing the body.

Suggested change
JSON=$(wget -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json")
[[ -z "$JSON" || "$JSON" == *"Not Found"* ]] && { echo "Not found: Ansible $ANSIBLE_VERSION"; exit 1; }
HTTP_STATUS=$(wget --server-response -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json" 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1)
if [[ "$HTTP_STATUS" != "200" ]]; then
echo "Not found: Ansible $ANSIBLE_VERSION (HTTP status: $HTTP_STATUS)"
exit 1
fi
JSON=$(wget -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json")

Copilot uses AI. Check for mistakes.

REQ=$(echo "$JSON" | jq -r '.info.requires_python // empty')
[[ -z "$REQ" ]] && { echo "Pass: no Python constraint"; exit 0; }

cmp() {
a=$1 b=$2; [[ "$(printf '%s\n%s' "$a" "$b" | sort -V | head -n1)" == "$a" ]]
}

check_python_compatibility() {
for c in $(sed 's/,//g' <<< "$1"); do
Copy link

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constraint parsing removes commas instead of splitting on them, so multi-part requirements like ">=2.7,<4.0" become a single token. Replace sed 's/,//g' with sed 's/,/ /g' to iterate over each requirement separately.

Suggested change
for c in $(sed 's/,//g' <<< "$1"); do
for c in $(sed 's/,/ /g' <<< "$1"); do

Copilot uses AI. Check for mistakes.
op=${c//[0-9.]/}; ver=${c//[<>=]/}
case $op in
"==") [[ "$2" == "$ver" ]] || return 1 ;;
">=") cmp "$ver" "$2" || return 1 ;;
"<=") cmp "$2" "$ver" || return 1 ;;
">") cmp "$ver" "$2" && [[ "$2" != "$ver" ]] || return 1 ;;
"<") cmp "$2" "$ver" && [[ "$2" != "$ver" ]] || return 1 ;;
esac
done
}

check_python_compatibility "$REQ" "$PYVER" && {
echo "Compatible: Python $PYVER satisfies Ansible $ANSIBLE_VERSION requirement. $REQ"; } || {
echo "Incompatible: Python $PYVER does not satisfy Ansible $ANSIBLE_VERSION requirement. $REQ"; exit 1; }

# Create virtual environment and install python dependencies
if command -v virtualenv &> /dev/null ; then
sudo mkdir -p "${VENV_DIR}"
Expand Down