github.com/decred/politeia@v1.4.0/politeiad/scripts/tstore-mysql-setup.sh (about) 1 #!/usr/bin/env sh 2 3 # Accepts environment variables: 4 # - MYSQL_HOST: The hostname of the MySQL server (default: localhost). 5 # - MYSQL_PORT: The port the MySQL server is listening on (default: 3306). 6 # - MYSQL_ROOT_USER: A user with sufficient rights to create new users and 7 # create/drop the politeiad database (default: root). 8 # - MYSQL_ROOT_PASSWORD: The password for the user defined by MYSQL_ROOT_USER 9 # (requed, default: none). 10 # - MYSQL_POLITEIAD_PASSWORD: The password for the politeiad user that will be 11 # created during this script (required, default: none). 12 # - MYSQL_TRILLIAN_PASSWORD: The password for the trillian user that will be 13 # created during this script (required, default: none). 14 # - MYSQL_USER_HOST: The host that the politeiad and trillian users will 15 # connect from; use '%' as a wildcard (default: localhost). 16 17 # Set unset environment variables to defaults 18 [ -z ${MYSQL_HOST+x} ] && MYSQL_HOST="localhost" 19 [ -z ${MYSQL_PORT+x} ] && MYSQL_PORT="3306" 20 [ -z ${MYSQL_ROOT_USER+x} ] && MYSQL_ROOT_USER="root" 21 [ -z ${MYSQL_ROOT_PASSWORD+x} ] && MYSQL_ROOT_PASSWORD="" 22 [ -z ${MYSQL_POLITEIAD_PASSWORD+x} ] && MYSQL_POLITEIAD_PASSWORD="" 23 [ -z ${MYSQL_TRILLIAN_PASSWORD+x} ] && MYSQL_TRILLIAN_PASSWORD="" 24 [ -z ${MYSQL_USER_HOST+x} ] && MYSQL_USER_HOST="localhost" 25 26 flags="-u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" --verbose \ 27 --host ${MYSQL_HOST} --port ${MYSQL_PORT}" 28 29 # Database users 30 politeiad="politeiad" 31 trillian="trillian" 32 33 # Database names 34 testnet_kv="testnet3_kv" 35 mainnet_kv="mainnet_kv" 36 37 # Setup database users 38 mysql ${flags} -e \ 39 "CREATE USER IF NOT EXISTS '${politeiad}'@'${MYSQL_USER_HOST}' \ 40 IDENTIFIED BY '${MYSQL_POLITEIAD_PASSWORD}'" 41 42 mysql ${flags} -e \ 43 "CREATE USER IF NOT EXISTS '${trillian}'@'${MYSQL_USER_HOST}' \ 44 IDENTIFIED BY '${MYSQL_TRILLIAN_PASSWORD}'" 45 46 # Setup kv databases. The trillian script creates the trillian databases. 47 mysql ${flags} -e "CREATE DATABASE IF NOT EXISTS ${testnet_kv};" 48 mysql ${flags} -e "CREATE DATABASE IF NOT EXISTS ${mainnet_kv};" 49 50 mysql ${flags} -e \ 51 "GRANT ALL ON ${testnet_kv}.* TO '${politeiad}'@'${MYSQL_USER_HOST}'" 52 mysql ${flags} -e \ 53 "GRANT ALL ON ${mainnet_kv}.* TO '${politeiad}'@'${MYSQL_USER_HOST}'"