# Maintainer (aur): Jake <aur@ja-ke.tech>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>


# parabola changes and rationale:
# libre:
# - Fixed license name in 'license' array
# privacy:
# - Moved random secret key generation into an .install hook
# technical:
# - Renamed upstream source-ball


pkgname=searx
pkgver=1.1.0
pkgrel=2
pkgdesc="A privacy-respecting, hackable metasearch engine (python(3) based)"
arch=('any')
url="https://searx.github.io/searx/"
license=('AGPL3')
makedepends=('openssl')
install="${pkgname}.install"
depends=(
        'uwsgi'
        'uwsgi-plugin-python'
        'python-certifi'
        'python-flask-babel' # sub dep: flask, babel, jinja
        'python-lxml'
        'python-idna'
        'python-pygments'
        'python-dateutil'
        'python-yaml'
        'python-requests'
        'python-pysocks'
        'python-langdetect')
conflicts=('searx-git' )
replaces=('searx-py3')
backup=('etc/searx/settings.yml' 'etc/uwsgi/searx.ini')
source=(${pkgname}-${pkgver}.zip::https://github.com/searx/searx/archive/refs/tags/v1.1.0.zip
        'flask-babel-3.patch'
        'searx.ini'
        'searx.sysusers')
sha512sums=('ed92199913353ed246ff30c516402326e9eac0f439b4519d6500b516f9ef73e73d0b25d894c078fb9b65870f2b10a09777d1ae068d13c8e10c91ec14de450b1e'
            '1db543553aa4989e1cb9fb449a1c4badfd5a1c8e39afc99b5f894557ba74b9293b64d02882919ce9f2e4c108a6cd3b7acb51043e98bc3bab40e69078fbe8813f'
            '476a4297c51681a9a92c6db3933359cc5a8ec292e45b229d98608ef2906b80c173868a30df06c329204c6f9371736a5bb322239860199526fd559780b37a2d0a'
            '6856e26451fe053d37c2ce4b9d5f3b35891dd8ec702c5256c02d04415124c57705abc497f12943948a85621bb0238d26c2c1f3a7bf42404a6ff1487c7655909e')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"

  patch -Np1 < ../flask-babel-3.patch

  # Allow newer versions of the dependencies
  sed -i "s|==|>=|g" requirements.txt

  # Generate a random secret key
  # parabola does this in the .install hook (privacy concern)
}

package() {
  cd "$srcdir/$pkgname-$pkgver"
  local _site_packages="$(python -c 'import site; print(site.getsitepackages()[0])')"

  python setup.py install --root="$pkgdir" --optimize=1

  mv "${pkgdir}${_site_packages}"/{README.rst,requirements*,searx}

  mkdir -p "$pkgdir/etc/$pkgname"
  mv "${pkgdir}${_site_packages}/$pkgname/settings.yml" $pkgdir/etc/$pkgname/
  ln -s /etc/$pkgname/settings.yml "${pkgdir}${_site_packages}/$pkgname/settings.yml"

  install -Dm644 "${srcdir}/searx.sysusers" "${pkgdir}/usr/lib/sysusers.d/searx.conf"
  install -Dm644 "${srcdir}/searx.ini" "${pkgdir}/etc/uwsgi/searx.ini"
}
