server-scripts/docker-updater.sh

63 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/bash
2024-12-28 21:35:51 -03:00
NC='\033[0m'
LIGHT_BLUE='\033[1;34m'
LIGHT_GREEN='\033[1;32m'
LIGHT_GREY='\033[0;37m'
### AUTO-UPDATER ###
2024-12-28 21:30:00 -03:00
export FILE_NAME="docker-updater.sh"
2024-12-28 21:18:35 -03:00
SERVER_AU="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/auto-updater.sh"
2024-12-28 21:18:35 -03:00
# Run auto-updater script
2024-12-28 21:30:00 -03:00
UPDATER=$(curl -sSL $SERVER_AU | bash)
if [ $? -eq 2 ]; then
exit 0
fi
####################
# Navigate to docker folder
DOCKER_FOLDER=/root/docker
if [ -d "$DOCKER_FOLDER" ]; then
cd $DOCKER_FOLDER
else
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_GREY}[i] Docker folder not found.${NC}"
exit 1
fi
# Navigate on each folder and run docker-compose stop, pull and up -d
for folder in */; do
cd $folder
2024-12-28 21:13:05 -03:00
2024-12-28 21:13:51 -03:00
DOCKER_RUNNING=$(docker-compose ps -q)
2024-12-28 21:13:05 -03:00
if [ -n "$DOCKER_RUNNING" ]; then
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_BLUE}[$folder] Stopping Docker containers"
2024-12-28 21:18:35 -03:00
docker-compose down > /dev/null
2024-12-28 21:13:05 -03:00
else
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_BLUE}[$folder] No Docker containers running"
2024-12-28 21:13:05 -03:00
fi
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_BLUE}[$folder] Updating images"
2024-12-28 21:18:35 -03:00
docker-compose pull > /dev/null
2024-12-28 21:13:05 -03:00
if [ -n "$DOCKER_RUNNING" ]; then
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_BLUE}[$folder] Starting Docker containers"
2024-12-28 21:18:35 -03:00
docker-compose up -d > /dev/null
2024-12-28 21:13:05 -03:00
fi
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_GREEN}[$folder] Updated!"
cd ..
done
# Run Docker image prune
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_BLUE}Running Docker image prune..."
docker image prune -af
2024-12-28 21:35:51 -03:00
echo -e "${LIGHT_GREEN} All done!"