# http://www.proftpd.org/ - Highly configurable GPL-licensed FTP server software
#
# Because it uses collective.recipe.environment this components needs slapos.core >= 1.4.7
# ( grid: do not hide `$USER` when running buildout )
#
[buildout]
extends = 
  ../openssl/buildout.cfg
  ../perl/buildout.cfg
  ../zlib/buildout.cfg
  ../curl/buildout.cfg
  ../libtool/buildout.cfg
  ../git/buildout.cfg

# proftpd server
[proftpd-environment]
recipe = collective.recipe.environment

[proftpd-grp]
recipe = collective.recipe.grp

[proftpd]
recipe = slapos.recipe.cmmi
md5sum = 13270911c42aac842435f18205546a1b
url = ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.6.tar.gz
configure-options =
  --enable-openssl
  --enable-nls
  --enable-ctrls
  --enable-dso
  --with-modules=mod_sftp:mod_ban
  --prefix=${buildout:parts-directory}/${:_buildout_section_name_}
environment = 
  CPPFLAGS=${:cppflags}
  LDFLAGS=${:ldflags}
  install_user=${proftpd-environment:USER}
  install_group=${proftpd-grp:GROUP}
cppflags=-I${zlib:location}/include -I${openssl:location}/include
ldflags=-L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib -L${openssl:location}/lib -Wl,-rpath=${openssl:location}/lib


# mod_auth_web: a proftpd module to authenticate users against an HTTP service
[proftpd-mod_auth_web-repository]
recipe = slapos.recipe.build:gitclone
#repository = https://github.com/proftpd/mod_auth_web
# XXX until https://github.com/proftpd/mod_auth_web/pull/1 gets merged, we use
# the source repository of this PR directly
repository = https://github.com/jwm/mod_auth_web
revision = dec090bd0e287544a34be156ee17f715bd4286f9
git-executable = ${git:location}/bin/git

[proftpd-mod_auth_web]
recipe = plone.recipe.command
stop-on-error = true
command =
  LIBTOOL=${libtool:location}/bin/libtool \
  LDFLAGS="-Wl,-rpath=${curl:location}/lib ${proftpd:ldflags}" \
  ${proftpd-output:prxs} -c -i \
  -I ${curl:location}/include ${proftpd:cppflags} \
  -L ${curl:location}/lib/ \
  -l curl \
  -d ${proftpd-mod_auth_web-repository:location}/mod_auth_web.c
location=${proftpd:location}/libexec/mod_auth_web.so


# ftpasswod: a perl script to manage a proftpd AuthUserFile
[ftpasswd]
recipe = slapos.recipe.build:download
url = https://raw.githubusercontent.com/proftpd/proftpd/v1.3.6/contrib/ftpasswd
md5sum = 4a47df2cab86d8de7077a445bb416f31
download-only = true
mode = 0700


[proftpd-output]
# Shared binary location to ease migration
recipe = plone.recipe.command
stop-on-error = true
update-command = ${:command}
command = ${coreutils-output:test} -x ${:proftpd} -a -x ${:ftpasswd}
modules-deps =
  ${proftpd-mod_auth_web:recipe}

perl = ${perl:location}/bin/perl
ftpasswd = ${ftpasswd:target}
proftpd = ${proftpd:location}/sbin/proftpd
prxs = ${proftpd:location}/bin/prxs
ftpdctl = ${proftpd:location}/bin/ftpdctl