2014-05-10 11:54:15 +02:00
|
|
|
#!/bin/bash
|
2016-07-04 21:16:34 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# GENERIC START
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-07-04 21:16:34 +02:00
|
|
|
|
2018-05-11 22:59:18 +02:00
|
|
|
source _common.sh
|
2017-05-01 15:47:20 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-03-03 20:32:26 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2017-08-28 03:03:36 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-05-01 15:47:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2016-07-04 21:16:34 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-05-01 15:47:20 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-07-04 21:16:34 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-07-05 12:25:15 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2020-12-19 23:34:40 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
final_path="/opt/yunohost/$app"
|
2019-05-18 20:15:36 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2017-08-28 03:03:36 +02:00
|
|
|
|
|
|
|
# Register (book) web path
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-08-28 03:03:36 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=2
|
2014-05-29 13:06:31 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-02-16 23:38:26 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=2
|
2014-07-21 23:26:57 +02:00
|
|
|
|
2019-04-13 00:38:47 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2014-09-23 12:20:00 +02:00
|
|
|
|
2021-03-21 23:13:21 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=3
|
|
|
|
|
|
|
|
# Create a system user
|
2021-06-26 12:02:15 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2021-03-21 23:13:21 +01:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=2
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2017-08-28 03:03:36 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app: "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
|
|
|
|
path_no_root=${path_url%/}
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config "path_no_root"
|
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# INSTALL SEARX IN A VIRTUALENV
|
|
|
|
#=================================================
|
2020-12-19 23:34:40 +01:00
|
|
|
ynh_script_progression --message="Installing Searx..." --weight=2
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2020-04-10 22:02:55 +02:00
|
|
|
python3 -m venv --system-site-packages "$final_path"
|
2018-06-29 19:21:14 +02:00
|
|
|
set +u; source $final_path/bin/activate; set -u
|
2021-06-26 12:50:24 +02:00
|
|
|
pip3 install -U pip setuptools wheel pyyaml --no-cache-dir
|
|
|
|
pip3 install --requirement $final_path/requirements-ynh.txt --no-cache-dir
|
2017-05-01 15:47:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE SEARX
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Configuring Searx..." --weight=2
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2021-05-03 18:31:05 +02:00
|
|
|
secret_key=$(ynh_string_random)
|
2021-07-20 21:00:24 +02:00
|
|
|
ynh_add_config --template="../conf/settings.yml" --destination="$final_path/searx/settings.yml"
|
2017-05-01 15:47:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SET PERMISSIONS ON SEARX DIRECTORY
|
|
|
|
#=================================================
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2021-02-16 23:38:26 +01:00
|
|
|
chown -R $app: $final_path
|
2014-05-10 11:54:15 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE UWSGI FOR SEARX
|
|
|
|
#=================================================
|
2020-12-19 23:34:40 +01:00
|
|
|
ynh_script_progression --message="Configuring uWSGI for Searx..." --weight=2
|
2014-05-27 12:13:54 +02:00
|
|
|
|
2021-07-20 21:00:24 +02:00
|
|
|
ynh_add_uwsgi_service
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2018-05-11 22:59:18 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# GENERIC FINALIZATION
|
2018-05-11 22:59:18 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=4
|
2018-05-11 22:59:18 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
# Start a systemd service
|
2021-06-26 12:33:40 +02:00
|
|
|
ynh_systemd_action --service_name=uwsgi-app@$app.service --action=start --line_match="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
|
2018-05-11 22:59:18 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-02-16 23:38:26 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=2
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
# Make app public if necessary
|
2017-05-01 15:47:20 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
2014-05-27 12:13:54 +02:00
|
|
|
then
|
2021-02-16 23:38:26 +01:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2014-05-27 12:13:54 +02:00
|
|
|
fi
|
2014-12-04 21:43:45 +01:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-12-19 23:34:40 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-03-03 20:33:02 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|