Skip to content

Commit

Permalink
Parse vars before being passed into mariadb
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Jun 28, 2024
1 parent d8328bd commit 94b6bb8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions dmoj/scripts/mariadb/init.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
sudo mariadb
CREATE DATABASE IF NOT EXISTS "$MYSQL_DATABASE" DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON "$MYSQL_DATABASE".* TO "$MYSQL_USER"@'localhost' IDENTIFIED BY "$MYSQL_PASSWORD";
# shellcheck disable=SC2035 # this is in a mariadb shell so it wont glob
GRANT RELOAD, PROCESS ON *.* TO "$MYSQL_USER"@'%';
#!/bin/bash

# Load environment variables from environment/mysql.env
set -a
source environment/mysql.env
source environment/mysql-admin.env
set +a

# Create SQL command with expanded variables (note the backticks for command substitution)
SQL="
CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE} DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';
GRANT RELOAD, PROCESS ON *.* TO '${MYSQL_USER}'@'%';
FLUSH PRIVILEGES;
exit
mariadb-tzinfo-to-sql /usr/share/zoneinfo | sudo mariadb -u root mysql
"

# Execute SQL command in MariaDB
mariadb -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" -e "$SQL"

0 comments on commit 94b6bb8

Please sign in to comment.