# http://www.proftpd.org/ - Highly configurable GPL-licensed FTP server software

[buildout]
extends = 
  ../openssl/buildout.cfg
  ../perl/buildout.cfg
  ../zlib/buildout.cfg
  ../curl/buildout.cfg
  ../libtool/buildout.cfg
  ../git/buildout.cfg
  ../patch/buildout.cfg
  ../zstd/buildout.cfg

# proftpd server
[proftpd-info]
recipe = slapos.recipe.build
init =
  import grp, os, pwd
  options['USER'] = pwd.getpwuid(os.getuid())[0]
  options['GROUP'] = grp.getgrgid(os.getgid())[0]

[proftpd]
recipe = slapos.recipe.cmmi
md5sum = 4a9b8877b2e9b08d70e71ad56c19e2c9
url = ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.7a.tar.gz
configure-options =
  --enable-openssl
  --enable-nls
  --enable-ctrls
  --enable-dso
  --disable-cap
  --with-modules=mod_sftp:mod_ban:mod_rewrite
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-info:USER}
  install_group=${proftpd-info: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
post-install =
  sed -i '1c\
  #!${perl:location}/bin/perl
  ' %(prefix)s/bin/ftpasswd

# 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
revision = e36105808b7d07d843b11f428a666a8f3cec35e4
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 -R ${zstd:location}/lib' \
  -l curl \
  ${proftpd-mod_auth_web-repository:location}/mod_auth_web.c
location=${proftpd:location}/libexec/mod_auth_web.so

[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}

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