#!/bin/sh
# Replace mariadb_root_password, mydb, myuser, and mypassword with your desired root password, MariaDB username, and password.

# Update APK repositories
apk update

# Install MariaDB
apk add mariadb mariadb-client

# Initialize the database
mysql_install_db --user=mysql --ldata=/var/lib/mysql

# Start MariaDB
rc-service mariadb start

# Secure the MariaDB installation (optional but recommended)
mysql_secure_installation <<EOF

y # Set root password? [Y/n] 
9F2*M5*43s4& # New password
9F2*M5*43s4& # Repeat password
y # Remove anonymous users? [Y/n]
y # Disallow root login remotely? [Y/n]
y # Remove test database and access to it? [Y/n]
y # Reload privilege tables now? [Y/n]
EOF

# Create a new user and database
mysql -u root -p9F2*M5*43s4& <<EOF
CREATE USER 'cart'@'%' IDENTIFIED BY 'o74x642Rc8%6';
CREATE DATABASE cart;
GRANT ALL PRIVILEGES ON cart.* TO 'cart'@'%';
FLUSH PRIVILEGES;
EOF

# Allow remote connections (optional)
echo "[mysqld]" >> /etc/my.cnf
echo "bind-address = 0.0.0.0" >> /etc/my.cnf

# Restart MariaDB to apply changes
rc-service mariadb restart
