[buildout]
extends =
  ../alsa/buildout.cfg
  ../dash/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

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

[firefox]
<= firefox-51

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

depends =
  ${liberation-fonts:location}
  ${ipaex-fonts:location}

version = 51.0.1

x86 = http://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/linux-i686/en-US/firefox-${:version}.tar.bz2 9a5b67e9d759a1e4df004294a24b2b43
x86-64 = http://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/linux-x86_64/en-US/firefox-${:version}.tar.bz2 bd93f2652d1d90d59ae462439a93c85f
geckodriver_x86 = https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux32.tar.gz b5836f5a944fe9f3ed1a67c7b342c6a7
geckodriver_x86-64 = https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux64.tar.gz 4a185d3179862a35104603b9274452e7

script =
  if not self.options.get('url'): self.options['url'], self.options['md5sum'] = self.options[guessPlatform()].split(' ')
  extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
  workdir = guessworkdir(extract_dir)
  self.copyTree(workdir, "%(location)s")
  geckodriver_url, geckodriver_md5sum = self.options['geckodriver_' + guessPlatform()].split(' ')
  extract_dir = self.extract(self.download(geckodriver_url, geckodriver_md5sum))
  shutil.copy(extract_dir + '/geckodriver', "%(location)s")
  wrapper_location = os.path.join("%(location)s", "firefox-slapos")
  wrapper = open(wrapper_location, 'w')
  wrapper.write("""#!${dash:location}/bin/dash
  cd %(location)s
  export LD_LIBRARY_PATH="%(location)s"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${alsa:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${atk:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${at-spi2-atk:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${at-spi2-core:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${bzip2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${cairo:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${dbus:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${dbus-glib:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${fontconfig:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${freetype:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gdk-pixbuf:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gettext:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${glib:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gtk-3:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${harfbuzz:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libepoxy:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libffi:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libICE:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libpng:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libSM:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libtool:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libuuid:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libX11:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXau:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libxcb:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXcomposite:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXcursor:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXext:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXi:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libxml2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXrender:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXt:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${mesa:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pango:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pcre:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pixman:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xdamage:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xfixes:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xz-utils:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${zlib:location}/lib"
  export PATH=${fontconfig:location}/bin:$PATH
  exec %(location)s/firefox $*""")
  wrapper.close()
  os.chmod(wrapper_location, 0755)

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

depends =
  ${liberation-fonts:location}
  ${ipaex-fonts:location}

version = 45.0.1

# MD5SUMs are available at :
# https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/${:version}/MD5SUMS
x86 = http://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/linux-i686/en-US/firefox-${:version}.tar.bz2 3756c8d06d6f915a3dff1dae643ee74b
x86-64 = http://download-installer.cdn.mozilla.net/pub/firefox/releases/${:version}/linux-x86_64/en-US/firefox-${:version}.tar.bz2 0409177ef649ec90ffe7a421a19bc156

script =
  if not self.options.get('url'): self.options['url'], self.options['md5sum'] = self.options[guessPlatform()].split(' ')
  extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
  workdir = guessworkdir(extract_dir)
  self.copyTree(workdir, "%(location)s")
  wrapper_location = os.path.join("%(location)s", "firefox-slapos")
  wrapper = open(wrapper_location, 'w')
  wrapper.write("""#!${dash:location}/bin/dash
  cd %(location)s
  export LD_LIBRARY_PATH="%(location)s"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${alsa:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${atk:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${bzip2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${cairo:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${dbus:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${dbus-glib:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${fontconfig:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${freetype:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gdk-pixbuf:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gettext:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${glib:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gtk-2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${harfbuzz:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libICE:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libSM:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libX11:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXau:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXcomposite:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXcursor:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXext:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXrender:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXt:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libffi:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libpng:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libtool:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libuuid:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libxcb:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libxml2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${p11-kit:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pango:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pixman:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xdamage:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xfixes:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${zlib:location}/lib"
  export PATH=${fontconfig:location}/bin:$PATH
  exec %(location)s/firefox $*""")
  wrapper.close()
  os.chmod(wrapper_location, 0755)
