<commit_before>#!/bin/bash

test_for_cloud_db() {
  RESULT=`mysqlshow --user=root --password=<PASSWORD> --host=$DB_PORT_3306_TCP_ADDR | grep -o cloud | uniq`
  if [ "$RESULT" == "cloud" ]; then
    echo "Cloud DB exists. Starting CloudStack."
    cd /usr/share/cloudstack-management/bin
    ./catalina.sh run
  else
    echo "Cloud DB does not exist. Creating it."
    cloudstack-setup-databases cloud:cloudstack@$DB_PORT_3306_TCP_ADDR --deploy-as=root:cloud -m cloudstack -k cloudstack
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-40to410.sql
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-40to410-cleanup.sql
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-410to420.sql cloud 
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-410to420-cleanup.sql cloud
    sed -i.bak s/\-\-Add/\-\-\ Add/ /usr/share/cloudstack-management/setup/db/schema-420to421.sql
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-420to421.sql cloud
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-421to430.sql cloud
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-421to430-cleanup.sql cloud
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack cloud -e "UPDATE version SET version = '4.3.0', updated=now() WHERE id=1;"
    echo "DB Created."
    sleep 5
    test_for_cloud_db
  fi
}

test_for_cloud_db<commit_msg>Fixed against a case where the DB existed but the config on the management server was bad.<commit_after>#!/bin/bash

test_for_db_config() {
  CONFIG_CHECK=`cat /etc/cloudstack/management/db.properties | grep db.cloud.host=localhost`
  if [ "$CONFIG_CHECK" == "db.cloud.host=localhost" ]; then
    echo "db.properties misconfigured. Fixing this."
    cloudstack-setup-databases cloud:cloudstack@$DB_PORT_3306_TCP_ADDR -m cloudstack -k cloudstack
    test_for_db_config
  else
    echo "Everything's good. Starting CloudStack."
    cd /usr/share/cloudstack-management/bin
    ./catalina.sh run
  fi
}

test_for_cloud_db() {
  RESULT=`mysqlshow --user=root --password=<PASSWORD> --host=$DB_PORT_3306_TCP_ADDR | grep -o cloud | uniq`
  if [ "$RESULT" == "cloud" ]; then
    echo "Cloud DB exists. Starting CloudStack."
    test_for_db_config
  else
    echo "Cloud DB does not exist. Creating it."
    cloudstack-setup-databases cloud:cloudstack@$DB_PORT_3306_TCP_ADDR --deploy-as=root:cloud -m cloudstack -k cloudstack
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-40to410.sql
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-40to410-cleanup.sql
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-410to420.sql cloud 
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-410to420-cleanup.sql cloud
    sed -i.bak s/\-\-Add/\-\-\ Add/ /usr/share/cloudstack-management/setup/db/schema-420to421.sql
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-420to421.sql cloud
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-421to430.sql cloud
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack < /usr/share/cloudstack-management/setup/db/schema-421to430-cleanup.sql cloud
    mysql -h $DB_PORT_3306_TCP_ADDR -u cloud -pcloudstack cloud -e "UPDATE version SET version = '4.3.0', updated=now() WHERE id=1;"
    echo "DB Created."
    sleep 5
    test_for_cloud_db
  fi
}

test_for_cloud_db
{'fraction_non_alphanumeric': 0.1190897597977244, 'fraction_numerical': 0.04702907711757269, 'mean_word_length': 3.812652068126521, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '247208', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1386, 'n_words': 290}