[buildout]
extends =
  ../alsa/buildout.cfg
  ../dbus/buildout.cfg
  ../fontconfig/buildout.cfg
  ../fonts/buildout.cfg
  ../gtk-2/buildout.cfg
  ../gtk-3/buildout.cfg
  ../libffi/buildout.cfg
  ../libpng/buildout.cfg
  ../mesa/buildout.cfg
  ../p11-kit/buildout.cfg
  ../pcre/buildout.cfg
  ../xorg/buildout.cfg
  ../xz-utils/buildout.cfg

parts =
  firefox-wrapper
  geckodriver

# XXX : Firefox binary tries to find libgnomeui-2.so.0 and it will
# fail to run if exists.


[firefox-wrapper]
# Install a firefox wrapper named ${:part} in buildout's bin-directory,
# wrapping firefox installed in [${:part}]
# This [firefox-wrapper] installs the default firefox with name `firefox` and
# can also be used as a macro to install under a different name.
part = firefox

recipe = slapos.recipe.build
location = ${buildout:bin-directory}/${:part}
fonts-conf = ${firefox-default-fonts-conf:rendered}
init =
  self.buildout[options['part']]
install =
  import os
  part = self.buildout[options['part']]
  with open(location, 'w') as f:
    f.write("""#!/bin/sh -e
  d=%s
  export LD_LIBRARY_PATH=$d:%s
  export PATH=%s:$PATH
  # BBB use a default fonts.conf for compatibility, but it's software instance
  # responsability to build a fonts.conf with the fonts they want.
  [ "$FONTCONFIG_FILE" ] || export FONTCONFIG_FILE=%s
  exec $d/firefox "$@"
  """ % (
    part['location'],
    ':'.join(part['library'].split()),
    ':'.join(part['path'].split()),
    options['fonts-conf'],
  ))
    os.fchmod(f.fileno(), 0o755)

[firefox-wrapper-78]
<= firefox-wrapper
part = firefox-78

[firefox-wrapper-68]
<= firefox-wrapper
part = firefox-68

[firefox-wrapper-60]
<= firefox-wrapper
part = firefox-60

[firefox-wrapper-52]
<= firefox-wrapper
part = firefox-52

[firefox-default-fonts-conf]
recipe = slapos.recipe.template:jinja2
template = ${template-fonts-conf:output}
rendered = ${buildout:parts-directory}/${:_buildout_section_name_}/fonts.conf
context =
  key cachedir :cache-dir
  key fonts :fonts
  key includes :includes
fonts =
  ${ipaex-fonts:location}
  ${liberation-fonts:location}
includes =
  ${fontconfig:location}/etc/fonts/conf.d
cache-dir =
  ~/.fontconfig-firefox/

[firefox]
# The default installed firefox version when installing firefox-wrapper.
# Note that users must install ${firefox-wrapper:} to have a usable firefox
# installed in ${buildout:bin-directory}.
# Installing ${firefox:} is not enough, because wrapper setting $LD_LIBRARY_PATH
# would not be created.
<= firefox-68

[firefox-78]
<= firefox-download
version = 78.1.0esr
i686-md5sum = 09595a1b9a99d17a618a51bc1f971e5e
x86_64-md5sum = 06f4d488721ce7229d9a86cb4c6786f3

[firefox-68]
<= firefox-download
version = 68.0.2esr
i686-md5sum = eaa9e0246eb2a31ccf55c100dc2edd5a
x86_64-md5sum = d22dc17ce0949cdff78009afca6f2043

[firefox-60]
<= firefox-download
version = 60.0.2esr
i686-md5sum = ce7c80716036dfb5c2fb1ca2538556ff
x86_64-md5sum = 6fe25d9a3fcc82670320242c9047d1da

[firefox-52]
<= firefox-download
version = 52.9.0esr
i686-md5sum = 9aa18888b7812670208490609d75c9bc
x86_64-md5sum = 9336d70f45070c743d08e5473b783a7a

[firefox-download]
recipe = slapos.recipe.build
slapos_promise =
  file:firefox

url = https://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/${:_url}/en-US/firefox-${:version}.tar.bz2

library =
  ${alsa:location}/lib
  ${atk:location}/lib
  ${at-spi2-atk:location}/lib
  ${at-spi2-core:location}/lib
  ${bzip2:location}/lib
  ${cairo:location}/lib
  ${dbus:location}/lib
  ${dbus-glib:location}/lib
  ${fontconfig:location}/lib
  ${freetype:location}/lib
  ${gdk-pixbuf:location}/lib
  ${gettext:location}/lib
  ${glib:location}/lib
  ${gtk-2:location}/lib
  ${gtk-3:location}/lib
  ${harfbuzz:location}/lib
  ${libepoxy:location}/lib
  ${libffi:location}/lib
  ${libICE:location}/lib
  ${libpng:location}/lib
  ${libSM:location}/lib
  ${libtool:location}/lib
  ${libuuid:location}/lib
  ${libX11:location}/lib
  ${libXau:location}/lib
  ${libxcb:location}/lib
  ${libXcomposite:location}/lib
  ${libXcursor:location}/lib
  ${libXext:location}/lib
  ${libXi:location}/lib
  ${libxml2:location}/lib
  ${libXrender:location}/lib
  ${libXt:location}/lib
  ${mesa:location}/lib
  ${pango:location}/lib
  ${pcre:location}/lib
  ${pixman:location}/lib
  ${xdamage:location}/lib
  ${xfixes:location}/lib
  ${xz-utils:location}/lib
  ${zlib:location}/lib
path =
  ${fontconfig:location}/bin

install =
  self.copyTree(guessworkdir(self.extract(self.download())), location)
  ${:post-install}
post-install =

[firefox-download:getattr(sys,'_multiarch',None)=='i386-linux-gnu']
_url = linux-i686
md5sum = ${:i686-md5sum}

[firefox-download:getattr(sys,'_multiarch',None)=='x86_64-linux-gnu']
_url = linux-x86_64
md5sum = ${:x86_64-md5sum}


[geckodriver]
# Current geckodriver installed as ${buildout:bin-directory}/geckodriver
<= geckodriver-0.24.0

[geckodriver-0.24.0]
<= geckodriver-base
version = 0.24.0
i686-md5sum = b88eee754f6c90b01f760f7a453dda95
x86_64-md5sum = 7552b85e43973c84763e212af7cca566

[geckodriver-0.22.0]
<= geckodriver-base
version = 0.22.0
i686-md5sum = 6de7544753fda56fbaa8382dcac99aaa
x86_64-md5sum = 81746200ce5841e00cabf3b8ea7db542

[geckodriver-0.16.1]
<= geckodriver-base
version = 0.16.1
i686-md5sum = not not on github
x86_64-md5sum = 57dfd55d4759d9878eb75b4c0123d00c

[geckodriver-base]
# Installs geckodriver ${version}
recipe = slapos.recipe.build
url = https://github.com/mozilla/geckodriver/releases/download/v${:version}/geckodriver-v${:version}-${:_url}.tar.gz
location = ${buildout:bin-directory}/${:_buildout_section_name_}
install =
  import os, shutil
  extract_dir = self.extract(self.download(options['url'], options['md5sum']))
  shutil.copy(os.path.join(extract_dir, 'geckodriver'), location)

[geckodriver-base:getattr(sys,'_multiarch',None)=='i386-linux-gnu']
_url = linux32
md5sum = ${:i686-md5sum}

[geckodriver-base:getattr(sys,'_multiarch',None)=='x86_64-linux-gnu']
_url = linux64
md5sum = ${:x86_64-md5sum}
