#!/bin/sh
#v9.2.2
globalconf="${workdir}/cbsd.conf";
MYARG="jname"
MYOPTARG=""
MYDESC="Populate rsyncd.conf for jail part"

# TODO
# lock is needet
set -e
. ${globalconf}
set +e

. ${subr}
init $*

[ -z "${jname}" ] && err 1 "Empty jailname"
[ ! -f ${etcdir}/rsyncd.conf ] && err 1 "no such rsyncd.conf  file";

## here we can use dir location from conffile for rsync to correct place
## but now is hardcode for prototype test and security reason (empty jaildir can delete root)
##
if [ $( grep -c "^\[${jname}\]" ${etcdir}/rsyncd.conf ) -eq "0" ]; then
cat >> ${etcdir}/rsyncd.conf << EOF
[${jname}]
list = no
uid = root
gid = wheel
read only = no
path = ${jaildatadir}/${jname}-data
auth users = ${jname}
secrets file = ${etcdir}/${jname}.secrets
EOF
fi
