github.com/decred/politeia@v1.4.0/politeiawww/scripts/cmssetup.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # This script sets up the CockroachDB databases and assigns user privileges.
     4  # This script requires that you have already created CockroachDB certificates
     5  # using the cockroachcerts.sh script and that you have a CockroachDB instance
     6  # listening on the default port localhost:26257.
     7  
     8  set -ex
     9  
    10  # COCKROACHDB_DIR must be the same directory that was used with the
    11  # cockroachcerts.sh script.
    12  COCKROACHDB_DIR=$1
    13  if [ "${COCKROACHDB_DIR}" == "" ]; then
    14    COCKROACHDB_DIR="${HOME}/.cockroachdb"
    15  fi
    16  
    17  # ROOT_CERTS_DIR must contain client.root.crt, client.root.key, and ca.crt.
    18  readonly ROOT_CERTS_DIR="${COCKROACHDB_DIR}/certs/clients/root"
    19  
    20  if [ ! -f "${ROOT_CERTS_DIR}/client.root.crt" ]; then
    21    >&2 echo "error: file not found ${ROOT_CERTS_DIR}/client.root.crt"
    22    exit
    23  elif [ ! -f "${ROOT_CERTS_DIR}/client.root.key" ]; then
    24    >&2 echo "error: file not found ${ROOT_CERTS_DIR}/client.root.key"
    25    exit
    26  elif [ ! -f "${ROOT_CERTS_DIR}/ca.crt" ]; then
    27    >&2 echo "error: file not found ${ROOT_CERTS_DIR}/ca.crt"
    28    exit
    29  fi
    30  
    31  # Database names.
    32  readonly DB_MAINNET="cms_mainnet"
    33  readonly DB_TESTNET="cms_testnet3"
    34  
    35  readonly GITHUB_TRACKER="ghtracker"
    36  
    37  # Database usernames.
    38  readonly 	USER_POLITEIAWWW="politeiawww" 
    39  
    40  # Create the mainnet and testnet databases for the cms database.
    41  cockroach sql \
    42    --certs-dir="${ROOT_CERTS_DIR}" \
    43    --execute "CREATE DATABASE IF NOT EXISTS ${DB_MAINNET}"
    44  
    45  cockroach sql \
    46    --certs-dir="${ROOT_CERTS_DIR}" \
    47    --execute "CREATE DATABASE IF NOT EXISTS ${DB_TESTNET}"
    48  
    49  # Create the politeiawww user and assign privileges.
    50  cockroach sql \
    51    --certs-dir="${ROOT_CERTS_DIR}" \
    52    --execute "CREATE USER IF NOT EXISTS ${USER_POLITEIAWWW}"
    53  
    54  cockroach sql \
    55    --certs-dir="${ROOT_CERTS_DIR}" \
    56    --execute "GRANT CREATE, SELECT, DROP, INSERT, DELETE, UPDATE \
    57    ON DATABASE ${DB_MAINNET} TO  ${USER_POLITEIAWWW}"
    58  
    59  cockroach sql \
    60    --certs-dir="${ROOT_CERTS_DIR}" \
    61    --execute "GRANT CREATE, SELECT, DROP, INSERT, DELETE, UPDATE \
    62    ON DATABASE ${DB_TESTNET} TO  ${USER_POLITEIAWWW}"
    63  
    64  # Create the code tracker database that contains pullrequest and review
    65  # information from gihtub.
    66  cockroach sql \
    67    --certs-dir="${ROOT_CERTS_DIR}" \
    68    --execute "CREATE DATABASE IF NOT EXISTS ${GITHUB_TRACKER}"
    69  
    70  cockroach sql \
    71    --certs-dir="${ROOT_CERTS_DIR}" \
    72    --execute "GRANT CREATE, SELECT, DROP, INSERT, DELETE, UPDATE \
    73    ON DATABASE ${GITHUB_TRACKER} TO  ${USER_POLITEIAWWW}"