#!/bin/bash

. ${TOOLKIT}-functions.sh

full_users=`	jtconf ftp.full_users 2>/dev/null	| tr ',' ' '`
full_groups=`	jtconf ftp.full_groups 2>/dev/null	| tr ',' ' '`
chroot_users=`	jtconf ftp.chroot_users 2>/dev/null	| tr ',' ' '`

[ "$full_users" != "" -o "$full_groups" != "" ] && {
	[ "$chroot_users" != "" ] && \ 
		exit_err 1 "you can't user both anon (chroot) and full users at the same time"
}

echo "  building ftp access files ..."

#----------------------------------------------------------------
# build full access users/groups entries
#----------------------------------------------------------------

outfile=ku-users-full.conf.tmp
orig=ku-users-full.conf

if [ "$full_users" != "" -o "$full_groups" != "" ]
then
	acls=

	for user in $full_users
	do
		printf "   user  %-12s full access\n" $user
		acls="$acls  AllowUser	$user\n"
	done
	for group in $full_groups
	do
		printf "   group %-12s full access\n" $group
		acls="$acls  AllowGroup	$group\n"
	done
	sed -e "s#--ku-tag-insert-acl-here--#$acls#" $orig > $outfile || exit $?
else
	cp /dev/null $outfile
fi

exit 0
