#!/bin/sh

. /etc/sysconfig/system

[ "$SERVER_ROLE" = "master" ] || exit 0
[ "$2" = "add" ] || exit 0
target="$1"
shift
shift

. alterator-kdc-functions

cat <<E_O_F |trust-ssh $target
smbconf='/etc/samba/smb.conf'
[ -f \$smbconf ] || exit 0
sed -i \
    -e "/^[[:blank:]]*realm/ s/=.\+$/= $(realm)/" \
    -e "/^[[:blank:]]*passdb[[:blank:]]\+backend/ s,=.\+$,= ldapsam:ldaps://$(hostname)/," \
    -e "/^[[:blank:]]*ldap[[:blank:]]\+suffix/ s/=.\+$/= $(suffix)/" \
    -e "/^[[:blank:]]*ldap[[:blank:]]\+admin[[:blank:]]\+dn/ s/=.\+$/= $(rootdn)/" \$smbconf
smbpasswd -w $(rootpw)
E_O_F
