#! /bin/bash

# test fai-cd

#set -e

. ./debian/tests/common.sh
trap "cp -vp fai-cd.log $AUTOPKGTEST_ARTIFACTS" INT QUIT EXIT
cd "$AUTOPKGTEST_TMP"

mdir=/tmp/mirror

if [ ! -d /srv/fai/config ]; then
    sudo fai-mk-configspace
fi
if [ ! -d /srv/fai/nfsroot ]; then
    sudo fai-make-nfsroot -zgv
fi
chk-size /srv/fai/nfsroot 700
chk-file /srv/fai/nfsroot/var/tmp/packages.nfsroot
chk-file /srv/fai/nfsroot/var/tmp/base-pkgs.lis

if [ ! -d $mdir ]; then
    fai-mirror -h
    echo "Creating package mirror $mdir"
    su $AUTOPKGTEST_NORMAL_USER -c "fai-mirror -v -s$CS -m1 -xARM64,I386,ROCKY,UBUNTU,FOCAL,CLOUD,CHROOT,STANDARD,NONFREE,GNOME $mdir >& /tmp/mirror.log"
    ls -l /tmp/mirror.log
fi
chk-size $mdir 420

# - - - - - - - - - - - - - - - - -
fai-cd -Jm $mdir faicd64-small.iso >& fai-cd.log
echo fai-cd exit code: $?


# test the results of the commands called
chk-size faicd64-small.iso 730

if [ X$NO_CLEANUP != X1 ]; then
    rm -rf /tmp/mirror
fi
