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

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-31 02:59:20 +02:00 committed by Alexandre Aubin
parent fbbef0aefe
commit e3d830d27b
9 changed files with 91 additions and 149 deletions

View file

@ -4,7 +4,7 @@ location __PATH__/ {
uwsgi_param SCRIPT_NAME '__PATH_NO_ROOT__';
include uwsgi_params;
uwsgi_modifier1 30;
uwsgi_pass unix:///var/run/__NAME__/app.socket;
uwsgi_pass unix:///var/run/__APP__/app.socket;
#location __PATH__/searx/static/ {
# alias __INSTALL_DIR__/searx/static/;

View file

@ -20,7 +20,8 @@ admindoc = "https://github.com/searx/searx/wiki"
code = "https://github.com/searx/searx"
[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = false
@ -57,6 +58,7 @@ ram.runtime = "50M"
[resources.system_user]
[resources.install_dir]
group = "www-data:r-x"
[resources.permissions]
main.url = "/"

View file

@ -1,20 +1,16 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
#=================================================
# PERSONAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
_searx_venv_install() {
ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv"
ynh_exec_as_app python3 -m venv --upgrade "$install_dir/venv"
venvpy="$install_dir/venv/bin/python3"
ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip
ynh_exec_as_app "$venvpy" -m pip install --upgrade --no-cache-dir pip
ynh_exec_as "$app" "$venvpy" -m pip install setuptools wheel pyyaml
ynh_exec_as_app "$venvpy" -m pip install setuptools wheel pyyaml
}
#=================================================
@ -25,7 +21,7 @@ _searx_venv_install() {
#
# usage: ynh_check_global_uwsgi_config
ynh_check_global_uwsgi_config () {
uwsgi --version || ynh_die --message "You need to add uwsgi (and appropriate plugin) as a dependency"
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"
cat > /etc/systemd/system/uwsgi-app@.service <<EOF
[Unit]
@ -81,7 +77,7 @@ ynh_add_uwsgi_service () {
local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
# www-data group is needed since it is this nginx who will start the service
usermod --append --groups www-data "$app" || ynh_die --message "It wasn't possible to add user $app to group www-data"
usermod --append --groups www-data "$app" || ynh_die "It wasn't possible to add user $app to group www-data"
ynh_backup_if_checksum_is_different "$finaluwsgiini"
cp ../conf/uwsgi.ini "$finaluwsgiini"
@ -89,13 +85,13 @@ ynh_add_uwsgi_service () {
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if test -n "${install_dir:-}"; then
ynh_replace_string --match_string "__INSTALL_DIR__" --replace_string "$install_dir" --target_file "$finaluwsgiini"
ynh_replace --match "__INSTALL_DIR__" --replace "$install_dir" --file "$finaluwsgiini"
fi
if test -n "${path:-}"; then
ynh_replace_string --match_string "__PATH__" --replace_string "$path" --target_file "$finaluwsgiini"
ynh_replace --match "__PATH__" --replace "$path" --file "$finaluwsgiini"
fi
if test -n "${app:-}"; then
ynh_replace_string --match_string "__APP__" --replace_string "$app" --target_file "$finaluwsgiini"
ynh_replace --match "__APP__" --replace "$app" --file "$finaluwsgiini"
fi
# Replace all other variable given as arguments
@ -103,10 +99,10 @@ ynh_add_uwsgi_service () {
do
# ${var_to_replace^^} make the content of the variable on upper-cases
# ${!var_to_replace} get the content of the variable named $var_to_replace
ynh_replace_string --match_string "__${var_to_replace^^}__" --replace_string "${!var_to_replace}" --target_file "$finaluwsgiini"
ynh_replace --match "__${var_to_replace^^}__" --replace "${!var_to_replace}" --file "$finaluwsgiini"
done
ynh_store_file_checksum --file "$finaluwsgiini"
ynh_store_file_checksum "$finaluwsgiini"
chown $app:root "$finaluwsgiini"
@ -136,24 +132,23 @@ ynh_remove_uwsgi_service () {
yunohost service remove "uwsgi-app@$app"
systemctl disable "uwsgi-app@$app.service" --quiet
ynh_secure_remove --file="$finaluwsgiini"
ynh_secure_remove --file="/var/log/uwsgi/$app"
ynh_secure_remove --file="/etc/systemd/system/uwsgi-app@$app.service.d"
ynh_safe_rm "$finaluwsgiini"
ynh_safe_rm "/var/log/uwsgi/$app"
ynh_safe_rm "/etc/systemd/system/uwsgi-app@$app.service.d"
fi
if [ -e /etc/init.d/uwsgi ]
then
# Redémarre le service uwsgi si il n'est pas désinstallé.
ynh_systemd_action --service_name=uwsgi --action=start
ynh_systemctl --service=uwsgi --action=start
else
if yunohost service status | grep -q uwsgi
then
ynh_print_info --message="Remove uwsgi service"
ynh_print_info "Remove uwsgi service"
yunohost service remove uwsgi
fi
fi
}
#=================================================
# Remove a file or a directory securely
@ -167,7 +162,7 @@ ynh_remove_uwsgi_service () {
# Requires YunoHost version 2.6.4 or higher.
ynh_regex_secure_remove () {
# Declare an array to define the options of this helper.
local legacy_args=frnd
#REMOVEME? local legacy_args=frnd
declare -Ar args_array=( [f]=file= [r]=regex= [n]=non_recursive [d]=dry_run )
local file
local regex
@ -186,7 +181,7 @@ ynh_regex_secure_remove () {
# Fail if no argument is provided to the helper.
if [ -z "$file" ]
then
ynh_print_warn --message="ynh_regex_secure_remove called with no argument --file, ignoring."
ynh_print_warn "ynh_regex_secure_remove called with no argument --file, ignoring."
return 0
fi
@ -202,7 +197,7 @@ ynh_regex_secure_remove () {
# Use find to list the files in $file and grep to filter with the regex
files_to_remove="$(find -P "$file" $recursive -name ".." -prune -o -print | grep --extended-regexp "$regex")"
else
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
ynh_print_info "'$file' wasn't deleted because it doesn't exist."
return 0
fi
else
@ -222,14 +217,14 @@ ynh_regex_secure_remove () {
# Match if the path finishes by /. Because it seems there is an empty variable
[ "${file_to_remove:${#file_to_remove}-1}" = "/" ]
then
ynh_print_err --message="Not deleting '$file_to_remove' because this path is forbidden !!!"
ynh_print_warn "Not deleting '$file_to_remove' because this path is forbidden !!!"
# If the file to remove exists
elif [ -e "$file_to_remove" ]
then
if [ $dry_run -eq 1 ]
then
ynh_print_warn --message="File to remove: $file_to_remove"
ynh_print_warn "File to remove: $file_to_remove"
else
if [ $non_recursive -eq 1 ]; then
local recursive=""
@ -244,7 +239,7 @@ ynh_regex_secure_remove () {
# Ignore non existent files with regex, as we likely remove the parent directory before its content is listed.
if [ -z "$regex" ]
then
ynh_print_info --message="'$file_to_remove' wasn't deleted because it doesn't exist."
ynh_print_info "'$file_to_remove' wasn't deleted because it doesn't exist."
fi
fi
fi

View file

@ -1,31 +1,22 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
@ -33,10 +24,10 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini"
ynh_backup "/etc/uwsgi/apps-available/$app.ini"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,53 +1,43 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=10
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=uwsgi --action=stop
ynh_systemctl --service=uwsgi --action=stop
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2
ynh_script_progression "Updating NGINX web server configuration..."
path_no_root=${path%/}
# Create a dedicated NGINX config
ynh_change_url_nginx_config
ynh_config_change_url_nginx
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# RECONFIGURING SEARX
#=================================================
ynh_script_progression --message="Reconfiguring Searx..." --weight=2
ynh_script_progression "Reconfiguring Searx..."
#ynh_replace_string --match_string="base_url : https://${old_domain}${old_path%/}/" --replace_string="base_url : https://${new_domain}${new_path%/}/" --target_file="$install_dir/searx/settings.yml"
#ynh_replace --match="base_url : https://${old_domain}${old_path%/}/" --replace="base_url : https://${new_domain}${new_path%/}/" --file="$install_dir/searx/settings.yml"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
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"
ynh_systemctl --service=uwsgi-app@$app.service --action=restart --wait_until="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"

View file

@ -1,80 +1,70 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/source"
chmod -R o-rwx "$install_dir"
chown -R "$app:" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:" "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
ynh_script_progression "Configuring NGINX web server..."
path_no_root=${path%/}
# Create a dedicated NGINX config
ynh_add_nginx_config "path_no_root"
ynh_config_add_nginx "path_no_root"
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL SEARX IN A VIRTUALENV
#=================================================
ynh_script_progression --message="Installing Searx..." --weight=2
ynh_script_progression "Installing Searx..."
_searx_venv_install
ynh_add_config --template="requirements-ynh.txt" --destination="$install_dir/requirements-ynh.txt"
ynh_config_add --template="requirements-ynh.txt" --destination="$install_dir/requirements-ynh.txt"
ynh_exec_as "$app" "$venvpy" -m pip install --requirement "$install_dir/requirements-ynh.txt" --no-cache-dir
ynh_exec_as_app "$venvpy" -m pip install --requirement "$install_dir/requirements-ynh.txt" --no-cache-dir
#=================================================
# CONFIGURE SEARX
#=================================================
ynh_script_progression --message="Configuring Searx..." --weight=2
ynh_script_progression "Configuring Searx..."
secret_key=$(ynh_string_random)
ynh_add_config --template="settings.yml" --destination="$install_dir/source/searx/settings.yml"
ynh_config_add --template="settings.yml" --destination="$install_dir/source/searx/settings.yml"
#=================================================
# SET PERMISSIONS ON SEARX DIRECTORY
#=================================================
chown -R "$app:" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:" "$install_dir"
#=================================================
# CONFIGURE UWSGI FOR SEARX
#=================================================
ynh_script_progression --message="Configuring uWSGI for Searx..." --weight=2
ynh_script_progression "Configuring uWSGI for Searx..."
ynh_add_uwsgi_service
#=================================================
# GENERIC FINALIZATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=4
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
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"
ynh_systemctl --service="uwsgi-app@$app.service" --action=start --wait_until="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -14,17 +8,17 @@ source /usr/share/yunohost/helpers
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2
ynh_script_progression "Stopping and removing the systemd service..."
# Remove the uwsgi configuration
ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop
ynh_systemctl --service "uwsgi-app@$app.service" --action stop
ynh_remove_uwsgi_service
# Remove the dedicated NGINX config
ynh_remove_nginx_config
ynh_config_remove_nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
@ -13,26 +7,25 @@ source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2
ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app: "$install_dir"
ynh_restore "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app: "$install_dir"
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_script_progression "Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_script_progression "Restoring various files..."
ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini"
ynh_restore "/etc/uwsgi/apps-available/$app.ini"
mkdir -p /var/log/uwsgi/$app
chown $app:root /var/log/uwsgi/$app
chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app
@ -42,14 +35,14 @@ systemctl enable "uwsgi-app@$app.service" --quiet
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=4
ynh_script_progression "Starting $app's systemd service..."
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"
ynh_systemctl --service=uwsgi-app@$app.service --action=start --wait_until="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -1,95 +1,82 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
ynh_script_progression "Ensuring downward compatibility..."
if [ -f "$install_dir/setup.py" ]; then
# Clean up the whole install_dir except settings.yml
tmpdir="$(mktemp -d)"
cp "$install_dir/searx/settings.yml" "$tmpdir"
ynh_secure_remove "$install_dir"
ynh_safe_rm "$install_dir"
mkdir -p "$install_dir"
chmod 750 "$install_dir"
chown "$app:" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:" "$install_dir"
mkdir -p "$install_dir/source/searx"
cp "$tmpdir/settings.yml" "$install_dir/source/searx"
ynh_secure_remove --file="$tmpdir"
ynh_safe_rm "$tmpdir"
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=3
ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/source" --full_replace=1 --keep="searx/settings.yml"
ynh_setup_source --dest_dir="$install_dir/source" --full_replace --keep="searx/settings.yml"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_script_progression "Upgrading system configurations related to $app..."
path_no_root=${path%/}
# Create a dedicated NGINX config
ynh_add_nginx_config "path_no_root"
ynh_config_add_nginx "path_no_root"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPGRADE SEARX IN ITS VIRTUALENV
#=================================================
ynh_script_progression --message="Upgrading Searx..." --weight=7
ynh_script_progression "Upgrading Searx..."
_searx_venv_install
ynh_add_config --template="requirements-ynh.txt" --destination="$install_dir/requirements-ynh.txt"
ynh_config_add --template="requirements-ynh.txt" --destination="$install_dir/requirements-ynh.txt"
ynh_exec_as "$app" "$venvpy" -m pip install --requirement "$install_dir/requirements-ynh.txt" --no-cache-dir
ynh_exec_as_app "$venvpy" -m pip install --requirement "$install_dir/requirements-ynh.txt" --no-cache-dir
#=================================================
# CONFIGURE SEARX
#=================================================
# ynh_script_progression --message="Configuring Searx..." --weight=2
# ynh_script_progression "Configuring Searx..."
# secret_key=$(ynh_string_random)
# ynh_add_config --template="settings.yml" --destination="$install_dir/source/searx/settings.yml"
# ynh_config_add --template="settings.yml" --destination="$install_dir/source/searx/settings.yml"
#=================================================
# CONFIGURE UWSGI FOR SEARX
#=================================================
ynh_script_progression --message="Reconfiguring uWSGI for Searx..." --weight=2
ynh_script_progression "Reconfiguring uWSGI for Searx..."
# Clean old files
ynh_secure_remove --file="/etc/uwsgi/apps-enabled/$app.ini"
ynh_secure_remove --file="/etc/uwsgi/apps-available/$app.ini"
ynh_safe_rm "/etc/uwsgi/apps-enabled/$app.ini"
ynh_safe_rm "/etc/uwsgi/apps-available/$app.ini"
ynh_add_uwsgi_service
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_script_progression "Starting $app's systemd service..."
# 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"
ynh_systemctl --service="uwsgi-app@$app.service" --action=restart --wait_until="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"