Created
January 4, 2025 20:32
-
-
Save lucabased/500db2fc59e1458909b73b9ebc4ef464 to your computer and use it in GitHub Desktop.
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 | |
| # Exit immediately if a command exits with a non-zero status. | |
| set -e | |
| # Variables | |
| DOCKER_COMPOSE_DIR="/opt/devbox" | |
| # Function to stop and remove Docker containers | |
| remove_docker_containers() { | |
| if [ -d "$DOCKER_COMPOSE_DIR" ]; then | |
| echo "Stopping and removing Docker containers..." | |
| cd "$DOCKER_COMPOSE_DIR" | |
| docker compose down -v | |
| echo "Docker containers stopped and removed." | |
| else | |
| echo "Docker Compose directory does not exist. Skipping container removal." | |
| fi | |
| } | |
| # Function to remove Docker Compose files and data | |
| remove_docker_files() { | |
| if [ -d "$DOCKER_COMPOSE_DIR" ]; then | |
| echo "Removing Docker Compose directory and all data..." | |
| rm -rf "$DOCKER_COMPOSE_DIR" | |
| echo "Docker Compose files and data removed." | |
| else | |
| echo "Docker Compose directory does not exist. Skipping file removal." | |
| fi | |
| } | |
| # Function to uninstall Docker and Docker Compose | |
| uninstall_docker() { | |
| echo "Uninstalling Docker and Docker Compose..." | |
| apt-get purge -y docker-ce docker-ce-cli containerd.io docker-compose-plugin | |
| apt-get autoremove -y | |
| rm -rf /var/lib/docker | |
| rm -rf /var/lib/containerd | |
| echo "Docker and Docker Compose uninstalled." | |
| } | |
| # Function to remove cron job | |
| remove_cron_job() { | |
| echo "Removing cron job for certificate renewal..." | |
| crontab -l | grep -v "certbot/certbot renew" | crontab - | |
| echo "Cron job removed." | |
| } | |
| # Main Script Execution | |
| main() { | |
| # Ensure the script is run as root | |
| if [[ "$EUID" -ne 0 ]]; then | |
| echo "Please run as root or use sudo." | |
| exit 1 | |
| fi | |
| # Stop and remove Docker containers | |
| remove_docker_containers | |
| # Remove Docker Compose files and data | |
| remove_docker_files | |
| # Optionally, uninstall Docker and Docker Compose | |
| read -p "Do you want to uninstall Docker and Docker Compose? (y/N): " confirm | |
| if [[ "$confirm" =~ ^[Yy]$ ]]; then | |
| uninstall_docker | |
| else | |
| echo "Docker and Docker Compose are still installed." | |
| fi | |
| # Remove cron job | |
| remove_cron_job | |
| echo "Revert process completed successfully!" | |
| } | |
| # Run the main function | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment