Update containers_version.sh

This commit is contained in:
qiaofeng1227 2022-07-18 11:42:49 +08:00 committed by GitHub
parent 2e2f56a236
commit 1858821638
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,7 @@ fi
appnames=$(ls StackHub/apps/roles |grep -v Template |grep -v README.md |grep -v role)
# 匹配成功的APP集合字符串
initdata=""
targetlist=""
# get all of the running container's information( containername and imagename)
for appinfo in $(docker ps --format '{{.Names}}%{{.Image}}'); do
@ -21,36 +21,33 @@ for appinfo in $(docker ps --format '{{.Names}}%{{.Image}}'); do
for appname in $appnames; do
if [[ $containername == $appname ]];then
# app的版本已经输出
if [[ $initdata =~ $appname ]];then
if [[ $targetlist =~ $appname ]];then
continue
fi
echo "$containername容器匹配成功app:$appname"
initdata="$initdata $appname"
targetlist="$targetlist $appname"
wget -O /tmp/$appname_get_version.sh https://raw.githubusercontent.com/Websoft9/docker-$appname/main/src/get_version.sh
bash /tmp/$appname_get_version.sh $containername
break
elif [[ $imagename =~ $appname ]];then
# app的版本已经输出
if [[ $initdata =~ $appname ]];then
if [[ $targetlist =~ $appname ]];then
continue
fi
tmpvar="-"
if [[ $containername =~ $tmpvar ]];then
echo "$imagename=镜像匹配成功app:$appname"
initdata="$initdata $appname"
targetlist="$targetlist $appname"
wget -O /tmp/$appname_get_version.sh https://raw.githubusercontent.com/Websoft9/docker-$appname/main/src/get_version.sh
bash /tmp/$appname_get_version.sh $containername
break
fi
else
# 容器和镜像均未匹配成功,通过服务名匹配
realapp=echo $containername|awk -F"-" '{print $1}'
services=docker compose -p $realapp ps --services
for service in $services; do
if [[ $service == $appname ]];then
echo "$containername容器匹配成功app:$appname"
initdata="$initdata $appname"
targetlist="$targetlist $appname"
wget -O /tmp/$appname_get_version.sh https://raw.githubusercontent.com/Websoft9/docker-$appname/main/src/get_version.sh
bash /tmp/$appname_get_version.sh $containername
break