#!/bin/sh

set -ex

rm /etc/apache2/sites-enabled/000-default.conf
cp /usr/share/doc/searx/examples/apache2/sites-available/searx.conf /etc/apache2/sites-available/
ln -s ../sites-available/searx.conf /etc/apache2/sites-enabled/searx.conf
a2enmod proxy
a2enmod proxy_uwsgi
a2enmod uwsgi

cp /usr/share/doc/searx/examples/uwsgi/apps-available/searx.ini /etc/uwsgi/apps-available
ln -s ../apps-available/searx.ini /etc/uwsgi/apps-enabled/searx.ini
mkdir /etc/searx
cp /usr/share/doc/searx/examples/settings.yml /etc/searx/settings.yml
sed -i -e "s/ultrasecretkey/$(openssl rand -hex 16)/g" /etc/searx/settings.yml
systemctl restart apache2
systemctl restart uwsgi
sleep 5
systemctl status apache2
systemctl status uwsgi
cat /var/log/uwsgi/app/searx.log
curl http://localhost/searx/
curl http://localhost/searx/ | grep '<input type="search".* name="q"'
