83 lines
2.9 KiB
Bash
83 lines
2.9 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# ----------------------------------------------------
|
||
|
|
# Docker Compose Uninstall/Cleanup Script for Mealie
|
||
|
|
# ----------------------------------------------------
|
||
|
|
# This script will stop and remove the Mealie services
|
||
|
|
# defined in the current directory's docker-compose.yml.
|
||
|
|
# It provides an option to permanently remove all associated data (volumes).
|
||
|
|
|
||
|
|
# Function to display messages
|
||
|
|
log() {
|
||
|
|
echo "=> $1"
|
||
|
|
}
|
||
|
|
|
||
|
|
# --- Step 1: Confirmation ---
|
||
|
|
log "WARNING: This script will stop and remove all running Docker containers and networks defined in the current docker-compose.yml file."
|
||
|
|
log " This typically includes 'mealie' and 'mealie-postgres'."
|
||
|
|
echo ""
|
||
|
|
read -r -p "Are you sure you want to proceed? (y/N): " response
|
||
|
|
case "$response" in
|
||
|
|
[yY][eE][sS]|[yY])
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
log "Operation cancelled by user."
|
||
|
|
exit 0
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
|
||
|
|
# --- Step 2: Stop and Remove Containers/Networks ---
|
||
|
|
log "Stopping and removing containers and associated default networks..."
|
||
|
|
# `docker compose down` stops the containers and removes the network.
|
||
|
|
docker compose down
|
||
|
|
|
||
|
|
if [ $? -ne 0 ]; then
|
||
|
|
log "ERROR: 'docker compose down' failed. Check your Docker daemon status."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
log "Containers and network successfully removed."
|
||
|
|
|
||
|
|
# --- Step 3: Remove Volumes (Data) ---
|
||
|
|
echo ""
|
||
|
|
log "DATA REMOVAL STEP:"
|
||
|
|
log "If you wish to remove ALL persistent data (e.g., PostgreSQL data, Mealie uploads/settings),"
|
||
|
|
log "run the 'docker compose down' command again with the --volumes flag."
|
||
|
|
log "!!! WARNING: THIS IS PERMANENT DATA LOSS !!!"
|
||
|
|
echo ""
|
||
|
|
read -r -p "Do you want to PERMANENTLY remove all associated volumes/data (y/N)? " remove_volumes_response
|
||
|
|
case "$remove_volumes_response" in
|
||
|
|
[yY][eE][sS]|[yY])
|
||
|
|
log "Removing volumes now..."
|
||
|
|
# The -v or --volumes flag removes named volumes declared in the 'volumes' section of the Compose file.
|
||
|
|
# This step is performed after the initial `down` to ensure the volumes aren't in use.
|
||
|
|
docker compose down --volumes
|
||
|
|
if [ $? -eq 0 ]; then
|
||
|
|
log "Volumes successfully removed. All Mealie data is gone."
|
||
|
|
else
|
||
|
|
log "ERROR: Volume removal failed."
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
log "Volumes retained. You can restart the application later with existing data."
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
|
||
|
|
# --- Step 4: Final Cleanup (Optional Images) ---
|
||
|
|
echo ""
|
||
|
|
log "OPTIONAL: Remove the downloaded Mealie and PostgreSQL images."
|
||
|
|
read -r -p "Do you want to remove the downloaded Docker images (y/N)? " remove_images_response
|
||
|
|
case "$remove_images_response" in
|
||
|
|
[yY][eE][sS]|[yY])
|
||
|
|
log "Removing images..."
|
||
|
|
# Attempts to remove the images by their generated names, suppressing errors if they don't exist
|
||
|
|
docker rmi mealie_mealie mealie_postgres 2>/dev/null
|
||
|
|
log "Mealie and PostgreSQL images attempted for removal."
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
log "Images retained."
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
|
||
|
|
rm -rf ./mealie-data/
|
||
|
|
rm -rf ./mealie-pgdata/
|
||
|
|
|
||
|
|
log "UNINSTALL SCRIPT COMPLETE."
|