Last active
February 13, 2023 21:37
-
-
Save RBotfield/80958ea06fbe52c03b138bf091dd793d to your computer and use it in GitHub Desktop.
WP verify-checksums bulk runner & saver
This file contains hidden or 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 | |
| # MUST INCLUDE colors.sh | |
| # Script to cycle through the current directory to each direct child directory and generate a report of the WordPress file integrity using wp-cli (/usr/local/bin/wp) with the `wp core verify-checksums` and `wp plugin verify-checksums --all` commands. Reports will be saved in the current directory as a .txt file with the name of the directory the report was generated from and a unix timestamp appended. | |
| # Exit immediately if a command returns a non-zero status | |
| set -e | |
| # Get the current directory | |
| parent_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| scanreport_dir="scan_reports" | |
| # Source the colors.sh file | |
| source "$parent_dir/colors.sh" | |
| # Print the parent directory being scanned | |
| echo -e "${YELLOW}Running in ${UNDERLINE}${parent_dir}${RESET}" | |
| # Check if scan_reports directory exists, if not, create it | |
| if [ ! -d "$parent_dir/$scanreport_dir" ]; then | |
| echo -e "${YELLOW}Creating ${UNDERLINE}${parent_dir}/${scanreport_dir}${RESET}" | |
| mkdir -p "${parent_dir}/${scanreport_dir}" | |
| fi | |
| # Loop through each direct child directory | |
| for child_dir in */ | |
| do | |
| # Remove the trailing slash | |
| child_dir="${child_dir%/}" | |
| # Check if the current item is a directory | |
| if [ -d "${child_dir}" ]; then | |
| cd "${child_dir}" | |
| # Check if the child directory is a WordPress root directory | |
| if [ -f wp-config.php ]; then | |
| # Get the current Unix timestamp | |
| timestamp="$(date +%s)" | |
| echo -e "${YELLOW}Checking WordPress integrity for ${UNDERLINE}${child_dir}${RESET} (Timestamp ${timestamp})" | |
| # Generate the report | |
| # Use stdbuf to prevent buffering of the output and allow colors to be displayed properly | |
| stdbuf -oL wp --allow-root --skip-packages --color core verify-checksums 2>&1 | tee -a "${parent_dir}/${scanreport_dir}/wp-checksums-${child_dir}-${timestamp}.txt" | |
| stdbuf -oL wp --allow-root --skip-packages --color plugin verify-checksums --all 2>&1 | tee -a "${parent_dir}/${scanreport_dir}/wp-checksums-${child_dir}-${timestamp}.txt" | |
| fi | |
| # Return to the parent directory | |
| cd "$parent_dir" | |
| fi | |
| done | |
| # Print the completion message | |
| echo -e "${GREEN}${BOLD}Complete!${RESET} Check ${UNDERLINE}${parent_dir}/${scanreport_dir}${RESET} for results" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment