#!/usr/bin/env bash

set -e

if [ "$#" -ne 1 ]; then
  echo "Useage: ./ctrpull.sh image_name:tag"
  exit 1
fi

image=$1
tar_file=$(basename "${image}" | sed 's/:/-/g')

# 拉取镜像
ctr i pull ${image}

# 导出镜像为 tar 文件
ctr i export ${tar_file}.tar ${image}

# 删除本地镜像
ctr i rm ${image}

