Make mysql-entrypoint.sh bashate compliant
Change-Id: I4cd9bfbfd081c65e5f40ee99c9b3c26c2c7b128d Partially-Implements: blueprint bashate-gate
This commit is contained in:
parent
74d81e610e
commit
9242f60dd9
@ -5,43 +5,43 @@ set -e
|
|||||||
. /opt/kolla/config-mysql.sh
|
. /opt/kolla/config-mysql.sh
|
||||||
|
|
||||||
if [ -z "$(ls -A /var/lib/mysql)" -a "${1%_safe}" = 'mysqld' ]; then
|
if [ -z "$(ls -A /var/lib/mysql)" -a "${1%_safe}" = 'mysqld' ]; then
|
||||||
PATH=/usr/libexec:$PATH
|
PATH=/usr/libexec:$PATH
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
if [ -z "$MARIADB_ROOT_PASSWORD" ]; then
|
if [ -z "$MARIADB_ROOT_PASSWORD" ]; then
|
||||||
echo >&2 'error: database is uninitialized and MARIADB_ROOT_PASSWORD not set'
|
echo >&2 'error: database is uninitialized and MARIADB_ROOT_PASSWORD not set'
|
||||||
echo >&2 ' Did you forget to add -e MARIADB_ROOT_PASSWORD=... ?'
|
echo >&2 ' Did you forget to add -e MARIADB_ROOT_PASSWORD=... ?'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mysql_install_db --user=mysql --datadir="$DATADIR"
|
mysql_install_db --user=mysql --datadir="$DATADIR"
|
||||||
|
|
||||||
# These statements _must_ be on individual lines, and _must_ end with
|
# These statements _must_ be on individual lines, and _must_ end with
|
||||||
# semicolons (no line breaks or comments are permitted).
|
# semicolons (no line breaks or comments are permitted).
|
||||||
# TODO proper SQL escaping on ALL the things D:
|
# TODO proper SQL escaping on ALL the things D:
|
||||||
TEMP_FILE='/tmp/mysql-first-time.sql'
|
TEMP_FILE='/tmp/mysql-first-time.sql'
|
||||||
cat > "$TEMP_FILE" <<-EOSQL
|
cat > "$TEMP_FILE" <<-EOSQL
|
||||||
DELETE FROM mysql.user ;
|
DELETE FROM mysql.user ;
|
||||||
CREATE USER 'root'@'%' IDENTIFIED BY '${MARIADB_ROOT_PASSWORD}' ;
|
CREATE USER 'root'@'%' IDENTIFIED BY '${MARIADB_ROOT_PASSWORD}' ;
|
||||||
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
|
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
|
||||||
DROP DATABASE IF EXISTS test ;
|
DROP DATABASE IF EXISTS test ;
|
||||||
EOSQL
|
EOSQL
|
||||||
|
|
||||||
|
if [ "$MARIADB_DATABASE" ]; then
|
||||||
|
echo "CREATE DATABASE IF NOT EXISTS $MARIADB_DATABASE ;" >> "$TEMP_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$MARIADB_USER" -a "$MARIADB_PASSWORD" ]; then
|
||||||
|
echo "CREATE USER '$MARIADB_USER'@'%' IDENTIFIED BY '$MARIADB_PASSWORD' ;" >> "$TEMP_FILE"
|
||||||
|
|
||||||
if [ "$MARIADB_DATABASE" ]; then
|
if [ "$MARIADB_DATABASE" ]; then
|
||||||
echo "CREATE DATABASE IF NOT EXISTS $MARIADB_DATABASE ;" >> "$TEMP_FILE"
|
echo "GRANT ALL ON $MARIADB_DATABASE.* TO '$MARIADB_USER'@'%' ;" >> "$TEMP_FILE"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$MARIADB_USER" -a "$MARIADB_PASSWORD" ]; then
|
echo 'FLUSH PRIVILEGES ;' >> "$TEMP_FILE"
|
||||||
echo "CREATE USER '$MARIADB_USER'@'%' IDENTIFIED BY '$MARIADB_PASSWORD' ;" >> "$TEMP_FILE"
|
|
||||||
|
|
||||||
if [ "$MARIADB_DATABASE" ]; then
|
set -- "$@" --init-file="$TEMP_FILE"
|
||||||
echo "GRANT ALL ON $MARIADB_DATABASE.* TO '$MARIADB_USER'@'%' ;" >> "$TEMP_FILE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo 'FLUSH PRIVILEGES ;' >> "$TEMP_FILE"
|
|
||||||
|
|
||||||
set -- "$@" --init-file="$TEMP_FILE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chown -R mysql:mysql "$DATADIR"
|
chown -R mysql:mysql "$DATADIR"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user