Last active
January 27, 2024 00:48
-
-
Save khoipro/422d93a7e93ab32839e45d22e19bc0a6 to your computer and use it in GitHub Desktop.
Run a WP maintenance task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BEGIN WordPress | |
RewriteEngine On | |
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.php [L] | |
# END WordPress | |
# BEGIN Block direct access to scripts folder - By CODETOT | |
# It returns 403 HTTP status code when accessing this path | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteRule ^scripts/ - [F,L] | |
</IfModule> | |
# END Block direct access to scripts folder - By CODETOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "TASK: Check disk usage!" | |
# Target directory | |
target_dir="webapps" | |
# Iterate through each subdirectory in the target directory | |
for subdir in "$target_dir"/*/; do | |
# Ensure it's a directory and not a file | |
if [[ -d $subdir ]]; then | |
# Get the disk usage of the subdirectory | |
disk_usage=$(du -sh "$subdir" --max-depth=1 | awk '{print $1}') | |
# Print the subdirectory path and its disk usage | |
echo "$subdir: $disk_usage" | |
fi | |
done | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2023 by CODE TOT. | |
# This script is licensed under the MIT license. | |
# Version: 1.2.0 | |
# CHANGELOG: https://github.com/codetot-tech/wp-devops/issues/1 | |
echo "✨ A maintenance script was supported by CODE TOT. Post your issue on https://github.com/codetot-tech/wp-devops/issues if you have any bugs while running it." | |
echo "TASK: Check if WP-CLI available" | |
if [[ $(wp --info) ]]; then | |
echo "✅ PASSED: WP-CLI version: $(wp --info | grep version | awk '{print $2}')" | |
else | |
echo "🚨 ERROR: WP-CLI is not available." | |
exit 1 | |
fi | |
echo "TASK: Check if Git Environment available" | |
if [[ -d .git ]]; then | |
echo "✅ PASSED! This repository is under Git-control." | |
else | |
echo "🚨 ERROR: This directory is not a Git repository." | |
exit 1 | |
fi | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
if [[ "$current_branch" == "master" || "$current_branch" == "production" ]]; then | |
echo "✅ PASSED: This maintenance script is running with branch $current_branch only." | |
else | |
echo "🚨 ERROR: Can you double-check a current branch name? It was not production/master branch." | |
exit 1 | |
fi | |
echo "⚡️ TASK: Start backup DB 🚚 " | |
wp db export | |
echo "⚡️ TASK: Update plugins using WP-CLI" | |
wp plugin update --all | |
if [[ $(git status --porcelain) ]]; then | |
git add wp-content/plugins/ | |
git commit -m "📦️ Update live plugins" | |
git push | |
else | |
echo "INFO: No updates or no commit." | |
fi | |
echo "⚡️ TASK: Update themes using WP-CLI" | |
wp theme update --all | |
if [[ $(git status --porcelain) ]]; then | |
git add wp-content/themes/ | |
git commit -m "📦️ Update live themes" | |
git push | |
else | |
echo "INFO: No updates or no commit." | |
fi | |
echo "⚡️ TASK: Update translations using WP-CLI" | |
wp language plugin update --all | |
wp language theme update --all | |
if [[ $(git status --porcelain) ]]; then | |
git add wp-content/languages/ | |
git commit -m "📦️ Update live translations" | |
git push | |
else | |
echo "INFO: No updates or no commit." | |
fi | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Copy maintenance.sh from other folder and CHMOD" | |
"Remove old file" | |
git rm -rf scripts/ | |
git commit -m "Remove old scripts" | |
echo "Create folder scripts if no exists" | |
mkdir scripts | |
echo "Copy file" | |
cp -r ../$1/scripts/maintenance.sh scripts/ | |
echo "CHMOD +x maintenance.sh" | |
chmod +x scripts/*.sh | |
echo "Commit file" | |
git add scripts/ | |
git commit -m "Update bash script maintenance 1.2.0" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment