Revise SHell Code Logic

main
Anthony 2024-08-30 19:59:10 +08:00
parent b6cc807c70
commit df02b2aabb
1 changed files with 6 additions and 3 deletions

View File

@ -7,7 +7,7 @@ new_root_password=$(openssl rand -base64 12)
DB_NAME="wp_$(openssl rand -hex 4)" DB_NAME="wp_$(openssl rand -hex 4)"
DB_USER="wp_user_$(openssl rand -hex 4)" DB_USER="wp_user_$(openssl rand -hex 4)"
DB_PASSWORD="$(openssl rand -base64 12)" 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 root password will be: $new_root_password"
echo "New WordPress database credentials:" echo "New WordPress database credentials:"
@ -30,7 +30,7 @@ echo "Resetting the root password..."
# Reset the root password in safe mode # Reset the root password in safe mode
sudo mysql -u root <<EOF sudo mysql -u root <<EOF
FLUSH PRIVILEGES; 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; FLUSH PRIVILEGES;
EOF EOF
@ -68,7 +68,7 @@ echo "Creating WordPress database and user with the new root password..."
mysql -u root -p"$new_root_password" <<EOF mysql -u root -p"$new_root_password" <<EOF
CREATE DATABASE ${DB_NAME}; CREATE DATABASE ${DB_NAME};
CREATE USER '${DB_USER}'@'${DB_HOST}' IDENTIFIED BY '${DB_PASSWORD}'; 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; FLUSH PRIVILEGES;
EOF EOF
@ -80,6 +80,9 @@ else
exit 1 exit 1
fi fi
# Re-Start the MariaDB service normally
sudo systemctl start mariadb
# Backup the wp-config.php file before making changes # Backup the wp-config.php file before making changes
WP_CONFIG="/var/www/webroot/ROOT/wp-config.php" WP_CONFIG="/var/www/webroot/ROOT/wp-config.php"
sudo cp $WP_CONFIG $WP_CONFIG.bak sudo cp $WP_CONFIG $WP_CONFIG.bak