# Fixes search @ http://box/modules/es-wikihow (popular with Spanish youth)
# Source code: http://download.iiab.io/packages/php-stem.src.tar
# June 2018 debugging & compilation thanks to Tim Moody & George Hunt
# Original bug: https://github.com/iiab/iiab/issues/829

- name: Set fact stem available php 7.2 - includes x86_64 only
  set_fact:
    stem_available: True
  when: ansible_machine == "x86_64" and php_version == 7.2

- name: Set fact stem available php 7.3 - excludes i386
  set_fact:
    stem_available: True
  when: not ansible_machine == "i386" and php_version == 7.3

- name: Set fact stem available php 7.4
  set_fact:
    stem_available: True
  when: php_version == 7.4 and (ansible_machine == "aarch64" or ansible_machine == "x86_64")

- name: Unarchive http://download.iiab.io/packages/php{{ php_version }}-stem.rpi.tar to / (rpi)
  unarchive:
    src: http://download.iiab.io/packages/php{{ php_version }}-stem.rpi.tar
    dest: /
    owner: root
    group: root
    #mode: ????
    remote_src: yes
  when: ansible_machine == "armv7l" and stem_available is defined

- name: Unarchive http://download.iiab.io/packages/php{{ php_version }}-stem.aarch64.tar to / (rpi)
  unarchive:
    src: http://download.iiab.io/packages/php{{ php_version }}-stem.aarch64.tar
    dest: /
    owner: root
    group: root
    #mode: ????
    remote_src: yes
  when: ansible_machine == "aarch64" and stem_available is defined

- name: Unarchive http://download.iiab.io/packages/php{{ php_version }}-stem.x64.tar to / (x64)
  unarchive:
    src: http://download.iiab.io/packages/php{{ php_version }}-stem.x64.tar
    dest: /
    owner: root
    group: root
    #mode: ????
    remote_src: yes
  when: ansible_machine == "x86_64" and stem_available is defined

- name: Symlink /etc/php/{{ php_version }}/fpm/conf.d/20-stem.ini -> /etc/php/{{ php_version }}/mods-available/stem.ini
  file:
    src: "/etc/php/{{ php_version }}/mods-available/stem.ini"
    path: "/etc/php/{{ php_version }}/fpm/conf.d/20-stem.ini"
    state: link
  when: stem_available is defined

# Not sure what to do for apache, so do nothing for now

# The following are probably no longer true 2020-01-25
# Presumably fails on Debian 8 & 10?
# Fails on Debian i686 as of 2018-08-07: https://github.com/iiab/iiab/issues/983
# Fails on Ubuntu 18.04 as of 2018-07-28: https://github.com/iiab/iiab/issues/829
