server-scripts/docker-updater.sh
Jose Henrique be04437849
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 3s
testing auto updater
2024-12-28 21:19:24 -03:00

55 lines
1.2 KiB
Bash

#!/bin/bash
### AUTO-UPDATER ###
FILE_NAME="docker-updater.sh"
SERVER_FILE="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/$FILE_NAME"
SERVER_AU="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/auto-updater.sh"
# Run auto-updater script
curl -sSL $SERVER_AU | export FILE_NAME=$FILE_NAME bash
####################
# 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
DOCKER_RUNNING=$(docker-compose ps -q)
if [ -n "$DOCKER_RUNNING" ]; then
echo "[$folder] Stopping Docker containers"
docker-compose down > /dev/null
else
echo "[$folder] No Docker containers running"
fi
echo "[$folder] Updating images"
docker-compose pull > /dev/null
if [ -n "$DOCKER_RUNNING" ]; then
echo "[$folder] Starting Docker containers"
docker-compose up -d > /dev/null
fi
echo "[$folder] Updated!"
cd ..
done
# Run Docker image prune
echo "Running Docker image prune..."
docker image prune -af
echo "Done!"