diff --git a/cloud-sql-proxy/cloud-sql-proxy.sh b/cloud-sql-proxy/cloud-sql-proxy.sh index d8d8b6a9d..e68d521d1 100755 --- a/cloud-sql-proxy/cloud-sql-proxy.sh +++ b/cloud-sql-proxy/cloud-sql-proxy.sh @@ -21,6 +21,14 @@ # Do not use "set -x" to avoid printing passwords in clear in the logs set -euo pipefail +# 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 + +readonly OS_NAME=$(lsb_release -is | tr '[:upper:]' '[:lower:]') +distribution=$(. /etc/os-release;echo $ID$VERSION_ID) + declare -A DEFAULT_DB_PORT=(['MYSQL']='3306' ['POSTGRES']='5432' ['SQLSERVER']='1433') declare -A DEFAULT_DB_ADMIN_USER=(['MYSQL']='root' ['POSTGRES']='postgres' ['SQLSERVER']='sqlserver') declare -A DEFAULT_DB_PROTO=(['MYSQL']='mysql' ['POSTGRES']='postgresql' ['SQLSERVER']='sqlserver') @@ -61,6 +69,24 @@ readonly METASTORE_INSTANCE ADDITIONAL_INSTANCES="$(/usr/share/google/get_metadata_value ${ADDITIONAL_INSTANCES_KEY} || echo '')" readonly ADDITIONAL_INSTANCES +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 +} + # Get metastore DB instance type, result be one of MYSQL, POSTGRES, SQLSERVER function get_cloudsql_instance_type() { local instance=$(echo "$1" | cut -d "," -f 1) @@ -606,6 +632,11 @@ function main() { role="$(/usr/share/google/get_metadata_value attributes/dataproc-role)" validate + + if [[ ${OS_NAME} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then + remove_old_backports + fi + if [[ "${role}" == 'Master' ]]; then update_master else