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

124 lines
4.3 KiB
Text
Raw Normal View History

2014-09-23 12:04:43 +02:00
#!/bin/bash
2016-07-04 21:16:34 +02:00
#=================================================
2022-03-06 19:01:21 +01:00
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-07-04 21:16:34 +02:00
2020-04-15 20:29:35 +02:00
source _common.sh
2020-04-16 02:18:06 +02:00
source /usr/share/yunohost/helpers
2014-09-23 12:04:43 +02:00
2019-05-18 20:15:36 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2015-03-03 13:20:04 +01:00
2022-03-06 19:01:21 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2019-03-03 20:32:26 +01:00
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2019-05-18 20:15:36 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2014-07-21 23:53:27 +02:00
2022-03-09 20:30:52 +01:00
mkdir -p /var/log/uwsgi/$app
chown $app:root /var/log/uwsgi/$app
chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-05-18 20:15:36 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=3
2021-11-22 22:51:12 +01:00
# Create a temporary directory
2022-06-29 01:07:32 +02:00
tmpdir="$(mktemp -d)"
2021-11-22 22:51:12 +01:00
2022-06-29 01:07:32 +02:00
# Backup the config file in the temp dir
2023-08-18 11:38:35 +02:00
cp -a "$install_dir/searx/settings.yml" "$tmpdir/settings.yml"
2021-11-22 22:51:12 +01:00
2019-05-18 20:15:36 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2023-08-18 11:38:35 +02:00
ynh_setup_source --dest_dir="$install_dir"
2021-11-22 22:51:12 +01:00
2022-06-29 01:07:32 +02:00
# Copy the admin saved settings from tmp directory to final path
2023-08-18 11:38:35 +02:00
cp -a "$tmpdir/settings.yml" "$install_dir/searx/settings.yml"
2021-11-22 22:51:12 +01:00
2022-06-29 01:07:32 +02:00
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
2019-05-18 20:15:36 +02:00
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-12-19 23:34:40 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
2023-08-18 11:38:35 +02:00
path_no_root=${path%/}
2020-09-19 16:09:37 +02:00
# Create a dedicated NGINX config
2019-03-03 20:32:26 +01:00
ynh_add_nginx_config "path_no_root"
2014-07-21 23:53:27 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPGRADE SEARX IN ITS VIRTUALENV
#=================================================
2019-05-18 20:15:36 +02:00
ynh_script_progression --message="Upgrading Searx..." --weight=7
2020-09-19 20:39:58 +02:00
# Clean venv if it still on python2
if [ -e $install_dir/bin ] && [ ! -e $install_dir/bin/python3 ]
2020-09-19 20:39:58 +02:00
then
2023-08-18 11:38:35 +02:00
ynh_regex_secure_remove --file=$install_dir/lib/ --regex='python[^/.]*'
ynh_regex_secure_remove --file=$install_dir/lib64/ --regex='python[^/.]*'
ynh_regex_secure_remove --file=$install_dir/share/python-wheels
2020-09-19 20:39:58 +02:00
fi
2023-08-18 11:38:35 +02:00
ynh_regex_secure_remove --file=$install_dir/lib/python3/site-packages/setuptools
ynh_regex_secure_remove --file=$install_dir/lib/python3/site-packages/ --regex='setuptools-[^/.]*'
2020-09-19 20:39:58 +02:00
ynh_regex_secure_remove --file=$install_dir/venv/lib/python3/site-packages/setuptools
ynh_regex_secure_remove --file=$install_dir/venv/lib/python3/site-packages/ --regex='setuptools-[^/.]*'
2020-11-09 15:58:11 +01:00
pushd $install_dir
python3 -m venv venv
venv/bin/pip3 install -U pip setuptools wheel pyyaml --no-cache-dir
venv/bin/pip3 install --requirement $install_dir/requirements-ynh.txt --no-cache-dir
popd
2020-09-19 18:59:31 +02:00
2023-08-18 11:38:35 +02:00
chown -R $app: "$install_dir"
2022-03-06 19:01:21 +01:00
#=================================================
# CONFIGURE SEARX
#=================================================
2021-06-26 18:53:34 +02:00
# ynh_script_progression --message="Configuring Searx..." --weight=2
2021-06-26 18:53:34 +02:00
# secret_key=$(ynh_string_random)
2023-12-02 23:10:09 +01:00
# ynh_add_config --template="settings.yml" --destination="$install_dir/searx/settings.yml"
#=================================================
# CONFIGURE UWSGI FOR SEARX
#=================================================
2020-12-19 23:34:40 +01:00
ynh_script_progression --message="Reconfiguring uWSGI for Searx..." --weight=2
2020-04-10 22:02:55 +02:00
# Clean old files
ynh_secure_remove --file="/etc/uwsgi/apps-enabled/$app.ini"
ynh_secure_remove --file="/etc/uwsgi/apps-available/$app.ini"
ynh_add_uwsgi_service
2018-05-11 22:59:18 +02:00
#=================================================
2022-03-06 19:01:21 +01:00
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
2018-05-11 22:59:18 +02:00
#=================================================
2022-03-06 19:01:21 +01:00
ynh_script_progression --message="Starting a systemd service..." --weight=3
2018-05-11 22:59:18 +02:00
# Wait for searx to be fully started
ynh_systemd_action --service_name=uwsgi-app@$app.service --action=restart --line_match="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
2014-07-21 23:53:27 +02:00
2019-03-03 20:33:02 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2022-03-06 19:01:21 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last