#!/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
# Disable netbios, see bug 1129582
mysql -e "update cacti.automation_networks set enable_netbios = '' ;" cacti

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

# https://salsa.debian.org/salsa-ci-team/pipeline/-/issues/417
# artifacts aren't copied; I hope swapping the trap and the test works (but needs checking)
debian/tests/check-all-pages

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