github.com/decred/politeia@v1.4.0/politeiawww/scripts/userdb-mysql-setup.sh (about) 1 #!/usr/bin/env sh 2 3 # This script sets up the MySQL databases for the politeiawww user data 4 # and assigns user privileges. 5 6 # Accepts environment variables: 7 # - MYSQL_HOST: The hostname of the MySQL server (default: localhost). 8 # - MYSQL_PORT: The port the MySQL server is listening on (default: 3306). 9 # - MYSQL_ROOT_USER: A user with sufficient rights to create new users and 10 # create/drop the politeiawww user database (default: root). 11 # - MYSQL_ROOT_PASSWORD: The password for the user defined by MYSQL_ROOT_USER 12 # (default: none). 13 # - MYSQL_POLITEIAWWW_PASSWORD: The password for the politeiad user that 14 # will be created during this script (required, default: none). 15 # - MYSQL_USER_HOST: The host that the politeiawww user will 16 # connect from; use '%' as a wildcard (default: localhost). 17 18 # Set unset environment variables to defaults. 19 [ -z ${MYSQL_HOST+x} ] && MYSQL_HOST="localhost" 20 [ -z ${MYSQL_PORT+x} ] && MYSQL_PORT="3306" 21 [ -z ${MYSQL_ROOT_USER+x} ] && MYSQL_ROOT_USER="root" 22 [ -z ${MYSQL_ROOT_PASSWORD+x} ] && MYSQL_ROOT_PASSWORD="" 23 [ -z ${MYSQL_POLITEIAWWW_PASSWORD+x} ] && MYSQL_POLITEIAWWW_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 names. 30 DB_MAINNET="users_mainnet" 31 DB_TESTNET="users_testnet3" 32 33 # Database usernames. 34 USER_POLITEIAWWW="politeiawww" 35 36 # Create politeiawww user. 37 mysql ${flags} -e \ 38 "CREATE USER IF NOT EXISTS '${USER_POLITEIAWWW}'@'${MYSQL_USER_HOST}' \ 39 IDENTIFIED BY '${MYSQL_POLITEIAWWW_PASSWORD}';" 40 41 # Create the mainnet and testnet databases for the politeiawww user data. 42 mysql ${flags} -e \ 43 "CREATE DATABASE IF NOT EXISTS ${DB_MAINNET};" 44 45 mysql ${flags} -e \ 46 "CREATE DATABASE IF NOT EXISTS ${DB_TESTNET};" 47 48 # Grant politeiawww user privileges. 49 mysql ${flags} -e \ 50 "GRANT ALL PRIVILEGES ON ${DB_MAINNET}.* \ 51 TO '${USER_POLITEIAWWW}'@'${MYSQL_USER_HOST}';" 52 53 mysql ${flags} -e \ 54 "GRANT ALL PRIVILEGES ON ${DB_TESTNET}.* \ 55 TO '${USER_POLITEIAWWW}'@'${MYSQL_USER_HOST}';" 56