From 17648dc8db580f8d8cf99cd7a11ece93cf376a88 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sun, 21 Jul 2024 09:59:03 +0200 Subject: [PATCH] Refractor --- ALL_README.md | 1 - scripts/_common.sh | 56 ++++++++++++++++++++-------------------------- scripts/install | 4 ++++ scripts/upgrade | 1 + 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/ALL_README.md b/ALL_README.md index 4ed64dd..152f2e7 100644 --- a/ALL_README.md +++ b/ALL_README.md @@ -5,5 +5,4 @@ - [Irakurri README euskaraz](README_eu.md) - [Lire le README en français](README_fr.md) - [Le o README en galego](README_gl.md) -- [Baca README dalam bahasa bahasa Indonesia](README_id.md) - [阅读中文(简体)的 README](README_zh_Hans.md) diff --git a/scripts/_common.sh b/scripts/_common.sh index 3f7b0d4..20edd0d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,46 +9,38 @@ #================================================= # Install/Upgrade SearXNG in virtual environement -myynh_install_searxng () { - - ynh_script_progression --message="Setting up source files..." --weight=1 - - # Download source +myynh_source_searxng () { + # Retrieve info from manifest repo_fullpath=$(ynh_read_manifest --manifest_key="upstream.code") commit_sha=$(ynh_read_manifest --manifest_key="resources.sources.main.url" | xargs basename --suffix=".tar.gz") - ynh_exec_as $app git clone -n "$repo_fullpath" "$install_dir/searxng-src" + + # Download source + ynh_exec_as $app ynh_exec_fully_quiet git clone -n "$repo_fullpath" "$install_dir/searxng-src" pushd "$install_dir/searxng-src" - ynh_exec_as $app git checkout "$commit_sha" + ynh_exec_as $app ynh_exec_fully_quiet git checkout "$commit_sha" popd +} +myynh_install_searxng () { # Create the virtual environment - ynh_exec_as $app python3 -m venv "$install_dir/searxng-pyenv" + sudo -i -u $app bash << EOF +python3 -m venv "$install_dir/searxng-pyenv" +echo ". $install_dir/searxng-pyenv/bin/activate" >> "$install_dir/.profile" +EOF - # Source the virtual environment in the user profile - ynh_exec_as $app echo ". $install_dir/searxng-pyenv/bin/activate" >> "$install_dir/.profile" + # Check if virtualenv was sourced from the login + sudo -i -u $app bash << EOF +command -v python && python --version +EOF - ynh_script_progression --message="Installing SearXNG..." --weight=2 - # Install SearXNG in a 'sub shell' - ( - # Check if virtualenv was sourced from the login - ynh_exec_as $app echo $(command -v python && python --version) - - # Install last version of pip - ynh_exec_warn_less ynh_exec_as $app pip install --upgrade pip - - # Install last version of setuptools - ynh_exec_warn_less ynh_exec_as $app pip install --upgrade setuptools - - # Install last version of wheel - ynh_exec_warn_less ynh_exec_as $app pip install --upgrade wheel - - # Install last version of pyyaml - ynh_exec_warn_less ynh_exec_as $app pip install --upgrade pyyaml - - # Install SearXNG - cd "$install_dir/searxng-src" - pip install -e . - ) + sudo -i -u $app bash << EOF +pip install --upgrade pip +pip install --upgrade setuptools +pip install --upgrade wheel +pip install --upgrade pyyaml +cd "$install_dir/searxng-src" +pip install -e . +EOF } # Upgrade the virtual environment directory diff --git a/scripts/install b/scripts/install index 072cdf3..fa616c5 100755 --- a/scripts/install +++ b/scripts/install @@ -14,6 +14,10 @@ source /usr/share/yunohost/helpers #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --weight=1 +myynh_source_searxng + +ynh_script_progression --message="Installing SearXNG..." --weight=2 myynh_install_searxng #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index da070c0..33bb372 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -47,6 +47,7 @@ ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="stop" --log if [ "$upgrade_type" == "UPGRADE_APP" ] then myynh_upgrade_venv_directory + myynh_source_searxng myynh_install_searxng fi