#!/usr/bin/env bash
# 文  件: install_spokeo.sh
# 功  能: 安装工具

set -o pipefail

source $(realpath ../)/.vars.conf

skopeo_version=1.13.0
skopeo_file=skopeo-${skopeo_version}-${ARCH}.tar.gz
tool_name=$(echo ${skopeo_file} | awk -F '-' '{print $1}')

if [[ -e /usr/bin/${tool_name} ]]
then
    printf "$info: [ ${bldgre}${tool_name}${txtrst} ] 已存在.\n"
else
    tar axvf $(realpath ..)/files/${skopeo_file} -C /usr/bin/ 2>/dev/null
    mkdir -p /etc/containers && tee > /etc/containers/policy.json <<-EOF
{
    "default": [
        {
            "type": "insecureAcceptAnything"
        }
    ],
    "transports":
        {
            "docker-daemon":
                {
                    "": [{"type":"insecureAcceptAnything"}]
                }
        }
}
EOF

    if [[ "$?" -eq "0" ]]
    then
        printf "$info: [ ${bldgre}${tool_name}${txtrst} ] 安装完毕.\n"
    else
        printf "$err: [ ${bldgre}${tool_name}${txtrst} ] 安装失败.\n"
    fi
fi
