#!/bin/bash

configFile="$1"
shareName="$2"
pathName="$3"
comment="$4"
max_connections="$5"
csc_policy="$6"

eval "$(ucr shell hostname domainname)"
ldif=$(univention-ldapsearch -LLLo ldif-wrap=no "(&(objectClass=univentionShareSamba)(univentionShareHost=$hostname.$domainname)(cn=$shareName))" dn)
dn=$(sed -n 's/^dn: //p' <<<"$ldif")
if [ -z "$dn" ]; then
	exit 1
fi

current_csc_policy=$(sed -n 's/^univentionShareSambaCscPolicy: //p' <<<"$ldif")
if [ -z "$current_csc_policy" ]; then
	current_csc_policy=manual
fi

if [ "$csc_policy" != "$current_csc_policy" ]; then
	udm shares/share modify --dn "$dn" --set sambaCscPolicy="$csc_policy"
fi
