Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matteomorreale/clean-wp-files-for-litespeed
This Bash script automatically scans all WordPress installations in a specified directory, uses WP-CLI to verify the integrity of WordPress core files, and removes any unauthorized files. It temporarily adjusts ownership and permissions for the operations and restores the original settings afterward, ensuring the security of the installations.
https://github.com/matteomorreale/clean-wp-files-for-litespeed
wordpress wordpress-development wordpress-site
Last synced: about 1 month ago
JSON representation
This Bash script automatically scans all WordPress installations in a specified directory, uses WP-CLI to verify the integrity of WordPress core files, and removes any unauthorized files. It temporarily adjusts ownership and permissions for the operations and restores the original settings afterward, ensuring the security of the installations.
- Host: GitHub
- URL: https://github.com/matteomorreale/clean-wp-files-for-litespeed
- Owner: matteomorreale
- Created: 2024-11-24T09:57:19.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-11-24T10:06:11.000Z (about 1 month ago)
- Last Synced: 2024-11-24T10:29:43.989Z (about 1 month ago)
- Topics: wordpress, wordpress-development, wordpress-site
- Language: Shell
- Homepage: https://matteomorreale.it
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WordPress Cleanup Script
This Bash script scans all WordPress installations under a specified directory, identifies unauthorized files using **WP-CLI**'s `core verify-checksums`, and removes them. It also temporarily changes ownership for the script to run, restores the original ownership and permissions, and ensures file and directory security.
## Features
- Automatically identifies all WordPress installations by locating `wp-config.php` files.
- Uses WP-CLI to verify the integrity of WordPress core files.
- Removes suspicious files flagged by WP-CLI.
- Temporarily changes ownership for operations and restores the original owner.
- Ensures secure permissions for files and directories after execution.## Requirements
### Install WP-CLI
Ensure that WP-CLI is installed on your server before running this script. To install WP-CLI:
```bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
```Verify the installation with:
```bash
wp --info
```### Edit the Script
Before running the script, open it with a text editor to set your username:
```bash
nano clean_wp_files.sh
```Locate the line:
```bash
TEMP_OWNER="yourname:nogroup"
```Replace `yourname` with your username (e.g., `matteo`). Save and exit the editor.
## Usage
### Clone the Repository
Clone the repository to your server:
```bash
git clone https://github.com/your-repo/wordpress-cleanup.git
```Navigate to the directory:
```bash
cd wordpress-cleanup
```### Make the Script Executable
Ensure the script is executable:
```bash
chmod +x clean_wp_files.sh
```### Run the Script
Run the script with `sudo` to ensure it can manage file permissions:
```bash
sudo ./clean_wp_files.sh
```## Scheduled Execution (Optional)
To automate this script, you can schedule it to run nightly using a cron job.
1. Open the crontab editor:
```bash
sudo crontab -e
```2. Add the following line to schedule the script to run every night at 4 AM:
```bash
0 4 * * * /path/to/clean_wp_files.sh >> /var/log/clean_wp_files.log 2>&1
```3. Save and exit. The script will now run automatically at 4 AM every day.
## Security Note
- Ensure backups of your WordPress installations before running the script.
- Double-check the temporary ownership configuration in the script.## Troubleshooting
If you encounter any issues:
1. Verify that WP-CLI is correctly installed and accessible.
2. Check that you have permissions to run the script on the specified directory.
3. Ensure the username and group specified in the script match your system configuration.## Contributing
Feel free to contribute by submitting pull requests or reporting issues in the [Issues section](https://github.com/your-repo/wordpress-cleanup/issues).