#!/bin/bash limit='' while test $# -gt 0; do case "$1" in (-h|--help) cat <&2 exit 1 fi shift done for f in $*; do name=${f%.yaml} file=${name}.yaml name=${f##*/} echo "upgrading ${name}" IFS=" " for param in $(sed -n '/^ *\([^:]\+\): *$/{s//'"${name}"'_\1/;h};/^ *image: */{s///;G;s/\n/ /p}' $file); do IFS=" " if [ -z "$limit" ] || [[ "${param}" =~ " ${name}_${limit}" ]]; then echo "....update $param: docker service update -d --image $param" docker service update -d --image $param fi done done