From 5b0205bc95aabd98e53de497f9a9ab5493d35baa Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 03:55:10 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 3 ++ manifest.toml | 4 +- scripts/_common.sh | 14 +----- scripts/backup | 29 +++++------- scripts/change_url | 48 ++++++++------------ scripts/install | 100 +++++++++++++++++++---------------------- scripts/remove | 41 ++++++++--------- scripts/restore | 60 +++++++++++-------------- scripts/upgrade | 110 +++++++++++++++++++-------------------------- 9 files changed, 170 insertions(+), 239 deletions(-) diff --git a/.gitignore b/.gitignore index 7bbc71c..ac45474 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,6 @@ ENV/ # mypy .mypy_cache/ +*~ +*.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 33a3fe4..8d95556 100644 --- a/manifest.toml +++ b/manifest.toml @@ -22,7 +22,8 @@ cpe = "cpe:2.3:a:weblate:weblate" fund = "https://weblate.org/fr/donate/" [integration] -yunohost = ">= 11.2.12" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = false @@ -86,6 +87,7 @@ ram.runtime = "3G" [resources.system_user] [resources.install_dir] + group = "www-data:r-x" [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index c5f9ef0..5e9b55a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= debian_maj_version=$(sed 's/\..*//' /etc/debian_version) @@ -16,10 +16,6 @@ elif [ "$debian_maj_version" -eq 12 ] ; then weblate_pypath="python3.11" fi -#================================================= -# PERSONAL HELPERS -#================================================= - set_forge_variables() { if [ $used_forge = "GitHub" ] ; then github_username="$forge_username" @@ -33,11 +29,3 @@ set_forge_variables() { gitlab_token="$forge_token" fi } - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index dbbe2a8..fd85c98 100755 --- a/scripts/backup +++ b/scripts/backup @@ -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,30 +24,30 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" -ynh_backup --src_path="/etc/systemd/system/$app-celery.service" +ynh_backup "/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app-celery.service" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" +ynh_backup "/etc/uwsgi/apps-available/$app.ini" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # 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)." diff --git a/scripts/change_url b/scripts/change_url index 5a4d779..041c63f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,87 +1,77 @@ #!/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 systemd services..." --weight=1 +ynh_script_progression "Stopping systemd services..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI" -ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --log_path="/var/log/$app/weblate.log" --wait_until="goodbye to uWSGI" +ynh_systemctl --service="$app-celery" --action="stop" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS #================================================= # MODIFY SETTINGS #================================================= -ynh_script_progression --message="Modify weblate's config file..." --weight=1 +ynh_script_progression "Modify weblate's config file..." settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" -ynh_backup_if_checksum_is_different --file="$settings" +ynh_backup_if_checksum_is_different "$settings" # Change the path in the nginx config file if [ $change_path -eq 1 ] then - ynh_replace_string --match_string="URL_PREFIX = \"${old_path%/}\"" --replace_string="URL_PREFIX = \"${new_path%/}\"" --target_file="$settings" + ynh_replace --match="URL_PREFIX = \"${old_path%/}\"" --replace="URL_PREFIX = \"${new_path%/}\"" --file="$settings" fi # Change the domain for nginx if [ $change_domain -eq 1 ] then # replace SERVER_EMAIL - ynh_replace_string --match_string="noreply@$old_domain" --replace_string="noreply@$new_domain" --target_file="$settings" + ynh_replace --match="noreply@$old_domain" --replace="noreply@$new_domain" --file="$settings" # replace SITE_DOMAIN - ynh_replace_string --match_string="SITE_DOMAIN = \"$old_domain\"" --replace_string="SITE_DOMAIN = \"$new_domain\"" --target_file="$settings" + ynh_replace --match="SITE_DOMAIN = \"$old_domain\"" --replace="SITE_DOMAIN = \"$new_domain\"" --file="$settings" # replace ALLOWED_HOSTS - ynh_replace_string --match_string="ALLOWED_HOSTS = \[\"$old_domain\"\]" --replace_string="ALLOWED_HOSTS = \[\"$new_domain\"\]" --target_file="$settings" + ynh_replace --match="ALLOWED_HOSTS = \[\"$old_domain\"\]" --replace="ALLOWED_HOSTS = \[\"$new_domain\"\]" --file="$settings" fi -ynh_store_file_checksum --file="$settings" +ynh_store_file_checksum "$settings" #================================================= # MODIFY UWSGI #================================================= finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" -ynh_backup_if_checksum_is_different --file="$finaluwsgiini" +ynh_backup_if_checksum_is_different "$finaluwsgiini" # Change the path in the nginx config file if [ $change_path -eq 1 ] then - ynh_replace_string --match_string="mount = $old_path=" --replace_string="mount = $new_path=" --target_file="$finaluwsgiini" + ynh_replace --match="mount = $old_path=" --replace="mount = $new_path=" --file="$finaluwsgiini" fi -ynh_store_file_checksum --file="$finaluwsgiini" +ynh_store_file_checksum "$finaluwsgiini" -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=5 +ynh_script_progression "Starting $app's systemd service..." -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_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI" +ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 4e13e85..cdd1f08 100755 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -19,11 +13,11 @@ key=$(ynh_string_random --length=50) #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 +ynh_script_progression "Storing installation settings..." -ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge -ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username -ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token +ynh_app_setting_set --key=used_forge --value=$used_forge +ynh_app_setting_set --key=forge_username --value=$forge_username +ynh_app_setting_set --key=forge_token --value=$forge_token # Remove trailing "/" from the path path_no_slash=${path%/} @@ -31,36 +25,35 @@ path_no_slash=${path%/} #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 +ynh_script_progression "Creating a PostgreSQL database..." -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." mkdir -p "$install_dir/avatar-cache" mkdir -p "$install_dir/data" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$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 | 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:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=2 +ynh_script_progression "Configuring NGINX web server..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx #================================================= # SPECIFIC SETUP #================================================= # INSTALL XXHASH #================================================= -ynh_script_progression --message="Installing xxHash..." +ynh_script_progression "Installing xxHash..." tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" @@ -68,17 +61,17 @@ pushd $tempdir make make install popd -ynh_secure_remove --file="$tempdir" +ynh_safe_rm "$tempdir" #================================================= # CONFIGURE HUB #================================================= if [ $used_forge = "GitHub" ] ; then - ynh_script_progression --message="Configure hub..." --weight=1 - + ynh_script_progression "Configure hub..." + mkdir "$install_dir/.config/" - ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub" + ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub" cat < "$install_dir/.bashrc" eval "$(hub alias -s /bin/bash)" @@ -88,11 +81,10 @@ fi #================================================= # PIP INSTALLATION #================================================= -ynh_script_progression --message="Install weblate using PIP..." --weight=80 +ynh_script_progression "Install weblate using PIP..." virtualenv --python=python3 "${install_dir}/venv" -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" #run source in a 'sub shell' ( set +o nounset @@ -116,33 +108,33 @@ chown -R $app: "$install_dir" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." redis_db=$(ynh_redis_get_free_db) -ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" +ynh_app_setting_set --key=redis_db --value="$redis_db" settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" set_forge_variables -ynh_add_config --template="../conf/settings.py" --destination="$settings" -ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate" -ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" +ynh_config_add --template="settings.py" --destination="$settings" +ynh_config_add --template="celery-weblate" --destination="$install_dir/celery-weblate" +ynh_config_add --template="uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" touch "$install_dir/local_settings.py" ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py" # Set permissions to app files -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app: "$install_dir" -chown "$app:www-data" "$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 | 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" +#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:www-data" "$install_dir" chown -R "$app:www-data" "$install_dir/data" #================================================= # SPECIFIC SETUP Filling up the database # https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database #========================================== -ynh_script_progression --message="Filling up the database..." --weight=10 +ynh_script_progression "Filling up the database..." ( set +o nounset @@ -152,46 +144,44 @@ ynh_script_progression --message="Filling up the database..." --weight=10 cd "${install_dir}" # the user needs to be weblate for postgresql - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput - - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate createadmin --no-color \ + ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput + + ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate createadmin --no-color \ --password "$password" \ --username "$admin" \ --email "$admin_mail" # generate static files - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput + ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput # https://docs.weblate.org/en/latest/admin/install/venv-debian.html - ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate compress + ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate compress # 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 + ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true ) #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=3 +ynh_script_progression "Configuring $app's systemd service..." -ynh_add_systemd_config --service=$app --template="weblate.service" -ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" +ynh_config_add_systemd --template="weblate.service" +ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service" -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +ynh_script_progression "Configuring log rotation..." # Use logrotate to manage application logfile(s) -ynh_use_logrotate --non-append +ynh_config_add_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" @@ -199,13 +189,13 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=5 +ynh_script_progression "Starting $app's systemd service..." -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_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI" +ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index f6d4bd6..b4e2e43 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -16,48 +10,49 @@ source /usr/share/yunohost/helpers #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=1 + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status "$app-celery" >/dev/null +if ynh_hide_warnings yunohost service status "$app-celery" >/dev/null then - ynh_script_progression --message="Removing $app-celery service integration..." --weight=1 + ynh_script_progression "Removing $app-celery service integration..." yunohost service remove "$app-celery" fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=5 +ynh_script_progression "Stopping and removing the systemd service..." # Remove the dedicated systemd config -ynh_remove_systemd_config --service=$app -ynh_remove_systemd_config --service="$app-celery" +ynh_config_remove_systemd + +ynh_config_remove_systemd"$app-celery" #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 +ynh_script_progression "Removing logrotate configuration..." # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_script_progression "Removing NGINX web server configuration..." # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # REMOVE XXHASH #================================================= -ynh_script_progression --message="Removing xxHash..." +ynh_script_progression "Removing xxHash..." tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" @@ -65,18 +60,18 @@ pushd $tempdir make make uninstall popd -ynh_secure_remove --file="$tempdir" +ynh_safe_rm "$tempdir" #================================================= # SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." +ynh_script_progression "Removing various files..." -ynh_secure_remove --file="/etc/uwsgi/apps-available/$app.ini" +ynh_safe_rm "/etc/uwsgi/apps-available/$app.ini" -ynh_secure_remove --file="/var/run/$app-celery" +ynh_safe_rm "/var/run/$app-celery" ynh_redis_remove_db @@ -84,4 +79,4 @@ ynh_redis_remove_db # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 0263875..541db01 100755 --- a/scripts/restore +++ b/scripts/restore @@ -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,37 +7,37 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=4 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_restore "$install_dir" touch "$install_dir/local_settings.py" ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app: "$install_dir" -chown $app:www-data "$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 | 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" +#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:www-data "$install_dir" chown -R $app:www-data "$install_dir/data" #================================================= # 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 THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_psql_db_shell < ./db.sql #================================================= # INSTALL XXHASH #================================================= -ynh_script_progression --message="Installing xxHash..." +ynh_script_progression "Installing xxHash..." tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" @@ -51,37 +45,37 @@ pushd $tempdir make make install popd -ynh_secure_remove --file="$tempdir" +ynh_safe_rm "$tempdir" #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring various files..." --weight=1 +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" #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=4 +ynh_script_progression "Restoring $app's systemd service..." -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -ynh_restore_file --origin_path="/etc/systemd/system/$app-celery.service" +ynh_restore "/etc/systemd/system/$app-celery.service" systemctl enable "$app-celery" --quiet #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." +ynh_script_progression "Restoring the logrotate configuration..." mkdir -p "/var/log/$app" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" @@ -89,22 +83,20 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=5 +ynh_script_progression "Starting $app's systemd service..." -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-w1.log" --line_match="mingle: all alone" +ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI" +ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-w1.log" --wait_until="mingle: all alone" -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_script_progression "Reloading NGINX web server..." -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" diff --git a/scripts/upgrade b/scripts/upgrade index 6d65747..b5659ce 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,18 +1,12 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression "Loading installation settings..." admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) key=$(ynh_string_random --length=50) @@ -20,51 +14,41 @@ key=$(ynh_string_random --length=50) # Remove trailing "/" from the path path_no_slash=${path%/} -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping systemd services..." --weight=5 +ynh_script_progression "Stopping systemd services..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI" -ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --log_path="/var/log/$app/weblate.log" --wait_until="goodbye to uWSGI" +ynh_systemctl --service="$app-celery" --action="stop" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." # If used_forge, forge_username, forge_token don't exist, create them if [ -z "$used_forge" ]; then used_forge="GitHub" - forge_username=$(ynh_app_setting_get --app=$app --key=github_account) - forge_token=$(ynh_app_setting_get --app=$app --key=github_token) - ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge - ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username - ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token + forge_username=$(ynh_app_setting_get --key=github_account) + forge_token=$(ynh_app_setting_get --key=github_token) + ynh_app_setting_set --key=used_forge --value=$used_forge + ynh_app_setting_set --key=forge_username --value=$forge_username + ynh_app_setting_set --key=forge_token --value=$forge_token fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 +ynh_script_progression "Upgrading NGINX web server configuration..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx -#================================================= -# SPECIFIC UPGRADE #================================================= # INSTALL XXHASH #================================================= -ynh_script_progression --message="Installing xxHash..." +ynh_script_progression "Installing xxHash..." tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" @@ -72,17 +56,17 @@ pushd $tempdir make make install popd -ynh_secure_remove --file="$tempdir" +ynh_safe_rm "$tempdir" #================================================= # CONFIGURE HUB #================================================= if [ $used_forge = "GitHub" ] ; then - ynh_script_progression --message="Configure hub..." --weight=1 - + ynh_script_progression "Configure hub..." + #mkdir "$install_dir/.config/" - ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub" + ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub" cat < "$install_dir/.bashrc" eval "$(hub alias -s /bin/bash)" @@ -92,19 +76,19 @@ fi #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=2 +ynh_script_progression "Updating configuration..." -ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" +ynh_config_add --template="uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" -ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate" +ynh_config_add --template="celery-weblate" --destination="$install_dir/celery-weblate" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=3 +ynh_script_progression "Configuring $app's systemd service..." -ynh_add_systemd_config --service=$app --template="weblate.service" -ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" +ynh_config_add_systemd --template="weblate.service" +ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service" #================================================= # UPGRADE WEBLATE @@ -116,12 +100,11 @@ upgrade() { #================================================= # PIP INSTALLATION #================================================= - ynh_script_progression --message="Install weblate using PIP..." --weight=15 + ynh_script_progression "Install weblate using PIP..." - ynh_secure_remove --file="${install_dir}/venv" + ynh_safe_rm "${install_dir}/venv" virtualenv --python=python3 "${install_dir}/venv" - 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" #run source in a 'sub shell' ( set +o nounset @@ -144,19 +127,19 @@ upgrade() { #================================================= # MODIFY A CONFIG FILE #================================================= - ynh_script_progression --message="Create weblate configuration file..." --weight=2 + ynh_script_progression "Create weblate configuration file..." # save old settings file settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" path="${path%/}" set_forge_variables - ynh_add_config --template="../conf/settings.py" --destination="$settings" + ynh_config_add --template="settings.py" --destination="$settings" - ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" + ynh_app_setting_set --key=redis_db --value="$redis_db" # Recalculate and store the config file checksum into the app settings - ynh_store_file_checksum --file="$settings" + ynh_store_file_checksum "$settings" touch "$install_dir/local_settings.py" ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py" @@ -164,9 +147,9 @@ upgrade() { #================================================= # MIGRATE WEBLATE #================================================= - ynh_script_progression --message="Run migration scripts..." --weight=10 + ynh_script_progression "Run migration scripts..." - ynh_systemd_action --service_name="$app-celery" --action="start" + ynh_systemctl --service="$app-celery" --action="start" ( set +o nounset @@ -189,7 +172,7 @@ upgrade() { fi ) - ynh_systemd_action --service_name="$app-celery" --action="stop" + ynh_systemctl --service="$app-celery" --action="stop" } file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py" @@ -205,7 +188,7 @@ else current_version=3 fi -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;" if [ "$current_version" -lt "5" ] then @@ -216,27 +199,24 @@ upgrade $(ynh_app_upstream_version) "../conf/settings.py" # Set right permissions for curl installation mkdir -p "$install_dir/avatar-cache" -chown -R $app: "$install_dir" -chown "$app:www-data" "$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" +#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:www-data" "$install_dir" chown -R "$app:www-data" "$install_dir/data" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" - -#================================================= -# GENERIC FINALIZATION +#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 | chmod -R o-rwx "$install_dir" #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +ynh_script_progression "Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +ynh_config_add_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" @@ -244,13 +224,13 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" #================================================= # START SYSTEMD SERVICES #================================================= -ynh_script_progression --message="Starting systemd services..." --weight=5 +ynh_script_progression "Starting systemd services..." -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_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI" +ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"