2022-07-15 06:55:40 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
2022-07-15 07:57:02 +00:00
|
|
|
|
|
|
|
|
|
# get applist
|
2022-07-15 08:02:54 +00:00
|
|
|
|
if [ -d StackHub ] ; then
|
|
|
|
|
echo "StackHub is exists"
|
|
|
|
|
else
|
2023-04-18 01:45:23 +00:00
|
|
|
|
git clone --depth=1 https://ghproxy.com/https://github.com/Websoft9/StackHub.git
|
2022-07-15 08:02:54 +00:00
|
|
|
|
fi
|
2022-07-15 07:57:02 +00:00
|
|
|
|
appnames=$(ls StackHub/apps/roles |grep -v Template |grep -v README.md |grep -v role)
|
2022-07-15 08:40:03 +00:00
|
|
|
|
|
2022-07-18 03:42:49 +00:00
|
|
|
|
targetlist=""
|
2022-07-16 08:17:22 +00:00
|
|
|
|
|
2022-07-16 00:58:18 +00: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 08:17:22 +00:00
|
|
|
|
for appname in $appnames; do
|
2022-07-18 00:44:39 +00:00
|
|
|
|
|
2022-07-16 00:58:18 +00:00
|
|
|
|
if [[ $containername == $appname ]];then
|
2022-07-18 03:42:49 +00:00
|
|
|
|
if [[ $targetlist =~ $appname ]];then
|
2022-07-18 00:44:39 +00:00
|
|
|
|
continue
|
|
|
|
|
fi
|
2022-07-26 06:47:27 +00:00
|
|
|
|
echo "$containername容器名匹配成功app:$appname"
|
2022-07-18 03:42:49 +00:00
|
|
|
|
targetlist="$targetlist $appname"
|
2023-04-18 01:58:49 +00:00
|
|
|
|
cp /data/apps/library/apps/"$appname"/src/get_version.sh /tmp/"$appname"_get_version.sh
|
2023-04-09 01:47:32 +00:00
|
|
|
|
chmod +x /tmp/"$appname"_get_version.sh
|
2022-07-26 08:44:34 +00:00
|
|
|
|
bash /tmp/"$appname"_get_version.sh $containername
|
2022-07-18 01:04:06 +00:00
|
|
|
|
break
|
2022-07-27 03:52:50 +00:00
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
for appinfo in $(docker ps --format '{{.Names}}%{{.Image}}'); do
|
|
|
|
|
|
|
|
|
|
containername=$(echo $appinfo |awk -F"%" '{print $1}')
|
|
|
|
|
imagename=$(echo $appinfo |awk -F"%" '{print $2}')
|
|
|
|
|
|
|
|
|
|
for appname in $appnames; do
|
|
|
|
|
|
|
|
|
|
if [[ $imagename =~ $appname ]];then
|
2022-07-18 03:42:49 +00:00
|
|
|
|
if [[ $targetlist =~ $appname ]];then
|
2022-07-18 00:44:39 +00:00
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
tmpvar="-"
|
|
|
|
|
if [[ $containername =~ $tmpvar ]];then
|
2022-07-26 06:47:27 +00:00
|
|
|
|
echo "$imagename=镜像名匹配成功app:$appname, and容器名是:$containername"
|
2022-07-18 03:42:49 +00:00
|
|
|
|
targetlist="$targetlist $appname"
|
2023-04-18 01:58:49 +00:00
|
|
|
|
cp /data/apps/library/apps/"$appname"/src/get_version.sh /tmp/"$appname"_get_version.sh
|
2023-04-09 01:47:32 +00:00
|
|
|
|
chmod +x /tmp/"$appname"_get_version.sh
|
2022-07-26 08:44:34 +00:00
|
|
|
|
bash /tmp/"$appname"_get_version.sh $containername
|
2022-07-18 01:04:06 +00:00
|
|
|
|
break
|
2022-07-18 01:04:45 +00:00
|
|
|
|
fi
|
2022-07-15 08:40:03 +00:00
|
|
|
|
else
|
2022-07-18 01:40:31 +00:00
|
|
|
|
realapp=echo $containername|awk -F"-" '{print $1}'
|
|
|
|
|
services=docker compose -p $realapp ps --services
|
|
|
|
|
for service in $services; do
|
|
|
|
|
if [[ $service == $appname ]];then
|
2022-07-26 06:47:27 +00:00
|
|
|
|
echo "$service服务名匹配成功app:$appname, and容器名是:$containername"
|
2022-07-18 03:42:49 +00:00
|
|
|
|
targetlist="$targetlist $appname"
|
2023-04-18 01:58:49 +00:00
|
|
|
|
cp /data/apps/library/apps/"$appname"/src/get_version.sh /tmp/"$appname"_get_version.sh
|
2023-04-09 01:47:32 +00:00
|
|
|
|
chmod +x /tmp/"$appname"_get_version.sh
|
2022-07-26 08:44:34 +00:00
|
|
|
|
bash /tmp/"$appname"_get_version.sh $containername
|
2022-07-18 01:40:31 +00:00
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
2022-07-15 08:40:03 +00:00
|
|
|
|
fi
|
2022-07-16 00:58:18 +00:00
|
|
|
|
done
|
2022-07-15 07:57:02 +00:00
|
|
|
|
done
|