#!/bin/bash # # check input if [ -z "$1" ]; then echo "*****************************************************************" echo echo " Please input image like below:" echo " registry.svicloud.com/powercloud/oms/server:V01R01B18-3043" echo echo "*****************************************************************" echo exit 1 fi # if has another process retry=30 while true; do ps_count=`ps -ef | grep -v grep | grep ${0#./*} | wc -l` retry_count=`expr $retry_count + 1` # 30 times if [ "$retry_count" -ge $retry ]; then echo "timeout after 90 seconds, exit." echo exit 1 fi # has other process if [ $ps_count -ge 3 ] ; then echo "another process \"${0#./*}\" is running, retry after 3 seconds." sleep 3 else break fi done # feature echo echo " 在这台服务器上推拉镜像到法国,会比其它服务器快至少 10 倍的速度 :)" echo " 点解...?" echo which cstream &>/dev/nulll && \ echo " 科学上网,你值得拥有! --- Need help? QQ: 85509336" | cstream -b1 -t10 || \ echo " 科学上网,你值得拥有! --- Need help? QQ: 85509336" && sleep 1 echo # make a host entry if ! grep -q "registry.svicloud.com" /etc/hosts; then echo "151.106.8.135 registry.svicloud.com" >>/etc/hosts fi # comment to use local repo sed -i "/^[^#].*registry.svicloud.com/s/^/#/" /etc/hosts # login local repo docker login -u admin -p Changeme_123 registry.svicloud.com &>/dev/null || \ { echo "docker login to local repo failed" && echo && exit 1; } # pull the image if docker pull $1; then sed -i "/^[#].*registry.svicloud.com/s/^#//" /etc/hosts sleep 2 echo "checking remote registry status with ping 5 packages" ping registry.svicloud.com -c 5 docker login -u admin -p "Gocm5]WeqaSufg" registry.svicloud.com &>/dev/null || \ { echo "docker login to remote repo failed" && echo && exit 1; } echo if docker push $1; then echo "push success" else echo "push $1 to remote repo failed" echo exit 1 fi else echo "pull local image $1 to local server failed" echo exit 1 fi