#!/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 # 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 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