Skip to content

Commit

Permalink
Fix for pip-install.sh - Debian buster repo issue (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuldeepkk-dev committed Apr 29, 2024
1 parent c9ff5be commit a84a7eb
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion python/pip-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
set -exo pipefail

readonly PACKAGES=$(/usr/share/google/get_metadata_value attributes/PIP_PACKAGES || true)
readonly OS_NAME=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)

# Detect dataproc image version from its various names
if (! test -v DATAPROC_IMAGE_VERSION) && test -v DATAPROC_VERSION; then
DATAPROC_IMAGE_VERSION="${DATAPROC_VERSION}"
fi

function remove_old_backports {
# This script uses 'apt-get update' and is therefore potentially dependent on
# backports repositories which have been archived. In order to mitigate this
# problem, we will remove any reference to backports repos older than oldstable

# https://github.com/GoogleCloudDataproc/initialization-actions/issues/1157
oldstable=$(curl -s https://deb.debian.org/debian/dists/oldstable/Release | awk '/^Codename/ {print $2}');
stable=$(curl -s https://deb.debian.org/debian/dists/stable/Release | awk '/^Codename/ {print $2}');

matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list*)"
if [[ -n "$matched_files" ]]; then
for filename in "$matched_files"; do
grep -e "$oldstable-backports" -e "$stable-backports" "$filename" || \
sed -i -e 's/^.*-backports.*$//' "$filename"
done
fi
}

function err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
Expand Down Expand Up @@ -42,7 +67,9 @@ function main() {
echo "ERROR: Must specify PIP_PACKAGES metadata key"
exit 1
fi

if [[ ${OS_NAME} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then
remove_old_backports
fi
install_pip
run_with_retry pip install --upgrade ${PACKAGES}
}
Expand Down

0 comments on commit a84a7eb

Please sign in to comment.