<commit_before>#!/bin/bash

# For SCL enablement
source $HOME/.bashrc

set -eu

# Data directory where MySQL database files live. The data subdirectory is here
# because .bashrc lives in /var/lib/mysql/ and we don't want a volume to
# override it.
MYSQL_DATADIR=/var/lib/mysql/data
MYSQL_DEFAULTS_FILE=/opt/openshift/etc/my.cnf

# Be paranoid and stricter than we should be.
# https://dev.mysql.com/doc/refman/5.5/en/identifiers.html
mysql_identifier_regex='^[a-zA-Z0-9_]+$'
mysql_password_regex='^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$'

function usage() {
	if [ $# == 2 ]; then
		echo "error: $1"
	fi
	echo "You must specify following environment variables:"
	echo "  \$MYSQL_USER (regex: '$mysql_identifier_regex')"
	echo "  \$MYSQL_PASSWORD (regex: '$mysql_password_regex')"
	echo "  \$MYSQL_DATABASE (regex: '$mysql_identifier_regex')"
	echo "Optional:"
	echo "  \$MYSQL_ROOT_PASSWORD (regex: '$mysql_password_regex')"
	exit 1
}

function check_env_vars() {
	[[ "$MYSQL_USER"     =~ $mysql_identifier_regex ]] || usage "Invalid MySQL username"
	[ ${#MYSQL_USER} -le 16 ] || usage "MySQL username too long (maximum 16 characters)"
	[[ "$MYSQL_PASSWORD" =~ $mysql_password_regex   ]] || usage "Invalid password"<commit_msg>Check for mandatory environment variables<commit_after>#!/bin/bash

# For SCL enablement
source $HOME/.bashrc

set -eu

# Data directory where MySQL database files live. The data subdirectory is here
# because .bashrc lives in /var/lib/mysql/ and we don't want a volume to
# override it.
MYSQL_DATADIR=/var/lib/mysql/data
MYSQL_DEFAULTS_FILE=/opt/openshift/etc/my.cnf

# Be paranoid and stricter than we should be.
# https://dev.mysql.com/doc/refman/5.5/en/identifiers.html
mysql_identifier_regex='^[a-zA-Z0-9_]+$'
mysql_password_regex='^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$'

function usage() {
	if [ $# == 2 ]; then
		echo "error: $1"
	fi
	echo "You must specify following environment variables:"
	echo "  \$MYSQL_USER (regex: '$mysql_identifier_regex')"
	echo "  \$MYSQL_PASSWORD (regex: '$mysql_password_regex')"
	echo "  \$MYSQL_DATABASE (regex: '$mysql_identifier_regex')"
	echo "Optional:"
	echo "  \$MYSQL_ROOT_PASSWORD (regex: '$mysql_password_regex')"
	exit 1
}

function check_env_vars() {
	if ! [[ -v MYSQL_USER && -v MYSQL_PASSWORD && -v MYSQL_DATABASE ]]; then
		usage
	fi

	[[ "$MYSQL_USER"     =~ $mysql_identifier_regex ]] || usage "Invalid MySQL username"
	[ ${#MYSQL_USER} -le 16 ] || usage "MySQL username too long (maximum 16 characters)"
	[[ "$MYSQL_PASSWORD" =~ $mysql_password_regex   ]] || usage "Invalid password"
{'fraction_non_alphanumeric': 0.15892229597813354, 'fraction_numerical': 0.01015228426395939, 'mean_word_length': 4.71875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6464270', 'n_tokens_mistral': 984, 'n_tokens_neox': 944, 'n_words': 227}