2014-05-10 11:54:15 +02:00
|
|
|
#!/bin/bash
|
2016-07-04 21:16:34 +02:00
|
|
|
app="searx"
|
|
|
|
|
|
|
|
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Source app helpers
|
|
|
|
. /usr/share/yunohost/helpers
|
2014-05-10 11:54:15 +02:00
|
|
|
|
|
|
|
# Retrieve arguments
|
2016-07-04 21:16:34 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2016-07-05 12:25:15 +02:00
|
|
|
# Force path to start with a /
|
|
|
|
if [ "${path:0:1}" != "/" ]; then
|
|
|
|
path="/$path"
|
|
|
|
fi
|
|
|
|
|
2016-07-04 21:16:34 +02:00
|
|
|
# Remove trailing slash to path
|
|
|
|
path=${path%/}
|
|
|
|
#force location to be / or /foo
|
|
|
|
location=${path:-/}
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2016-07-04 21:16:34 +02:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a $app \
|
|
|
|
|| (echo "Path not available: $domain$path" && exit 1)
|
2016-04-24 18:05:52 +02:00
|
|
|
|
2014-07-22 12:22:20 +02:00
|
|
|
# Save specific settings
|
2014-05-29 13:06:31 +02:00
|
|
|
sudo yunohost app setting searx is_public -v $is_public
|
|
|
|
|
2014-05-10 11:54:15 +02:00
|
|
|
# Check depends installation
|
2016-04-24 17:08:48 +02:00
|
|
|
sudo apt-get install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev libffi-dev libssl-dev python-lxml uwsgi uwsgi-plugin-python -y
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2014-05-12 21:44:08 +02:00
|
|
|
# Check Swap
|
2014-05-16 21:25:52 +02:00
|
|
|
if [ $(sudo swapon -s | wc -l) = 1 ];
|
2014-05-12 21:44:08 +02:00
|
|
|
then
|
2016-07-05 12:26:52 +02:00
|
|
|
# It is NOT possible to setup a swap file on a tmpfs filesystem
|
|
|
|
mount | grep /tmp | grep tmpfs > /dev/null 2>&1
|
|
|
|
if [ $? = 1 ];
|
|
|
|
then
|
|
|
|
tmp_swap_file=/tmp/searx_swapfile
|
|
|
|
else
|
|
|
|
tmp_swap_file=/var/cache/searx_swapfile
|
|
|
|
fi
|
|
|
|
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
|
2014-05-12 21:44:08 +02:00
|
|
|
fi
|
2014-07-21 23:26:57 +02:00
|
|
|
|
2016-07-04 21:16:34 +02:00
|
|
|
final_path=/opt/yunohost/$app
|
2014-09-23 12:20:00 +02:00
|
|
|
|
2014-05-10 11:54:15 +02:00
|
|
|
# Init virtualenv
|
2014-09-23 12:20:00 +02:00
|
|
|
if [ ! -d $final_path ];
|
2014-05-10 11:58:58 +02:00
|
|
|
then
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo mkdir -p $final_path
|
2014-05-10 11:58:58 +02:00
|
|
|
fi
|
2014-09-23 12:20:00 +02:00
|
|
|
sudo cp -r ../sources/* $final_path
|
2015-09-10 21:51:14 +02:00
|
|
|
sudo virtualenv --system-site-packages $final_path
|
2016-04-27 09:13:35 +02:00
|
|
|
sudo bash -c "source $final_path/bin/activate && pip install -r $final_path/requirements-ynh.txt"
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2014-05-12 21:44:08 +02:00
|
|
|
# Disable swapfile
|
2015-09-08 23:39:36 +02:00
|
|
|
if [[ -v "$tmp_swap_file" ]];
|
2014-05-12 21:44:08 +02:00
|
|
|
then
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo swapoff $tmp_swap_file
|
|
|
|
sudo rm -f $tmp_swap_file
|
2014-05-12 21:44:08 +02:00
|
|
|
fi
|
|
|
|
|
2014-05-10 11:54:15 +02:00
|
|
|
#Configuration Searx
|
2014-09-23 12:20:00 +02:00
|
|
|
sudo cp ../conf/settings.yml $final_path/searx/
|
|
|
|
sudo sed -i -e "s/ultrasecretkey/`openssl rand -hex 16`/g" $final_path/searx/settings.yml
|
2014-07-21 23:42:32 +02:00
|
|
|
if [ "$path" != "/" ];
|
2014-05-27 12:13:54 +02:00
|
|
|
then
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo sed -i -e "s@ynhbaseurl@https://$domain$path/@g" $final_path/searx/settings.yml
|
2014-07-21 23:42:32 +02:00
|
|
|
else
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo sed -i -e "s@ynhbaseurl@False@g" $final_path/searx/settings.yml
|
2014-07-21 23:42:32 +02:00
|
|
|
fi
|
2014-05-10 11:54:15 +02:00
|
|
|
|
|
|
|
# Set permissions to searx directory
|
2014-09-23 12:20:00 +02:00
|
|
|
sudo useradd searx -d $final_path
|
|
|
|
sudo chown searx:searx -R $final_path
|
2014-05-10 11:54:15 +02:00
|
|
|
|
|
|
|
# Copy uwsgi config
|
2016-07-04 21:16:34 +02:00
|
|
|
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/$app.ini
|
|
|
|
sudo ln -s /etc/uwsgi/apps-available/searx.ini /etc/uwsgi/apps-enabled/$app.ini
|
2014-05-10 11:54:15 +02:00
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2016-04-24 18:05:52 +02:00
|
|
|
sed -i "s@YNH_WWW_LOCATION@$location@g" ../conf/nginx.conf*
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf*
|
2014-07-21 23:26:57 +02:00
|
|
|
if [ "$path" != "/" ];
|
2014-05-27 12:04:01 +02:00
|
|
|
then
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/$app.conf
|
2014-05-27 12:04:01 +02:00
|
|
|
else
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2014-05-27 12:04:01 +02:00
|
|
|
fi
|
2014-05-10 11:54:15 +02:00
|
|
|
|
|
|
|
# Fix permission
|
2014-09-23 12:20:00 +02:00
|
|
|
#sudo find $final_path/ -type d -exec chmod 2755 {} \;
|
|
|
|
#sudo find $final_path/ -type f -exec chmod g+r,o+r {} \;
|
2014-05-10 11:54:15 +02:00
|
|
|
|
|
|
|
## Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo service uwsgi restart
|
2016-07-04 21:16:34 +02:00
|
|
|
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/$app.log
|
2014-05-27 12:13:54 +02:00
|
|
|
|
2014-07-21 23:26:57 +02:00
|
|
|
if [ "$is_public" = "Yes" ];
|
2014-05-27 12:13:54 +02:00
|
|
|
then
|
2016-07-05 12:26:52 +02:00
|
|
|
sudo yunohost app setting $app unprotected_uris -v "/"
|
2014-05-27 12:13:54 +02:00
|
|
|
fi
|
2014-12-04 21:43:45 +01:00
|
|
|
|