Skip to content

Commit

Permalink
Fix for cloud-sql-proxy.sh - Debian buster repo issue (#1165)
Browse files Browse the repository at this point in the history
* Fix for bigtable.sh - Debian buster repo issue

* Added missing variables for OS_NAME and deteting dataproc versions
  • Loading branch information
kuldeepkk-dev committed Apr 19, 2024
1 parent 0985c2e commit 1beab5d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cloud-sql-proxy/cloud-sql-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1beab5d

Please sign in to comment.