#!/bin/bash

# This script takes care of configuring the system to use the Zentyal Samba
# module. Most of the parts are needed to have a Samba PDC configuration.
#
# TODO: Do the script idempotent
#       User Perl

# stop samba
stop smbd
stop nmbd

# restart users
invoke-rc.d zentyal users restart

# create home directories
test -d /home/samba || mkdir /home/samba
test -d /home/samba/groups || mkdir /home/samba/groups
test -d /home/samba/profiles || mkdir /home/samba/profiles
test -d /home/samba/netlogon || mkdir /home/samba/netlogon

# add mandatory items to domain database
/usr/share/zentyal-samba/samba-ldap populate-ldap

# update current users in ldap database
/usr/share/zentyal-samba/samba-ldap update-users

# generate smb.conf and ldap.conf
/usr/share/zentyal-samba/samba-ldap genconfig

# update current ldap database
/usr/share/zentyal-samba/samba-ldap update-pdc

/usr/share/zentyal-samba/samba-ldap fix-sids

exit 0
