#!/usr/local/bin/cbsd
#v9.2.2
MYARG="jname"
MYOPTARG=""
MYDESC="Populate rsyncd.conf for jail part"

. ${subrdir}/nc.subr
. ${cbsdinit}

[ -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_CMD} -c "^\[${jname}\]" ${etcdir}/rsyncd.conf ) -eq "0" ]; then
${CAT_CMD} >> ${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

# sysdata module
if [ $( ${GREP_CMD} -c "^\[${jname}-sysdata\]" ${etcdir}/rsyncd.conf ) -eq "0" ]; then
${CAT_CMD} >> ${etcdir}/rsyncd.conf << EOF
[${jname}-sysdata]
list = no
uid = root
gid = wheel
read only = no
path = ${jailsysdir}/${jname}
auth users = ${jname}
secrets file = ${etcdir}/${jname}.secrets
exclude = /locked
EOF
fi
