#!/bin/bash

eval "$(ucr shell)"

dpkg -C

univention-check-join-status

if [ "$server_role" = "memberserver" ]; then
	if [ -x /etc/init.d/samba ]; then
		net ads testjoin
	fi
fi

if [ -n "$samba4_role" ]; then
	wbinfo --ping
	wbinfo --ping-dc
	wbinfo --check-secret
fi

if [ "$server_role" != "${server_role#domaincontroller_}" ]; then
	if [ "$samba4_role" = "DC" ]; then
		kdestroy;
		kinit -t /etc/krb5.keytab "${hostname^^}$"
		klist; kdestroy
		kinit -t /var/lib/samba/private/dns.keytab "dns-$(hostname)"
		klist; kdestroy
		samba-tool drs showrepl
		/usr/share/univention-samba4/scripts/check_essential_samba4_dns_records.sh
		ldbsearch -H ldapi:///var/lib/samba/private/ldap_priv/ldapi sAMAccountName="${hostname}$" msDS-KeyVersionNumber
		ldbsearch -H /var/lib/samba/private/secrets.ldb objectClass=primaryDomain msDS-KeyVersionNumber
		# samba-tool dbcheck
	fi
fi

## Possibly offer to automatically upload this as encrypted email?
# wget -q "http://download.univention.de/download/univention-support.asc" -O - | gpg --import
# gpg --encrypt --trust-model always -a -r "support@univention.de" <Filename>
