55# ################
66
77# shellcheck disable=SC2034
8- VERSION=" 1.8.5 "
8+ VERSION=" 1.9 "
99
1010# Variables
1111CONFIG_FILE=" /etc/ultimate-updater/update.conf"
@@ -14,6 +14,7 @@ IOBROKER=$(awk -F'"' '/^IOBROKER=/ {print $2}' $CONFIG_FILE)
1414PTERODACTYL=$( awk -F' "' ' /^PTERODACTYL=/ {print $2}' $CONFIG_FILE )
1515OCTOPRINT=$( awk -F' "' ' /^OCTOPRINT=/ {print $2}' $CONFIG_FILE )
1616DOCKER_COMPOSE=$( awk -F' "' ' /^DOCKER_COMPOSE=/ {print $2}' $CONFIG_FILE )
17+ COMPOSE_PATH=$( awk -F' "' ' /^COMPOSE_PATH=/ {print $2}' $CONFIG_FILE )
1718
1819# PiHole
1920if [[ -f " /usr/local/bin/pihole" && $PIHOLE == true ]]; then
8384if [[ -f /usr/local/bin/docker-compose ]]; then DOCKER_COMPOSE_V1=true; fi
8485if docker compose version & > /dev/null; then DOCKER_COMPOSE_V2=true; fi
8586
86- # Docker-Compose v1
87- if [[ $DOCKER_COMPOSE_V1 == true && $DOCKER_COMPOSE == true ]]; then
88- echo -e " \n*** Updating Docker-Compose v1 (oldstable) ***\n"
89- if COMPOSE=$( find / -name " docker-compose.yaml" > /dev/null 2>&1 | rev | cut -c 20- | rev | tail -n 1) ; then
90- :
91- elif COMPOSE=$( find / -name " docker-compose.yml" > /dev/null 2>&1 | rev | cut -c 20- | rev | tail -n 1) ; then
92- :
93- fi
94- cd " $COMPOSE " || exit
95- # Get the containers from the first argument, else get all containers
96- CONTAINER_LIST=" ${1:- $(docker ps -q)} "
97- for CONTAINER in ${CONTAINER_LIST} ; do
98- # Get requirements
99- CONTAINER_IMAGE=$( docker inspect --format " {{.Config.Image}}" --type container " ${CONTAINER} " )
100- RUNNING_IMAGE=$( docker inspect --format " {{.Image}}" --type container " ${CONTAINER} " )
101- NAME=$( docker inspect --format " {{.Name}}" --type container " ${CONTAINER} " | cut -c 2-)
102- # Pull in the latest version of the container and get the hash
103- docker pull " ${CONTAINER_IMAGE} " 2> /dev/null
104- LATEST_IMAGE=$( docker inspect --format " {{.Id}}" --type image " ${CONTAINER_IMAGE} " )
105- # Restart the container if the image is different by name
106- if [[ ${RUNNING_IMAGE} != " ${LATEST_IMAGE} " ]]; then
107- echo " Updating ${CONTAINER} image ${CONTAINER_IMAGE} "
108- /usr/local/bin/docker-compose up -d --no-deps --build " $NAME "
109- fi
110- cd " $COMPOSE " || exit
111- # Docker-Compose v1
112- if [[ $DOCKER_COMPOSE_V1 == true ]]; then
113- echo -e " \n*** Updating Docker-Compose v1 (oldstable) ***\n"
114- /usr/local/bin/docker-compose pull
115- /usr/local/bin/docker-compose up --force-recreate --build -d
116- /usr/local/bin/docker-compose restart
117- fi
118- # Docker-Compose v2
119- if [[ $DOCKER_COMPOSE_V2 == true ]]; then
120- echo -e " \n*** Updating Docker Compose ***"
121- docker compose pull
122- docker compose up -d
123- fi
124- # Cleaning
87+ # Docker-Compose run
88+ if [[ $DOCKER_COMPOSE == true && $DOCKER_COMPOSE_V1 == true || $DOCKER_COMPOSE_V2 == true ]]; then
89+ # Cleaning
90+ DOCKER_EXIT () {
12591 echo -e " \n*** Cleaning ***"
12692 docker container prune -f
12793 docker system prune -a -f
12894 docker image prune -f
12995 docker system prune --volumes -f
96+ }
97+ COMPOSEFILES=(" docker-compose.yaml" " docker-compose.yml" " compose.yaml" " compose.yml" )
98+ DIRLIST=()
99+ for COMPOSEFILE in " ${COMPOSEFILES[@]} " ; do
100+ while IFS= read -r line; do
101+ DIRLIST+=(" $line " )
102+ done < <( find " $COMPOSE_PATH " -name " $COMPOSEFILE " -exec dirname {} \; 2> >( grep -v ' Permission denied' ) )
130103 done
131- fi
104+ # Docker-Compose v1
105+ if [[ $DOCKER_COMPOSE_V1 == true && ${# DIRLIST[@]} -gt 0 ]]; then
106+ echo -e " \n*** Updating Docker-Compose v1 (oldstable) ***\n"
107+ for dir in " ${DIRLIST[@]} " ; do
108+ echo " Updating $dir ..."
109+ pushd " $dir " > /dev/null || return
110+ /usr/local/bin/docker-compose pull
111+ /usr/local/bin/docker-compose up --force-recreate --build -d
112+ /usr/local/bin/docker-compose restart
113+ popd > /dev/null || return
114+ done
115+ echo " All projects have been updated."
116+ DOCKER_EXIT
117+ fi
118+ # Docker-Compose v2
119+ if [[ $DOCKER_COMPOSE_V2 == true && ${# DIRLIST[@]} -gt 0 ]]; then
120+ echo -e " \n*** Updating Docker Compose ***"
121+ for dir in " ${DIRLIST[@]} " ; do
122+ echo " Updating $dir ..."
123+ pushd " $dir " > /dev/null || return
124+ docker compose pull && docker compose up -d
125+ popd > /dev/null || return
126+ done
127+ echo " All projects have been updated."
128+ DOCKER_EXIT
129+ fi
130+ fi
0 commit comments