#!/usr/bin/env bash # usage usage() { USAGE=$(cat < /dev/null || { echo "Requiring 'docker-compose' but it's not installed"; exit 1; } } # check requirements FALLBACK_CONFIG_FILE="${HOME}/.docker_compose_update.conf"; FALLBACK_CONFIG_GLOBAL_FILE="/etc/docker_compose_update.conf"; source_config "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}"; apply_defaults; check_required; # DO NOT TOUCH BELOW currentDir=$(pwd) echo "Current directory is '${currentDir}'" cd "${DOCKER_COMPOSE_UPDATE_BASEDIR}"; for dir in *; do if [ -d "${dir}" ]; then basename=$(basename "${dir}") ignore=false; for ignorePattern in "${DOCKER_COMPOSE_UPDATE_IGNORES[@]}"; do if [[ "${basename}" == *"${ignorePattern}"* ]]; then ignore=true; fi done if [[ "${ignore}" == "true" ]]; then echo "Ignoring '${basename}'"; continue; fi echo "Handling '${basename}'"; updateCommand="" for cmd in "${!DOCKER_COMPOSE_UPDATE_COMMANDS[@]}"; do if [[ "${cmd}" == "${basename}" ]]; then updateCommand="${DOCKER_COMPOSE_UPDATE_COMMANDS[$cmd]}"; fi done if [[ -n "${updateCommand}" ]]; then echo "Using custom command '${updateCommand}'"; else updateCommand="${DOCKER_COMPOSE_UPDATE_COMMAND}"; echo "Using command '${DOCKER_COMPOSE_UPDATE_COMMAND}'"; fi cd "${basename}"; if [[ "${DOCKER_COMPOSE_UPDATE_FAIL_ON_UPDATE_ERROR}" == "false" ]]; then set +e; fi # shellcheck disable=SC2034 res=$(eval "${updateCommand}") if [[ "${DOCKER_COMPOSE_UPDATE_FAIL_ON_UPDATE_ERROR}" == "false" ]]; then set -e; fi cd "../"; echo ""; fi done