Skip to content

Commit

Permalink
[user-environment]Fix for Debian 10 backports repo issue. (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-cs committed Apr 22, 2024
1 parent 3d16c55 commit 8599bdd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions user-environment/user-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ set -o errexit
set -o nounset
set -o xtrace

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 update_apt_get() {
for ((i = 0; i < 10; i++)); do
if apt-get update; then
Expand All @@ -31,6 +57,10 @@ function update_apt_get() {
## Delete to customize all nodes.
[[ "${HOSTNAME}" =~ -m$ ]] || exit 0

if [[ ${OS_NAME} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then
remove_old_backports
fi

## Make global changes here
update_apt_get
apt-get install -y vim
Expand Down

0 comments on commit 8599bdd

Please sign in to comment.