Revise SHell Code Logic
parent
b6cc807c70
commit
df02b2aabb
|
@ -7,7 +7,7 @@ new_root_password=$(openssl rand -base64 12)
|
|||
DB_NAME="wp_$(openssl rand -hex 4)"
|
||||
DB_USER="wp_user_$(openssl rand -hex 4)"
|
||||
DB_PASSWORD="$(openssl rand -base64 12)"
|
||||
DB_HOST="localhost" # Change if your database is hosted elsewhere
|
||||
DB_HOST="127.0.0.1" # Change if your database is hosted elsewhere
|
||||
|
||||
echo "New root password will be: $new_root_password"
|
||||
echo "New WordPress database credentials:"
|
||||
|
@ -30,7 +30,7 @@ echo "Resetting the root password..."
|
|||
# Reset the root password in safe mode
|
||||
sudo mysql -u root <<EOF
|
||||
FLUSH PRIVILEGES;
|
||||
ALTER USER 'root'@'localhost' IDENTIFIED BY '$new_root_password';
|
||||
ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '$new_root_password';
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
|
||||
|
@ -68,7 +68,7 @@ echo "Creating WordPress database and user with the new root password..."
|
|||
mysql -u root -p"$new_root_password" <<EOF
|
||||
CREATE DATABASE ${DB_NAME};
|
||||
CREATE USER '${DB_USER}'@'${DB_HOST}' IDENTIFIED BY '${DB_PASSWORD}';
|
||||
GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'${DB_HOST}';
|
||||
GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'${DB_HOST}' IDENTIFIED BY '${DB_PASSWORD}';
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
|
||||
|
@ -80,6 +80,9 @@ else
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Re-Start the MariaDB service normally
|
||||
sudo systemctl start mariadb
|
||||
|
||||
# Backup the wp-config.php file before making changes
|
||||
WP_CONFIG="/var/www/webroot/ROOT/wp-config.php"
|
||||
sudo cp $WP_CONFIG $WP_CONFIG.bak
|
||||
|
|
Loading…
Reference in New Issue