2024-12-28 11:00:37 -03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
### AUTO-UPDATER ###
|
|
|
|
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 11:00:37 -03:00
|
|
|
|
2024-12-28 21:18:35 -03:00
|
|
|
# Run auto-updater script
|
2024-12-28 21:21:54 -03:00
|
|
|
curl -sSL $SERVER_AU | bash
|
2024-12-28 11:00:37 -03:00
|
|
|
|
|
|
|
####################
|
|
|
|
|
|
|
|
# Navigate to docker folder
|
|
|
|
DOCKER_FOLDER=/root/docker
|
|
|
|
|
|
|
|
if [ -d "$DOCKER_FOLDER" ]; then
|
|
|
|
cd $DOCKER_FOLDER
|
|
|
|
else
|
|
|
|
echo "Error: $DOCKER_FOLDER not found." >&2
|
|
|
|
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
|
|
|
|
echo "[$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
|
|
|
|
echo "[$folder] No Docker containers running"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "[$folder] Updating images"
|
2024-12-28 21:18:35 -03:00
|
|
|
docker-compose pull > /dev/null
|
2024-12-28 11:00:37 -03:00
|
|
|
|
2024-12-28 21:13:05 -03:00
|
|
|
if [ -n "$DOCKER_RUNNING" ]; then
|
|
|
|
echo "[$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
|
|
|
|
|
|
|
|
echo "[$folder] Updated!"
|
2024-12-28 11:00:37 -03:00
|
|
|
|
|
|
|
cd ..
|
|
|
|
done
|
|
|
|
|
|
|
|
# Run Docker image prune
|
|
|
|
|
|
|
|
echo "Running Docker image prune..."
|
|
|
|
docker image prune -af
|
|
|
|
|
2024-12-28 21:13:05 -03:00
|
|
|
echo "Done!"
|