#! /bin/bash

# test fai dirinstall

set -e

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

ch=/srv/chroot
cl="DEBIAN,AMD64,FAIBASE,DHCPC,DEMO,LAST"
export NIC1=dummy
LC_ALL=C fai -v dirinstall -c $cl -s file://$CS $ch >& dirinstall.log



# test the results of the commands called
chk-size $ch 780
chk-size $ch/boot 30

# chroot into and execute some commands
chroot $ch ls -l /boot/ || error "error calling ls in chroot"
chroot $ch /usr/bin/ldd --version
chroot $ch /usr/bin/apt --version  || error "error calling apt in chroot"
chroot $ch /usr/bin/systemd --version
chk-no-file $ch/etc/dpkg/dpkg.cfg.d/unsafe-io

grep tmpfs $ch/etc/fstab
if [ ! -f $ch/etc/network/interfaces.d/dummy ]; then
    error "dirinstall failed. interfaces.d/dummy is missing"
fi
if [ ! -d $ch/home/demo/ ]; then
    error "dirinstall failed. No home dir for user demo"
fi
if grep -q FAILED $ch/var/log/fai/localhost/last/status.log; then
    error "dirinstall failed. See status.log"
fi
if grep -q FAILED dirinstall.log; then
    error "dirinstall failed. See dirinstall.log"
fi

if [ X$NO_CLEANUP != X1 ]; then
    rm -rf $ch
fi
