#!/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 && {
	# starting from 10.04 (upstart enabed) the name is changed
	# and nmbd is separated from smbd
	#
	case $DISTRIB_FULL_ID in
	  Ubuntu-9*)
		reload_service samba smbd || exit 1
		;;
	  Ubuntu*)
		reload_service smbd smbd || exit 1
		reload_service nmbd nmbd || exit 1
		;;
	  Devuan*)
		reload_service smbd smbd || exit 1
		restart_service nmbd nmbd || exit 1
		;;
	esac
}
exit 0
