<commit_before>#!/bin/bash

PS3="
Please type the number corresponding to your selection and then press the Enter/Return key.
Your choice: "

function generate_config_file() {

  echo
  echo "**********************************"
  echo "Generating configuration file..."
  echo "**********************************"
  echo

  INSTALL_SCRIPT_HOME="util/scripts/install"
  cd $INSTALL_SCRIPT_HOME

  if [[ -e temp.config.json ]]; then
    rm temp.config.json
  fi

  touch temp.config.json

  echo "$1" > temp.config.json

  python make_config.py

  rm temp.config.json

  cd ../../.. #get back to augur root
}

function get_github_api_key() {
  echo
  echo "You will also need your GitHub API key."
  read -p "GitHub API Key: " github_api_key
  echo
}

function set_remote_db_credentials() {

  read -p "Database: " database
  read -p "Host: " host
  read -p "Port: " port
  read -p "User: " user
  read -p "Password: " password
  read -p "Key: " key

  get_github_api_key

  IFS='' read -r -d '' config <<EOF
    {
      "database": "$database",
      "host": "$host",
      "port": "$port",
      "user": "$user",
      "password": "$password",
      "key": "$key",
      "github_api_key": "$github_api_key"
    }
EOF

  generate_config_file "$config"
}

function set_local_db_credentials() {

  read -p "Database: " database
  read -p "User: " user
  read -p "Port: " port
  read -p "Password: " password
  read -p "Key: " key

  get_github_api_key

  IFS='' read -r -d '' config <<EOF
  {
    "database": "$database",
    "host": "localhost",
    "port": "$port",
    "user": "$user",
    "password": "$password",
    "key": "$key",
    "github_api_key": "$github_api_key"
  }
EOF

  generate_config_file "$config"
}

echo "If you need to install Postgres, the downloads can be found here: https://www.postgresql.org/download/"
echo
install_locally="Would you like to use a LOCAL Postgres 10 or 11 installation without the database already installed?"
install_remotely="Would you like to use a REMOTE Postgres 10 or 11 installation without the database already installed?"
already_installed="Would you like to use a pre-existing Postgres 10 or 11 installation with the Augur database ALREADY installed? "
echo

select install_location in "$install_locally" "$install_remotely" "$already_installed"
do
  case $install_location in
    $install_locally )
        echo "Please set the credentials for your database."
        set_local_db_credentials
        psql -c "create database $database;"
        psql -c "create user $user with encrypted password '$password';"
        psql -c "alter database $database owner to $user;"
        psql -c "grant all privileges on database $database to $user;"
        psql -h "localhost" -d $database -U $user -p $port -a -w -f augur/persistence_schema/0-all.sql
        break
      ;;
    $install_remotely )
        echo "Please set the credentials for your database."
        set_remote_db_credentials
        psql -h $host -p $port -c "create database $database;"
        psql -h $host -p $port -c "create user $user with encrypted password '$password';"
        psql -h $host -p $port -c "alter database $database owner to $user;"
        psql -h $host -p $port -c "grant all privileges on database $database to $user;"
        psql -h $host -d $database -U $user -p $port -a -w -f augur/persistence_schema/0-all.sql
        break
      ;;
    $already_installed )
        echo "Please enter the credentials for your database."
        set_remote_db_credentials
        break
      ;;
  esac
done<commit_msg>Update install script to reflect schema location change<commit_after>#!/bin/bash

PS3="
Please type the number corresponding to your selection and then press the Enter/Return key.
Your choice: "

function generate_config_file() {

  echo
  echo "**********************************"
  echo "Generating configuration file..."
  echo "**********************************"
  echo

  INSTALL_SCRIPT_HOME="util/scripts/install"
  cd $INSTALL_SCRIPT_HOME

  if [[ -e temp.config.json ]]; then
    rm temp.config.json
  fi

  touch temp.config.json

  echo "$1" > temp.config.json

  python make_config.py

  rm temp.config.json

  cd ../../.. #get back to augur root
}

function get_github_api_key() {
  echo
  echo "You will also need your GitHub API key."
  read -p "GitHub API Key: " github_api_key
  echo
}

function set_remote_db_credentials() {

  read -p "Database: " database
  read -p "Host: " host
  read -p "Port: " port
  read -p "User: " user
  read -p "Password: " password
  read -p "Key: " key

  get_github_api_key

  IFS='' read -r -d '' config <<EOF
    {
      "database": "$database",
      "host": "$host",
      "port": "$port",
      "user": "$user",
      "password": <PASSWORD>",
      "key": "$key",
      "github_api_key": "$github_api_key"
    }
EOF

  generate_config_file "$config"
}

function set_local_db_credentials() {

  read -p "Database: " database
  read -p "User: " user
  read -p "Port: " port
  read -p "Password: " password
  read -p "Key: " key

  get_github_api_key

  IFS='' read -r -d '' config <<EOF
  {
    "database": "$database",
    "host": "localhost",
    "port": "$port",
    "user": "$user",
    "password": "$password",
    "key": "$key",
    "github_api_key": "$github_api_key"
  }
EOF

  generate_config_file "$config"
}

echo "If you need to install Postgres, the downloads can be found here: https://www.postgresql.org/download/"
echo
install_locally="Would you like to use a LOCAL Postgres 10 or 11 installation without the database already installed?"
install_remotely="Would you like to use a REMOTE Postgres 10 or 11 installation without the database already installed?"
already_installed="Would you like to use a pre-existing Postgres 10 or 11 installation with the Augur database ALREADY installed? "
echo

select install_location in "$install_locally" "$install_remotely" "$already_installed"
do
  case $install_location in
    $install_locally )
        echo "Please set the credentials for your database."
        set_local_db_credentials
        psql -c "create database $database;"
        psql -c "create user $user with encrypted password '$password';"
        psql -c "alter database $database owner to $user;"
        psql -c "grant all privileges on database $database to $user;"
        psql -h "localhost" -d $database -U $user -p $port -a -w -f /persistence_schema/0-all.sql
        break
      ;;
    $install_remotely )
        echo "Please set the credentials for your database."
        set_remote_db_credentials
        psql -h $host -p $port -c "create database $database;"
        psql -h $host -p $port -c "create user $user with encrypted password '$password';"
        psql -h $host -p $port -c "alter database $database owner to $user;"
        psql -h $host -p $port -c "grant all privileges on database $database to $user;"
        psql -h $host -d $database -U $user -p $port -a -w -f /persistence_schema/0-all.sql
        break
      ;;
    $already_installed )
        echo "Please enter the credentials for your database."
        set_remote_db_credentials
        break
      ;;
  esac
done
{'fraction_non_alphanumeric': 0.13131313131313133, 'fraction_numerical': 0.004489337822671156, 'mean_word_length': 3.0095613048368954, 'pattern_counts': {'":': 28, '<': 12, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2209899', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2182, 'n_words': 780}