#!/bin/bash
# kola: { "timeoutMin": 20 }
#
# Copyright (C) 2022 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

set -euo pipefail

. ${KOLA_EXT_DATA}/libtest.sh

set -x

libtest_prepare_offline
cd $(mktemp -d)
image_dir=/var/tmp/fcos
image=oci:$image_dir
image_pull=ostree-unverified-image:$image
tmp_imagedir=/var/tmp/fcos-tmp
arch=$(arch)

systemctl mask --now zincati

# Take the existing ostree commit, and export it to a container image, then rebase to it.
checksum=$(rpm-ostree status --json | jq -r '.deployments[0].checksum')

ostree container encapsulate --repo=/ostree/repo ${checksum} containers-storage:localhost/fcos
podman run --privileged --pid=host --net=host --rm -v /:/run/host --rm localhost/fcos rpm-ostree ex deploy-from-self /run/host

echo ok container-update-inplace
