github.com/decred/politeia@v1.4.0/politeiad/scripts/tstore-mysql-reset.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_USER_HOST: The host that the politeiad and trillian users will
    11  #   connect from; use '%' as a wildcard (default: localhost).
    12  # - POLITEIAD_DIR: politeiad application directory. This will vary depending
    13  #   on you operating system (default: ${HOME}/.politeiad).
    14  
    15  # Set unset environment variables to defaults
    16  [ -z ${MYSQL_HOST+x} ] && MYSQL_HOST="localhost"
    17  [ -z ${MYSQL_PORT+x} ] && MYSQL_PORT="3306"
    18  [ -z ${MYSQL_ROOT_USER+x} ] && MYSQL_ROOT_USER="root"
    19  [ -z ${MYSQL_ROOT_PASSWORD+x} ] && MYSQL_ROOT_PASSWORD=""
    20  [ -z ${MYSQL_USER_HOST+x} ] && MYSQL_USER_HOST="localhost"
    21  [ -z ${POLITEIAD_DIR+x} ] && POLITEIAD_DIR="${HOME}/.politeiad"
    22  
    23  flags="-u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" --verbose \
    24    --host ${MYSQL_HOST} --port ${MYSQL_PORT}"
    25  
    26  # Database users
    27  politeiad="politeiad"
    28  
    29  # Database names
    30  testnet_kv="testnet3_kv"
    31  
    32  # Delete databases
    33  mysql ${flags} -e "DROP DATABASE IF EXISTS ${testnet_kv};"
    34  
    35  # Setup kv databases. The trillian script creates the trillian databases.
    36  mysql ${flags} -e "CREATE DATABASE ${testnet_kv};"
    37  
    38  mysql ${flags} -e \
    39    "GRANT ALL ON ${testnet_kv}.* TO '${politeiad}'@'${MYSQL_USER_HOST}'"
    40  
    41  # Delete cached politeiad data
    42  politeiad_data_dir="${POLITEIAD_DIR}/data/testnet3/"
    43  echo "Warning: about to delete the following directories:
    44  ${politeiad_data_dir}"
    45  read -p "Continue? [Y/N] " answer
    46  case $answer in
    47    yes|Yes|y)
    48      rm -rf ${politeiad_data_dir}
    49      ;;
    50    no|n)
    51      echo "Delete aborted"
    52      ;;
    53  esac
    54  
    55  echo "Testnet politeiad reset complete!"
    56  echo "The trillian logs must be reset using the trillian script. See docs."
    57  echo "Mainnet politeiad resets must be done manually."
    58