From 553adf5271850888ccedb6f8e1c1b50a95d27a3b Mon Sep 17 00:00:00 2001 From: Prince Datta Date: Mon, 22 Apr 2024 18:42:45 +0530 Subject: [PATCH] Fix for Debian 10 backports repo issue. (#1166) --- hue/hue.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hue/hue.sh b/hue/hue.sh index 237a233e9..c230ec3b6 100755 --- a/hue/hue.sh +++ b/hue/hue.sh @@ -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 @@ -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.