added creation of db

This commit is contained in:
2025-08-29 10:27:41 +02:00
parent 9e78e1acb2
commit 42b15e8a27

19
helper
View File

@@ -231,3 +231,22 @@ git_clone_if_missing() {
echo "Cloning repository $repo into $target_dir..."
git clone --quiet --branch main "$repo" "$target_dir"
}
#
# Creates a MariaDB database and user
#
setup_mariadb() {
local mariapwd="$1" dbname="$2" dbuser="$3" dbpass="$4"
if [[ -z "$mariapwd" || -z "$dbname" || -z "$dbuser" || -z "$dbpass" ]]; then
echo "Error: setup_mariadb requires mariapwd, dbname, dbuser, dbpass"
exit 1
fi
mysql -u root -p"$mariapwd" <<EOF
CREATE DATABASE IF NOT EXISTS \`$dbname\`;
CREATE USER IF NOT EXISTS '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';
GRANT ALL PRIVILEGES ON \`$dbname\`.* TO '$dbuser'@'localhost';
FLUSH PRIVILEGES;
EOF
}