searx_ynh/scripts/install

86 lines
2.3 KiB
Bash

#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
is_public=$3
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a searx
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Save specific settings
sudo yunohost app setting searx is_public -v $is_public
# Check depends installation
sudo apt-get install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python -y
# Check Swap
tmp_swap_file=/tmp/searx_swapfile
if [ $(sudo swapon -s | wc -l) = 1 ];
then
sudo dd if=/dev/zero of=$tmp_swap_file bs=1M count=256
sudo chmod 600 $tmp_swap_file
sudo mkswap $tmp_swap_file
sudo swapon $tmp_swap_file
fi
# Init virtualenv
if [ ! -d /opt/yunohost/searx ];
then
sudo mkdir -p /opt/yunohost/searx
fi
sudo cp -r ../sources/* /opt/yunohost/searx
sudo virtualenv /opt/yunohost/searx
sudo bash -c "source /opt/yunohost/searx/bin/activate && pip install -r /opt/yunohost/searx/requirements.txt"
# Disable swapfile
if [ -f $tmp_swap_file ];
then
sudo swapoff $tmp_swap_file
sudo rm -f $tmp_swap_file
fi
#Configuration Searx
sudo cp ../conf/settings.yml /opt/searx/searx/
sudo sed -i -e "s/ultrasecretkey/`openssl rand -hex 16`/g" /opt/searx/searx/settings.yml
if [ "$path" != "/" ];
then
sudo sed -i -e "s@ynhbaseurl@https://$domain$path/@g" /opt/searx/searx/settings.yml
else
sudo sed -i -e "s@ynhbaseurl@https://$domain$path@g" /opt/searx/searx/settings.yml
fi
# Set permissions to searx directory
sudo useradd searx -d /opt/yunohost/searx
sudo chown searx:searx -R /opt/yunohost/searx
# Copy uwsgi config
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/
sudo ln -s /etc/uwsgi/apps-available/searx.ini /etc/uwsgi/apps-enabled/
# Modify Nginx configuration file and copy it to Nginx conf directory
sudo sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf*
if [ "$path" != "/" ];
then
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/searx.conf
else
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/searx.conf
fi
# Fix permission
#sudo find /opt/yunohost/searx/ -type d -exec chmod 2755 {} \;
#sudo find /opt/yunohost/searx/ -type f -exec chmod g+r,o+r {} \;
## Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service uwsgi restart
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting searx skipped_uris -v "/"
fi
sudo yunohost app ssowatconf