1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/searx_ynh.git synced 2024-09-03 20:16:30 +02:00
searx_ynh/scripts/upgrade

93 lines
2.5 KiB
Text
Raw Normal View History

2014-09-23 12:04:43 +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-09-23 12:04:43 +02:00
2014-05-29 14:20:44 +02:00
# Retrieve arguments
2016-07-04 21:16:34 +02:00
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
# Remove trailing slash to path
path=${path%/}
#force location to be / or /foo
location=${path:-/}
2014-07-22 12:04:58 +02:00
2014-07-21 23:53:27 +02:00
# Check depends installation
2016-04-24 17:11:24 +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
2015-03-03 13:20:04 +01:00
2014-05-29 14:20:44 +02:00
# Check Swap
if [ $(sudo swapon -s | wc -l) = 1 ];
then
2015-03-03 13:20:04 +01:00
mount | grep /tmp | grep tmpfs > /dev/null 2>&1
if [ $? = 1 ];
then
tmp_swap_file=/tmp/searx_swapfile
else
tmp_swap_file=/var/cache/
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-07-21 23:53:27 +02:00
fi
2016-07-04 21:16:34 +02:00
final_path=/opt/yunohost/$app
2015-09-08 23:30:32 +02:00
sudo cp -r ../sources/* $final_path
sudo bash -c "source $final_path/bin/activate && pip install -r $final_path/requirements-ynh.txt --upgrade"
2014-05-29 14:20:44 +02:00
# Disable swapfile
2015-09-08 23:39:36 +02:00
if [[ -v "$tmp_swap_file" ]];
2014-05-29 14:20:44 +02:00
then
sudo swapoff $tmp_swap_file
sudo rm -f $tmp_swap_file
2014-07-21 23:53:27 +02:00
fi
#Configuration Searx
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:53:27 +02:00
if [ "$path" != "/" ];
then
sudo sed -i -e "s@ynhbaseurl@https://$domain$path/@g" $final_path/searx/settings.yml
2014-07-21 23:53:27 +02:00
else
2014-12-01 12:27:58 +01:00
sudo sed -i -e "s@ynhbaseurl@False@g" $final_path/searx/settings.yml
2014-07-21 23:53:27 +02:00
fi
# Set permissions to searx directory
if ! id -u searx > /dev/null 2>&1; then
sudo useradd searx -d $final_path
fi
sudo chown searx:searx -R $final_path
2014-07-21 23:53:27 +02:00
# Copy uwsgi config
2016-07-04 21:16:34 +02:00
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/$app.ini
2014-07-21 23:53:27 +02:00
# Modify Nginx configuration file and copy it to Nginx conf directory
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:53:27 +02:00
if [ "$path" != "/" ];
then
2016-07-04 21:16:34 +02:00
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/$app.conf
2014-07-21 23:53:27 +02:00
else
2016-07-04 21:16:34 +02:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2014-07-21 23:53:27 +02:00
fi
# Fix permission
#sudo find $final_path/ -type d -exec chmod 2755 {} \;
#sudo find $final_path/ -type f -exec chmod g+r,o+r {} \;
2014-07-21 23:53:27 +02:00
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting searx skipped_uris -d
sudo yunohost app setting searx unprotected_uris -v "/"
2014-07-21 23:53:27 +02:00
fi
2016-07-04 21:16:34 +02:00
## Reload services
sudo service nginx reload
sudo service uwsgi restart
2014-07-23 00:14:40 +02:00