github.com/letsencrypt/boulder@v0.20251208.0/test/vtcomboserver/setup_vschema_folder.sh (about)

     1  #!/bin/bash
     2  
     3  # Copied from Vitess's own setup_vschema_folder.sh:
     4  # https://github.com/vitessio/vitess/blob/v22.0.1/docker/vttestserver/setup_vschema_folder.sh
     5  
     6  # Copyright 2021 The Vitess Authors.
     7  #
     8  # Licensed under the Apache License, Version 2.0 (the "License");
     9  # you may not use this file except in compliance with the License.
    10  # You may obtain a copy of the License at
    11  #
    12  #     http://www.apache.org/licenses/LICENSE-2.0
    13  #
    14  # Unless required by applicable law or agreed to in writing, software
    15  # distributed under the License is distributed on an "AS IS" BASIS,
    16  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17  # See the License for the specific language governing permissions and
    18  # limitations under the License.
    19  
    20  # getLength gets the number of elements in a comma separated string
    21  function getLength() {
    22    COUNT=0
    23    for _ in ${1//,/ }
    24    do
    25      ((COUNT++))
    26    done
    27    echo "$COUNT"
    28  }
    29  
    30  # The first argument to the file is a comma separated list of keyspaces and the second argument is the comma separated list of number of shards.
    31  
    32  KEYSPACES="$1"
    33  NUM_SHARDS="$2"
    34  
    35  COUNT_KEYSPACES=$(getLength "$KEYSPACES")
    36  COUNT_NUM_SHARDS=$(getLength "$NUM_SHARDS")
    37  
    38  # Incase the number of keyspaces and num_shards do not match, throw an error
    39  if [ "$COUNT_KEYSPACES" != "$COUNT_NUM_SHARDS" ]; then
    40    echo "Incompatible list of keyspaces and number of shards"
    41    exit 1
    42  fi
    43  
    44  # Convert the strings to lists
    45  read -ra KEYSPACES_LIST <<<"${KEYSPACES//,/ }"
    46  read -ra NUM_SHARDS_LIST <<<"${NUM_SHARDS//,/ }"
    47  
    48  # create the main schema directory
    49  mkdir -p /vt/schema/
    50  
    51  i=0;
    52  for keyspace in "${KEYSPACES_LIST[@]}"; do
    53    # create a directory for each keyspace
    54    mkdir -p "/vt/schema/$keyspace"
    55    num_shard=${NUM_SHARDS_LIST[$i]}
    56    # Create a vschema.json file only if the number of shards are more than 1
    57    if [[ $num_shard -gt "1" ]]; then
    58      printf "{\n\t\"sharded\": true\n}\n" > "/vt/schema/$keyspace/vschema.json"
    59    fi
    60    ((i++))
    61  done