# 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
  ../patch/buildout.cfg

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

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

[proftpd]
recipe = slapos.recipe.cmmi
md5sum = 4040f6a6b86173e2a03f4ccdb9b9af6e
url = ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.6b.tar.gz
configure-options =
  --enable-openssl
  --enable-nls
  --enable-ctrls
  --enable-dso
  --disable-cap
  --with-modules=mod_sftp:mod_ban
  --prefix=${buildout:parts-directory}/${:_buildout_section_name_}
environment =
  CFLAGS=-DPR_RUN_DIR=\"/proc/self/cwd/var\"
  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
  install_user=${proftpd-environment:USER}
  install_group=${proftpd-grp:GROUP}
patch-binary = ${patch:location}/bin/patch
patch-options = -p1
patches =
  ${:_profile_base_location_}/0001-mod_rlimit-don-t-change-PR_SET_DUMPABLE-flag.patch#6e58a7a429ff96a51812dc9835e4c227

# 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
# prxs does not support setting rpath, but we can "inject" -R that will be passed to libtool
command =
  LIBTOOL=${libtool:location}/bin/libtool \
  ${proftpd-output:prxs} -c -i -d \
  -I ${curl:location}/include \
  -L '${curl:location}/lib/ -R ${openssl:location}/lib -R ${zlib:location}/lib' \
  -l curl \
  ${proftpd-mod_auth_web-repository:location}/mod_auth_web.c
location=${proftpd:location}/libexec/mod_auth_web.so


# ftpasswd: 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 = 0755


[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
