#!/bin/sh
set -e

if [ $(id -u) -gt 0 ]; then
	echo "ERROR: This script has to run as super-user root."
	exit 1
fi

# Attempt passwordless SSH login root@tjener (could be publickey, gssapi-keyex, or gssapi-with-mic)
set +e
ssh -o PasswordAuthentication=no -o KbdInteractiveAuthentication=no tjener "echo -n" 2>/dev/null
ret=$?
set -e
if [ "${ret}" != "0" ]; then
	# Try to get a Kerberos ticket for root instead to use GSSAPI login.
	kinit root
fi

scp tjener:/var/lib/debian-edu/host-keytabs/$(hostname -s).intern.keytab /etc/krb5.keytab

# Special case separate LTSP server.
if [ -f /srv/ltsp/dlw/etc/ltsp/ltsp.conf ] ; then
	cp /etc/krb5.keytab /srv/ltsp/dlw/etc/krb5.keytab
fi

if service nfs-common status 1>/dev/null 2>/dev/null; then
	service nfs-common restart
elif service rpc-gssd status 1>/dev/null 2>/dev/null; then
	service rpc-gssd restart
fi
