logic changes

This commit is contained in:
2025-08-29 10:59:06 +02:00
parent 42b15e8a27
commit e3a419885c

23
helper
View File

@@ -238,15 +238,28 @@ git_clone_if_missing() {
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
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 a temporary MySQL defaults file
local tmpfile
tmpfile=$(mktemp)
cat >"$tmpfile" <<EOF
[client]
user=root
password=$mariapwd
EOF
# Execute the SQL safely using the temporary file
mysql --defaults-extra-file="$tmpfile" <<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
# Remove the temporary file
rm -f "$tmpfile"
}