#!/bin/bash

. ${TOOLKIT}-functions.sh

# printer drivers dir relocations
#
dir=/etc/samba/printers
[ -d $dir ] || {
	here=$(pwd)
	create_dir $dir root:root	|| exit $?
	cd /var/lib/samba/printers	|| exit $?
	cp -af * $dir/.			|| exit $?
	cd $here
}

file="user-aliases"
[ -f /etc/samba/$file ] || {
	installfile $file /etc/samba/ root:root 644
}

getconfirm samba.ldap && {
	case $DISTRIB_ID in
	   Devuan)
  		echo "  WARNING: LDAP backend not available on samba4"
		;;
  	   *)
		if [ -r /etc/ldap.secret ]
		then
			echo -n "  using /etc/ldap.secret: "
			pass=`cat /etc/ldap.secret`
		else
			pass=`jtconf ldap.admin_password 2>/dev/null` && {
				echo "  using kusa DB: "
			}
		fi
		[ "$pass" != "" ] && {
			smbpasswd -w $pass || exit $?
		}

		# ldap enabled, install properly patched upstart file
		#
		[ -d /etc/init ] && {
			installfile smbd.conf /etc/init/ root:root 444
		}
		;;
	esac
} # getconfirm samba.ldap && {



$SOMETHING_CHANGED && {
	if [ -f /etc/init.d/samba ]
	then
		restart_service samba
	else
		restart_service smbd
		restart_service nmbd
	fi
}
exit 0
