You've already forked bash-helper
logic changes
This commit is contained in:
19
helper
19
helper
@@ -238,15 +238,28 @@ git_clone_if_missing() {
|
|||||||
setup_mariadb() {
|
setup_mariadb() {
|
||||||
local mariapwd="$1" dbname="$2" dbuser="$3" dbpass="$4"
|
local mariapwd="$1" dbname="$2" dbuser="$3" dbpass="$4"
|
||||||
|
|
||||||
if [[ -z "$mariapwd" || -z "$dbname" || -z "$dbuser" || -z "$dbpass" ]]; then
|
if [[ -z "$mariapwd" || -z "$dbname" || -z "$dbuser" || -z "$dbpass" ]]; then
|
||||||
echo "Error: setup_mariadb requires mariapwd, dbname, dbuser, dbpass"
|
echo "Error: setup_mariadb requires mariapwd, dbname, dbuser, dbpass"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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 DATABASE IF NOT EXISTS \`$dbname\`;
|
||||||
CREATE USER IF NOT EXISTS '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';
|
CREATE USER IF NOT EXISTS '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';
|
||||||
GRANT ALL PRIVILEGES ON \`$dbname\`.* TO '$dbuser'@'localhost';
|
GRANT ALL PRIVILEGES ON \`$dbname\`.* TO '$dbuser'@'localhost';
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Remove the temporary file
|
||||||
|
rm -f "$tmpfile"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user