mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
This is needed to be able to reach the mysql service from other hosts or through localhost. Handling both cases here means that we can support both localhost access and host access. Signed-off-by: Kevin Morris <kevr@0cost.org>
38 lines
1.2 KiB
Bash
Executable file
38 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
set -eou pipefail
|
|
|
|
MYSQL_DATA=/var/lib/mysql
|
|
|
|
[[ -z "$DB_HOST" ]] && DB_HOST="localhost"
|
|
|
|
mariadb-install-db --user=mysql --basedir=/usr --datadir=$MYSQL_DATA
|
|
|
|
# Start it up.
|
|
mysqld_safe --datadir=$MYSQL_DATA --skip-networking &
|
|
while ! mysqladmin ping 2>/dev/null; do
|
|
sleep 1s
|
|
done
|
|
|
|
# Configure databases.
|
|
DATABASE="aurweb" # Persistent database for fastapi/php-fpm.
|
|
TEST_DB="aurweb_test" # Test database (ephemereal).
|
|
|
|
echo "Taking care of primary database '${DATABASE}'..."
|
|
mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'localhost' IDENTIFIED BY 'aur';"
|
|
mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'%' IDENTIFIED BY 'aur';"
|
|
mysql -u root -e "CREATE DATABASE IF NOT EXISTS $DATABASE;"
|
|
mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'localhost';"
|
|
mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'%';"
|
|
|
|
# Drop and create our test database.
|
|
echo "Dropping test database '$TEST_DB'..."
|
|
mysql -u root -e "DROP DATABASE IF EXISTS $TEST_DB;"
|
|
mysql -u root -e "CREATE DATABASE $TEST_DB;"
|
|
mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'localhost';"
|
|
mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'%';"
|
|
|
|
echo "Created new '$TEST_DB'!"
|
|
|
|
mysqladmin -uroot shutdown
|
|
|
|
exec "$@"
|