#!/bin/sh

set -e

echo "Ensure apt integration is installed"
apt-config dump | grep -i Post-Invoke-Success | grep cnf-update-db

echo "Ensure apt update runs without errors"
apt-get update

echo "Ensure we have results from c-n-f"
/usr/lib/command-not-found --ignore-installed apt-ftparchive 2>&1 | grep apt-utils
/usr/lib/command-not-found --ignore-installed apt-ftparchive 2>&1 | grep -xF "apt install apt-utils"


echo "Add testuser"
adduser --gecos="no" --disabled-password testuser

echo "Ensure c-n-f works as user"
su -l testuser -c "/usr/lib/command-not-found --ignore-installed konsole" 2>&1 | grep konsole

echo "Ensure c-n-f database is world-readable"    # cf. #986461
rm -f /var/lib/command-not-found/*
(umask 0077 && /usr/lib/cnf-update-db)
su -l testuser -c "/usr/lib/command-not-found --ignore-installed emacs" 2>&1 | grep emacs
