2022-07-15 14:55:40 +08:00
|
|
|
#!/bin/bash
|
|
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
2022-07-15 15:57:02 +08:00
|
|
|
|
|
|
|
# get applist
|
2022-07-15 16:02:54 +08:00
|
|
|
if [ -d StackHub ] ; then
|
|
|
|
echo "StackHub is exists"
|
|
|
|
else
|
|
|
|
git clone --depth=1 https://github.com/Websoft9/StackHub.git
|
|
|
|
fi
|
2022-07-15 15:57:02 +08:00
|
|
|
appnames=$(ls StackHub/apps/roles |grep -v Template |grep -v README.md |grep -v role)
|
2022-07-15 16:40:03 +08:00
|
|
|
|
2022-07-16 16:17:22 +08:00
|
|
|
# 匹配成功的APP集合字符串
|
|
|
|
initdata=""
|
|
|
|
|
2022-07-16 08:58:18 +08:00
|
|
|
# get all of the running container's information( containername and imagename)
|
|
|
|
for appinfo in $(docker ps --format '{{.Names}}%{{.Image}}'); do
|
|
|
|
|
|
|
|
containername=$(echo $appinfo |awk -F"%" '{print $1}')
|
|
|
|
imagename=$(echo $appinfo |awk -F"%" '{print $2}')
|
|
|
|
|
2022-07-16 16:17:22 +08:00
|
|
|
for appname in $appnames; do
|
|
|
|
# app的版本已经输出
|
|
|
|
if [[ $initdata =~ $appname ]];then
|
2022-07-16 16:35:31 +08:00
|
|
|
continue
|
2022-07-16 16:17:22 +08:00
|
|
|
fi
|
2022-07-16 08:58:18 +08:00
|
|
|
if [[ $containername == $appname ]];then
|
2022-07-16 16:17:22 +08:00
|
|
|
echo "$containername容器匹配成功app:$appname"
|
2022-07-18 08:15:42 +08:00
|
|
|
appnames=(${appnames[*]/$appname})
|
|
|
|
initdata="$initdata $appname"
|
2022-07-16 08:58:18 +08:00
|
|
|
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
|
|
|
|
tmpvar="-"
|
|
|
|
if [[ $containername =~ $tmpvar ]];then
|
2022-07-16 16:17:22 +08:00
|
|
|
echo "$imagename=镜像匹配成功app:$appname"
|
|
|
|
appnames=(${appnames[*]/$appname})
|
2022-07-16 16:44:14 +08:00
|
|
|
initdata="$initdata $appname"
|
2022-07-18 08:14:47 +08:00
|
|
|
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
|
2022-07-16 08:58:18 +08:00
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "need other mothod "
|
|
|
|
fi
|
2022-07-15 16:40:03 +08:00
|
|
|
else
|
2022-07-16 16:17:22 +08:00
|
|
|
echo "容器镜像均未匹配成功app:$appname"
|
2022-07-15 16:40:03 +08:00
|
|
|
fi
|
2022-07-16 08:58:18 +08:00
|
|
|
done
|
2022-07-15 15:57:02 +08:00
|
|
|
done
|