#!/bin/sh

set -e

save_log_files() {
    cp -rf /tmp/check-all-pages/ "${AUTOPKGTEST_ARTIFACTS}"
    # Temporarily until release 1.2.24
    chmod a+r -R "${AUTOPKGTEST_ARTIFACTS}"
}

database_pw=$(grep -m1 database_password /etc/cacti/debian.php | \
		  awk '{print $3}' | sed "s/';//" | sed "s/'//")
database_pw=${database_pw%%\";}
database_pw=${database_pw#\"}

# Remove the crontab line to prevent the cron from interfering
rm -f /etc/cron.d/cacti

# Test suite should run fine with non-English locale
mysql -e "insert into cacti.settings set value = 'nl-NL', name = 'i18n_default_language' ;" cacti
mysql -e "insert into cacti.settings set value = 0, name = 'i18n_auto_detection' ;" cacti

debian/tests/check-all-pages

# To make sure that the autopkgtest/CI sites store the information
if [ -n "${AUTOPKGTEST_ARTIFACTS}" ] ; then
    trap save_log_files 0
fi

tests/tools/check_all_pages.sh -du cacti -dp ${database_pw}
