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

[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-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.17.0

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


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