You've already forked bash-helper
logic changes
This commit is contained in:
23
helper
23
helper
@@ -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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user