Skip to content

Commit

Permalink
Fix for Debian 10 backports repo issue. (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-cs authored Apr 22, 2024
1 parent c1662bc commit 553adf5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions hue/hue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,18 @@ function retry_command() {
return 1
}

function replace_backports_repo() {
sudo sed -i 's/^.*debian buster-backports main.*$//g' /etc/apt/sources.list
echo "deb https://archive.debian.org/debian buster-backports main" | sudo tee -a /etc/apt/sources.list > /dev/null
echo "deb-src https://archive.debian.org/debian buster-backports main" | sudo tee -a /etc/apt/sources.list > /dev/null
}

function install_packages() {
local -r packages="$*"
if [[ ${OS_NAME} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then
replace_backports_repo
retry_command "apt-get update -y -qq"
fi
if command -v apt-get >/dev/null; then
retry_command "apt-get install -t $(lsb_release -sc)-backports -y ${packages}"
else
Expand Down Expand Up @@ -234,8 +244,29 @@ EOF
systemctl start hue
}

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
}

# Only run on the master node ("0"-master in HA mode) of the cluster
if [[ "$(hostname -s)" == "${MASTER_HOSTNAME}" ]]; then
if [[ ${OS_NAME} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then
remove_old_backports
fi
update_repo || echo "Ignored errors when updating OS repo index"
# DATAPROC_IMAGE_VERSION is the preferred variable, but it doesn't exist in
# old images.
Expand Down

0 comments on commit 553adf5

Please sign in to comment.