2024-12-28 11:00:37 -03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-12-28 21:35:51 -03:00
|
|
|
NC='\033[0m'
|
2024-12-28 21:58:40 -03:00
|
|
|
LIGHT_GREEN='\033[1;32m'
|
2024-12-28 21:35:51 -03:00
|
|
|
LIGHT_BLUE='\033[1;34m'
|
|
|
|
LIGHT_GREEN='\033[1;32m'
|
|
|
|
LIGHT_GREY='\033[0;37m'
|
|
|
|
|
2024-12-28 11:00:37 -03:00
|
|
|
### AUTO-UPDATER ###
|
2024-12-28 21:58:40 -03:00
|
|
|
FILE_NAME="docker-updater.sh"
|
|
|
|
SERVER_FILE="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/$FILE_NAME"
|
|
|
|
SERVER_OK=1
|
|
|
|
|
|
|
|
# Check if the server file exists
|
|
|
|
curl -s --head $SERVER_FILE | head -n 1 | grep -E "HTTP/[12] [23].." > /dev/null
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo -e "${RED}[x] Error: $SERVER_FILE not found.${NC}" >&2
|
|
|
|
SERVER_OK=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $SERVER_OK -eq 1 ]; then
|
|
|
|
echo -e "${LIGHT_BLUE}[i] Running auto-update"
|
|
|
|
|
|
|
|
# Compare the local and server files sha256sum to check if an update is needed
|
|
|
|
LOCAL_SHA256=$(sha256sum $FILE_NAME | awk '{print $1}')
|
|
|
|
SERVER_SHA256=$(curl -s $SERVER_FILE | sha256sum | awk '{print $1}')
|
|
|
|
|
|
|
|
if [ "$LOCAL_SHA256" != "$SERVER_SHA256" ]; then
|
|
|
|
echo -e "${LIGHT_GREY}[i] Updating $FILE_NAME${NC}"
|
2024-12-28 11:00:37 -03:00
|
|
|
|
2024-12-28 21:58:40 -03:00
|
|
|
curl -s -o $FILE_NAME $SERVER_FILE
|
|
|
|
chmod +x $FILE_NAME
|
|
|
|
echo -e "${LIGHT_GREEN}[i] $FILE_NAME updated.${NC}"
|
2024-12-28 21:30:00 -03:00
|
|
|
|
2024-12-28 21:58:40 -03:00
|
|
|
echo -e "${LIGHT_BLUE}[i] Running updated $FILE_NAME...${NC}"
|
|
|
|
./$FILE_NAME
|
2024-12-28 21:59:33 -03:00
|
|
|
exit 0
|
2024-12-28 21:58:40 -03:00
|
|
|
else
|
|
|
|
echo -e "${LIGHT_GREEN}[i] $FILE_NAME is already up to date.${NC}"
|
|
|
|
fi
|
2024-12-28 21:30:00 -03:00
|
|
|
fi
|
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
|
2024-12-28 21:35:51 -03:00
|
|
|
echo -e "${LIGHT_GREY}[i] Docker folder not found.${NC}"
|
2024-12-28 11:00:37 -03:00
|
|
|
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 11:00:37 -03:00
|
|
|
|
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!"
|
2024-12-28 11:00:37 -03:00
|
|
|
|
|
|
|
cd ..
|
|
|
|
done
|
|
|
|
|
|
|
|
# Run Docker image prune
|
|
|
|
|
2024-12-28 21:35:51 -03:00
|
|
|
echo -e "${LIGHT_BLUE}Running Docker image prune..."
|
2024-12-28 11:00:37 -03:00
|
|
|
docker image prune -af
|
|
|
|
|
2024-12-28 21:35:51 -03:00
|
|
|
echo -e "${LIGHT_GREEN} All done!"
|