#!/usr/bin/env bash

set -o pipefail

source $(dirname $0)/../.vars

export container_name=ansible-docker
export image_tag=2.9.13-$(uname -m)
export image_file=ansible-docker-${image_tag}.tar.xz
export image_name=registry.cn-shenzhen.aliyuncs.com/shuhui/ansible-docker:${image_tag}

# 判断镜像是否已经导入
docker images | grep "${container_name}" | grep "${image_tag}" >/dev/null

if [[ "$?" != "0" ]] 
then

    printf "$info: 镜像压缩包解压中...\n"
    mkdir -p $(dirname $0)/../images/ansible && tar axvf $(dirname $0)/../images/${image_file} -C $(dirname $0)/../images/ansible >/dev/null

    printf "$info: 导入镜像： [ ${bldgre}${image_name##*/}${txtrst} ]\n"

    docker load < $(dirname $0)/../images/ansible/ansible-docker.tar >/dev/null && rm -rf $(dirname $0)/../images/ansible

else
    printf "$info: 镜像已存在： [ ${bldgre}${image_name##*/}${txtrst} ]\n"
fi
