[buildout]
extends =
  ../alsa/buildout.cfg
  ../dbus/buildout.cfg
  ../fontconfig/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 names ${:wrapper-name} 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.
wrapper-name = firefox
part = ${firefox:location}

recipe = slapos.recipe.build
location = ${buildout:bin-directory}/${:wrapper-name}
script =
  firefox = self.options['part']
  part = self.buildout[os.path.basename(firefox)]
  with open(%(location)r, 'w') as f:
    f.write("""#!/bin/sh -e
  cd {}
  export LD_LIBRARY_PATH=$PWD:{}
  export PATH={}:$PATH
  exec ./firefox "$@"
  """.format(
    firefox,
    ':'.join(part['library'].split()),
    ':'.join(part['path'].split()),
  ))
    os.fchmod(f.fileno(), 0o755)

[firefox-wrapper-68]
<= firefox-wrapper
wrapper-name = firefox-68
part = ${firefox-68:location}

[firefox-wrapper-60]
<= firefox-wrapper
wrapper-name = firefox-60
part = ${firefox-60:location}

[firefox-wrapper-52]
<= firefox-wrapper
wrapper-name = firefox-52
part = ${firefox-52:location}

[firefox-wrapper-51]
<= firefox-wrapper
wrapper-name = firefox-51
part = ${firefox-51:location}


[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-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-51]
<= firefox-download
version = 51.0.1
i686-md5sum = 9a5b67e9d759a1e4df004294a24b2b43
x86_64-md5sum = bd93f2652d1d90d59ae462439a93c85f


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

x86 = https://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/linux-i686/en-US/firefox-${:version}.tar.bz2 ${:i686-md5sum}
x86-64 = https://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/linux-x86_64/en-US/firefox-${:version}.tar.bz2 ${:x86_64-md5sum}

fonts =
  ${liberation-fonts:location}
  ${ipaex-fonts:location}
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

script =
  url, md5sum = self.options[guessPlatform()].split()
  extract_dir = self.extract(self.download(url, md5sum))
  self.copyTree(guessworkdir(extract_dir), %(location)r)


[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.21.0]
<= geckodriver-base
version = 0.21.0
i686-md5sum = 9fc1657dd1b94272d0cdb3b29ca80f79
x86_64-md5sum = 6bc36d4fd4975e296cdb3fa3c5e26a41

[geckodriver-0.19.0]
<= geckodriver-base
version = 0.19.0
i686-md5sum = 07cd383c8aef8ea5ef194a506141afd6
x86_64-md5sum = ca6935a72fd0527d15a78a17a35e56e8

[geckodriver-0.17.0]
<= geckodriver-base
version = 0.17.0
i686-md5sum = 79b1a158f96d29942a111c0905f1c807
x86_64-md5sum = be18faeea6e7db9db6990d8667e2298f

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

[geckodriver-0.14.0]
<= geckodriver-base
version = 0.14.0
i686-md5sum = b5836f5a944fe9f3ed1a67c7b342c6a7
x86_64-md5sum = 4a185d3179862a35104603b9274452e7


[geckodriver-base]
# Installs geckodriver ${version}
recipe = slapos.recipe.build
location = ${buildout:bin-directory}/${:_buildout_section_name_}

x86 = https://github.com/mozilla/geckodriver/releases/download/v${:version}/geckodriver-v${:version}-linux32.tar.gz ${:i686-md5sum}
x86-64 = https://github.com/mozilla/geckodriver/releases/download/v${:version}/geckodriver-v${:version}-linux64.tar.gz ${:x86_64-md5sum}

script =
  url, md5sum = self.options[guessPlatform()].split()
  extract_dir = self.extract(self.download(url, md5sum))
  shutil.copy(extract_dir + '/geckodriver', %(location)r)
