From 713f70ec5bb643d99385bc97a0a265433c5fe35e Mon Sep 17 00:00:00 2001 From: Thomas <51749973+Thovi98@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:57:54 +0100 Subject: [PATCH] try to simplify things --- scripts/install | 64 +++++++++++++++++----------------------- scripts/restore | 4 +-- scripts/upgrade | 78 ++++++++++++++++++++++--------------------------- 3 files changed, 64 insertions(+), 82 deletions(-) diff --git a/scripts/install b/scripts/install index ae5bc85..bd0d1f7 100755 --- a/scripts/install +++ b/scripts/install @@ -89,38 +89,34 @@ fi #================================================= # PIP INSTALLATION #================================================= -ynh_script_progression --message="Install weblate using PIP..." --weight=80 +ynh_script_progression --message="Install weblate using PIP..." --weight=5 -virtualenv --python=python3 "${install_dir}/venv" -chown -R $app: "$install_dir" +pushd $install_dir + python3 -m venv $install_dir/venv + source $install_dir/venv/bin/activate + ynh_exec_warn_less pip install --upgrade pip setuptools wheel pkgconfig xxhash -#run source in a 'sub shell' -( - set +o nounset - source "${install_dir}/venv/bin/activate" - set -o nounset - cd "${install_dir}" + # Read the "Note" section in https://docs.weblate.org/en/weblate-5.3/admin/install/venv-debian.html#python-modules + ynh_exec_warn_less pip install install --force-reinstall --no-binary :all: cffi - sudo --user=$app $install_dir/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash + ynh_exec_warn_less pip install Weblate=="$(ynh_app_upstream_version)" + + ynh_exec_warn_less pip install psycopg2-binary ruamel.yaml aeidon phply - # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules - sudo --user=$app $install_dir/venv/bin/pip install --force-reinstall --no-binary :all: cffi - # Still needed with latest version of weblate? - sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $install_dir/venv/bin/pip install Weblate=="$(ynh_app_upstream_version)" - sudo --user=$app $install_dir/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply - #pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml - # specific to YunoHost package: - sudo --user=$app $install_dir/venv/bin/pip install django_sendmail_backend -) + ynh_exec_warn_less pip install django_sendmail_backend + +popd #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 +# Configure redis redis_db=$(ynh_redis_get_free_db) -ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" +ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" + path="${path%/}" settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" @@ -146,26 +142,20 @@ chown -R "$app:www-data" "$install_dir/data" #========================================== ynh_script_progression --message="Filling up the database..." --weight=10 -( - set +o nounset - source "${install_dir}/venv/bin/activate" - set -o nounset - export DJANGO_SETTINGS_MODULE="weblate.settings" - cd "${install_dir}" +export DJANGO_SETTINGS_MODULE="weblate.settings" - # the user needs to be weblate for postgresql - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput - # generate static files - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate createadmin --no-color \ +ynh_exec_warn_less $install_dir/venv/bin/weblate migrate --noinput + +ynh_exec_warn_less $install_dir/venv/bin/weblate collectstatic --noinput + +ynh_exec_warn_less $install_dir/venv/bin/weblate createadmin --no-color \ --password "$password" \ --username "$admin" \ --email "$admin_mail" - # Check the configuration - # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true -) +# Check the configuration +# This may fail in some cases with errors, etc., but the app works and the user can fix issues later. +ynh_exec_warn_less $install_dir/venv/bin/weblate check --deploy || true #================================================= # SETUP SYSTEMD @@ -191,7 +181,7 @@ ynh_use_logrotate --non-append ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 yunohost service add $app --log="/var/log/$app/weblate.log" -yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" +yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery.log" #================================================= # START SYSTEMD SERVICE @@ -199,7 +189,7 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" ynh_script_progression --message="Starting a systemd service..." --weight=5 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" -ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery.log" --line_match="mingle: all alone" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 1d3f6b7..bf8586d 100755 --- a/scripts/restore +++ b/scripts/restore @@ -85,7 +85,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 yunohost service add $app --log="/var/log/$app/weblate.log" -yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" +yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery.log" #================================================= # START SYSTEMD SERVICE @@ -93,7 +93,7 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" ynh_script_progression --message="Starting a systemd service..." --weight=5 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" -ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery.log" --line_match="mingle: all alone" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 2c0b395..a839640 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -110,33 +110,27 @@ ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.servic upgrade() { new_version=$1 settings_template=$2 - #================================================= - # PIP INSTALLATION - #================================================= - ynh_script_progression --message="Install weblate using PIP..." --weight=15 +#================================================= +# PIP INSTALLATION +#================================================= +ynh_script_progression --message="Install weblate using PIP..." --weight=5 - ynh_secure_remove --file="${install_dir}/venv" - virtualenv --python=python3 "${install_dir}/venv" - chown -R $app: "$install_dir" +pushd $install_dir + python3 -m venv $install_dir/venv + source $install_dir/venv/bin/activate + ynh_exec_warn_less pip install --upgrade pip setuptools wheel pkgconfig xxhash - #run source in a 'sub shell' - ( - set +o nounset - source "${install_dir}/venv/bin/activate" - set -o nounset - cd "${install_dir}" + # Read the "Note" section in https://docs.weblate.org/en/weblate-5.3/admin/install/venv-debian.html#python-modules + ynh_exec_warn_less pip install install --force-reinstall --no-binary :all: cffi - sudo --user=$app $install_dir/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash + ynh_exec_warn_less pip install Weblate=="$(ynh_app_upstream_version)" - # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules - sudo --user=$app $install_dir/venv/bin/pip install --force-reinstall --no-binary :all: cffi - # Still needed with latest version of weblate? - sudo --user=$app $install_dir/venv/bin/pip install --upgrade Weblate=="$new_version" - sudo --user=$app $install_dir/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply - #pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml - # specific to YunoHost package: - sudo --user=$app $install_dir/venv/bin/pip install django_sendmail_backend - ) + ynh_exec_warn_less pip install psycopg2-binary ruamel.yaml aeidon phply + + # specific to YunoHost package: + ynh_exec_warn_less pip install django_sendmail_backend + +popd #================================================= # MODIFY A CONFIG FILE @@ -165,25 +159,23 @@ upgrade() { ynh_systemd_action --service_name="$app-celery" --action="start" - ( - set +o nounset - source "${install_dir}/venv/bin/activate" - set -o nounset - export DJANGO_SETTINGS_MODULE="weblate.settings" - cd "${install_dir}" + export DJANGO_SETTINGS_MODULE="weblate.settings" - sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput - sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput - sudo --user=$app $install_dir/venv/bin/weblate setuplang - sudo --user=$app $install_dir/venv/bin/weblate setupgroups - sudo --user=$app $install_dir/venv/bin/weblate compilemessages - - # Check the configuration - # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. - if [ "$new_version" == "$(ynh_app_upstream_version)" ]; then - sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true - fi - ) + ynh_exec_warn_less $install_dir/venv/bin/weblate migrate --noinput + + ynh_exec_warn_less $install_dir/venv/bin/weblate collectstatic --noinput + + ynh_exec_warn_less $install_dir/venv/bin/weblate setuplang + + ynh_exec_warn_less $install_dir/venv/bin/weblate setupgroups + + ynh_exec_warn_less $install_dir/venv/bin/weblate compilemessages + + # Check the configuration + # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. + if [ "$new_version" == "$(ynh_app_upstream_version)" ]; then + ynh_exec_warn_less $install_dir/venv/bin/weblate check --deploy || true + fi ynh_systemd_action --service_name="$app-celery" --action="stop" } @@ -230,7 +222,7 @@ ynh_use_logrotate --non-append ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 yunohost service add $app --log="/var/log/$app/weblate.log" -yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" +yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery.log" #================================================= # START SYSTEMD SERVICES @@ -238,7 +230,7 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" ynh_script_progression --message="Starting systemd services..." --weight=5 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" -ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery.log" --line_match="mingle: all alone" #================================================= # END OF SCRIPT