#!/bin/sh

# Copyright (c) KylinSoft Co., Ltd. 2016-2024.All rights reserved.
#
# Authors:
# Ma Chao    machao@kylinos.cn
# Alan Xie   xiehuijun@kylinos.cn
# Clom       huangcailong@kylinos.cn
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

IMAGE_REPO=$(crudini --get /usr/share/kmre/kmre.conf image repo 2>/dev/null)
if [ "$IMAGE_REPO"X = X ]; then
    exit 0
fi

IMAGE_TAG=$(crudini --get /usr/share/kmre/kmre.conf image tag 2>/dev/null)
if [ "$IMAGE_TAG"X = X ]; then
    exit 0
fi

IMAGE_NAME="${IMAGE_REPO}:${IMAGE_TAG}"
/usr/bin/docker images "$IMAGE_REPO" --format '{{.Repository}}:{{.Tag}}' | grep -q "\<$IMAGE_NAME\>"
if [ "$?" != "0" ]; then
    /usr/bin/docker load -i /usr/share/kmre/kmre-container-image.tar
fi

exit 0
