From e4ca3ac7458ca22dd97e89da859adee966b11580 Mon Sep 17 00:00:00 2001 From: a-masterov <72613290+a-masterov@users.noreply.github.com> Date: Wed, 4 Jun 2025 17:07:48 +0200 Subject: [PATCH] Fix codestyle for compute.sh for docker-compose (#12128) ## Problem The script `compute.sh` had a non-consistent coding style and didn't follow best practices for modern bash scripts ## Summary of changes The coding style was fixed to follow best practices. --- .../compute_wrapper/shell/compute.sh | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docker-compose/compute_wrapper/shell/compute.sh b/docker-compose/compute_wrapper/shell/compute.sh index ab8d74d355..c8ca812bf9 100755 --- a/docker-compose/compute_wrapper/shell/compute.sh +++ b/docker-compose/compute_wrapper/shell/compute.sh @@ -1,18 +1,18 @@ -#!/bin/bash +#!/usr/bin/env bash set -eux # Generate a random tenant or timeline ID # # Takes a variable name as argument. The result is stored in that variable. generate_id() { - local -n resvar=$1 - printf -v resvar '%08x%08x%08x%08x' $SRANDOM $SRANDOM $SRANDOM $SRANDOM + local -n resvar=${1} + printf -v resvar '%08x%08x%08x%08x' ${SRANDOM} ${SRANDOM} ${SRANDOM} ${SRANDOM} } PG_VERSION=${PG_VERSION:-14} -CONFIG_FILE_ORG=/var/db/postgres/configs/config.json -CONFIG_FILE=/tmp/config.json +readonly CONFIG_FILE_ORG=/var/db/postgres/configs/config.json +readonly CONFIG_FILE=/tmp/config.json # Test that the first library path that the dynamic loader looks in is the path # that we use for custom compiled software @@ -20,17 +20,17 @@ first_path="$(ldconfig --verbose 2>/dev/null \ | grep --invert-match ^$'\t' \ | cut --delimiter=: --fields=1 \ | head --lines=1)" -test "$first_path" == '/usr/local/lib' +test "${first_path}" = '/usr/local/lib' echo "Waiting pageserver become ready." while ! nc -z pageserver 6400; do - sleep 1; + sleep 1 done echo "Page server is ready." -cp ${CONFIG_FILE_ORG} ${CONFIG_FILE} +cp "${CONFIG_FILE_ORG}" "${CONFIG_FILE}" - if [ -n "${TENANT_ID:-}" ] && [ -n "${TIMELINE_ID:-}" ]; then + if [[ -n "${TENANT_ID:-}" && -n "${TIMELINE_ID:-}" ]]; then tenant_id=${TENANT_ID} timeline_id=${TIMELINE_ID} else @@ -41,7 +41,7 @@ else "http://pageserver:9898/v1/tenant" ) tenant_id=$(curl "${PARAMS[@]}" | jq -r .[0].id) - if [ -z "${tenant_id}" ] || [ "${tenant_id}" = null ]; then + if [[ -z "${tenant_id}" || "${tenant_id}" = null ]]; then echo "Create a tenant" generate_id tenant_id PARAMS=( @@ -51,7 +51,7 @@ else "http://pageserver:9898/v1/tenant/${tenant_id}/location_config" ) result=$(curl "${PARAMS[@]}") - echo $result | jq . + printf '%s\n' "${result}" | jq . fi echo "Check if a timeline present" @@ -61,7 +61,7 @@ else "http://pageserver:9898/v1/tenant/${tenant_id}/timeline" ) timeline_id=$(curl "${PARAMS[@]}" | jq -r .[0].timeline_id) - if [ -z "${timeline_id}" ] || [ "${timeline_id}" = null ]; then + if [[ -z "${timeline_id}" || "${timeline_id}" = null ]]; then generate_id timeline_id PARAMS=( -sbf @@ -71,7 +71,7 @@ else "http://pageserver:9898/v1/tenant/${tenant_id}/timeline/" ) result=$(curl "${PARAMS[@]}") - echo $result | jq . + printf '%s\n' "${result}" | jq . fi fi @@ -82,10 +82,10 @@ else fi echo "Adding pgx_ulid" shared_libraries=$(jq -r '.spec.cluster.settings[] | select(.name=="shared_preload_libraries").value' ${CONFIG_FILE}) -sed -i "s/${shared_libraries}/${shared_libraries},${ulid_extension}/" ${CONFIG_FILE} +sed -i "s|${shared_libraries}|${shared_libraries},${ulid_extension}|" ${CONFIG_FILE} echo "Overwrite tenant id and timeline id in spec file" -sed -i "s/TENANT_ID/${tenant_id}/" ${CONFIG_FILE} -sed -i "s/TIMELINE_ID/${timeline_id}/" ${CONFIG_FILE} +sed -i "s|TENANT_ID|${tenant_id}|" ${CONFIG_FILE} +sed -i "s|TIMELINE_ID|${timeline_id}|" ${CONFIG_FILE} cat ${CONFIG_FILE} @@ -93,5 +93,5 @@ echo "Start compute node" /usr/local/bin/compute_ctl --pgdata /var/db/postgres/compute \ -C "postgresql://cloud_admin@localhost:55433/postgres" \ -b /usr/local/bin/postgres \ - --compute-id "compute-$RANDOM" \ - --config "$CONFIG_FILE" + --compute-id "compute-${RANDOM}" \ + --config "${CONFIG_FILE}"