From 107b9c33271ac03bd61ceba141f1c6cc5188aa9c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 16 Apr 2020 23:33:43 +0200 Subject: [PATCH] Apply example_ynh --- README.md | 57 ++++++----------------- check_process | 3 -- conf/nginx.conf | 3 +- manifest.json | 10 ++-- scripts/_common.sh | 22 +++++++-- scripts/backup | 49 +++++++++++++------- scripts/install | 112 +++++++++++++++++++++++++++++++++------------ scripts/remove | 80 ++++++++++++++++++++++++-------- scripts/restore | 77 +++++++++++++++++++++---------- scripts/upgrade | 95 +++++++++++++++++++++++++++----------- 10 files changed, 335 insertions(+), 173 deletions(-) diff --git a/README.md b/README.md index f2c1d3b..c25e87a 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ -Mozilla’s Sync Server for Yunohost -================================== +# Mozilla’s Sync Server for Yunohost -[![Integration level](https://dash.yunohost.org/integration/ffsync.svg)](https://ci-apps.yunohost.org/ci/apps/ffsync%20%28Community%29/lastBuild/consoleFull) +[![Integration level](https://dash.yunohost.org/integration/ffsync.svg)](https://dash.yunohost.org/appci/app/ffsync) [![Install ffsync with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=ffsync) > *This package allow you to install ffsync quickly and simply on a YunoHost server. If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* -Overview --------- +## Overview The Sync Server provides a replacement for Firefox’s default server (hosted at Mozilla). @@ -18,50 +16,31 @@ Since no version was released since 2018, we follow now the master branch **Shipped version:** commit 33a1e42 -Documentation -------------- +## Configuration + +Once installed, reaching `http://domain.tld/path` should show a page explaining how to configure it. Otherwise please refer to the [Yunohost page](https://yunohost.org/#/app_ffsync). + +## Documentation * Official documentation: https://docs.services.mozilla.com/howtos/run-sync-1.5.html * YunoHost documentation: There no other documentations, feel free to contribute. -YunoHost specific features --------------------------- +## YunoHost specific features - - -Additional informations ------------------------ - -### Configuring - -Once installed, reaching `http://domain.tld/path` should show a page explaining how to configure it. Otherwise please refer to the [Yunohost page](https://yunohost.org/#/app_ffsync). +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/ffsync%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/ffsync/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/ffsync%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/ffsync/) ## Links * Report a bug about this package: https://github.com/YunoHost-Apps/ffsync_ynh/issues - * Report a bug about firefox sync itself: https://github.com/mozilla-services/syncserver + * Upstream app repository: https://github.com/mozilla-services/syncserver * YunoHost website: https://yunohost.org/ --- -Install -------- - -From command line: - -`sudo yunohost app install -l ffsync https://github.com/YunoHost-Apps/ffsync_ynh` - -Upgrade -------- - -From command line: - -`sudo yunohost app upgrade ffsync -u https://github.com/YunoHost-Apps/ffsync_ynh` - -Developers infos +Developers info ---------------- Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/ffsync_ynh/tree/testing). @@ -72,11 +51,3 @@ sudo yunohost app install https://github.com/YunoHost-Apps/ffsync_ynh/tree/testi or sudo yunohost app upgrade ffsync -u https://github.com/YunoHost-Apps/ffsync_ynh/tree/testing --debug ``` - -License -------- - -ffsync is published under the Mozilla Public License Version 2.0 - -TODO ----- diff --git a/check_process b/check_process index 1b21f7b..41a95e6 100644 --- a/check_process +++ b/check_process @@ -10,11 +10,8 @@ setup_private=0 setup_public=1 upgrade=1 - upgrade=1 from_commit=fd6350495d5a1d864ae30e1a61e18939fdb6a428 - upgrade=1 from_commit=267ccc21f7b52d22bc3d5b9cd6239857b9a82aad backup_restore=1 multi_instance=1 - incorrect_path=1 port_already_use=0 change_url=0 ;;; Levels diff --git a/conf/nginx.conf b/conf/nginx.conf index 0019584..af9f8fc 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,9 +1,10 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; - location __PATH__/ { + # Path to source alias __FINALPATH__/ ; + # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } diff --git a/manifest.json b/manifest.json index 362eec5..a7e515e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,13 +1,14 @@ { "name": "Firefox Sync Server", "id": "ffsync", - "version": "1.8.0~ynh1", - "url": "https://github.com/mozilla-services/syncserver", "packaging_format": 1, "description": { "en": "Mozilla’s Sync-Server to host your Firefox account data", "fr": "Le serveur de synchronisation de Mozilla, pour héberger vos données Firefox" }, + "version": "1.8.0~ynh1", + "url": "https://github.com/mozilla-services/syncserver", + "license": "MPL-2.0", "maintainer": { "name": "Josué Tille", "email": "josue@tille.ch" @@ -20,13 +21,12 @@ "email": "jean-baptiste@holcroft.fr" }], "requirements": { - "yunohost": ">=3.0.0" + "yunohost": ">= 3.5" }, - "license": "MPL-2.0", + "multi_instance": true, "services": [ "nginx" ], - "multi_instance": true, "arguments": { "install" : [ { diff --git a/scripts/_common.sh b/scripts/_common.sh index 08c2ffb..4d7ecfe 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,11 +1,17 @@ +#!/bin/bash + #================================================= -# SET ALL CONSTANTS +# COMMON VARIABLES #================================================= -app=$YNH_APP_INSTANCE_NAME -# Note that we also need some specific dependances for build with arm architectures -dependances="python-dev python-virtualenv virtualenv uwsgi uwsgi-plugin-python build-essential libssl-dev libffi-dev" +# Note that we also need some specific pkg_dependencies for build with arm architectures +# dependencies used by the app +pkg_dependencies="python-dev python-virtualenv virtualenv uwsgi uwsgi-plugin-python build-essential libssl-dev libffi-dev" + +#================================================= +# PERSONAL HELPERS +#================================================= install_sources() { ynh_setup_source --dest_dir "$final_path" @@ -39,3 +45,11 @@ set_permissions() { chown $app:root /var/log/uwsgi/$app chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app } + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index 661d0ae..9ff4146 100644 --- a/scripts/backup +++ b/scripts/backup @@ -3,46 +3,61 @@ #================================================= # 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/experimental_helper.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Import common cmd -source ../settings/scripts/experimental_helper.sh -source ../settings/scripts/_common.sh - +#================================================= # LOAD SETTINGS +#================================================= ynh_script_progression --message="Loading installation settings..." -final_path=$(ynh_app_setting_get --app $app --key final_path) -domain=$(ynh_app_setting_get --app $app --key domain) -db_name=$(ynh_app_setting_get --app $app --key db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # STANDARD BACKUP STEPS #================================================= - # BACKUP THE APP MAIN DIR +#================================================= ynh_script_progression --message="Backing up the main app directory..." -ynh_backup --src_path "$final_path" +ynh_backup --src_path="$final_path" +#================================================= # BACKUP THE NGINX CONFIGURATION -ynh_script_progression --message="Backing configuration..." -ynh_backup --src_path "/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +ynh_script_progression --message="Backing up nginx web server configuration..." +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= # BACKUP THE MYSQL DATABASE -ynh_script_progression --message="Backing up database" -ynh_mysql_dump_db "$db_name" > db.sql +#================================================= +ynh_script_progression --message="Backing up the MySQL database..." +ynh_mysql_dump_db --database="$db_name" > db.sql +#================================================= +# SPECIFIC BACKUP +#================================================= # Backup Log ynh_script_progression --message="Backing up logs" -ynh_backup --src_path "/var/log/uwsgi/$app" +ynh_backup --src_path="/var/log/uwsgi/$app" # BACKUP THE UWSGI FILES ynh_script_progression --message="Backing up configuration..." -ynh_backup --src_path "/etc/uwsgi/apps-available/$app.ini" -ynh_backup --src_path "/etc/systemd/system/uwsgi-app@.service" +ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" +ynh_backup --src_path="/etc/systemd/system/uwsgi-app@.service" +#================================================= +# END OF SCRIPT +#================================================= ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/install b/scripts/install index 84fc6e8..23201c8 100644 --- a/scripts/install +++ b/scripts/install @@ -3,62 +3,83 @@ #================================================= # GENERIC START #================================================= - # IMPORT GENERIC HELPERS +#================================================= + +source ./experimental_helper.sh +source ./_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Import common cmd -source ./experimental_helper.sh -source ./_common.sh +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +secret=$(ynh_string_random) +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= ynh_script_progression --message="Validating installation parameters..." -# Retrieve arguments -domain=$YNH_APP_ARG_DOMAIN -path_url=$(ynh_normalize_url_path --path_url $YNH_APP_ARG_PATH) -app=$YNH_APP_INSTANCE_NAME final_path="/opt/yunohost/$app" - -# Generate random password and save -secret=$(ynh_string_random) - -# STORE SETTINGS FROM MANIFEST -ynh_app_setting_set --app $app --key final_path --value "$final_path" -ynh_app_setting_set --app $app --key secret --value "$secret" - -# Check destination directory -test ! -e "$final_path" || ynh_die --message "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path -ynh_webpath_register --app $app --domain $domain --path_url $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=secret --value="$secret" #================================================= # STANDARD MODIFICATIONS #================================================= +#================================================= # INSTALL DEPENDENCIES +#================================================= ynh_script_progression --message="Installing dependencies..." --weight=7 -ynh_install_app_dependencies $dependances +ynh_install_app_dependencies $pkg_dependencies +#================================================= # CREATE A MYSQL DATABASE -ynh_script_progression --message="Configuring MySQL database..." -db_user=$app -db_name=$(ynh_sanitize_dbid --db_name $app) -ynh_app_setting_set --app $app --key db_name --value "$db_name" -ynh_mysql_setup_db --db_user "$db_user" --db_name "$db_name" +#================================================= +ynh_script_progression --message="Creating a MySQL database..." +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + +#================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= ynh_script_progression --message="Installing sources files..." --weight=10 + + +ynh_app_setting_set --app=$app --key=final_path --value=$final_path install_sources # Modify assets to take path into account # TODO: try to include this as a patch if still needed # find ../sources/syncserver/page/sync_files/ -type f -exec sed -i -e "s@media\/img@$path_url\/media\/img@g" {} \; +#================================================= # NGINX CONFIGURATION +#================================================= ynh_script_progression --message="Configuring nginx" ynh_add_nginx_config @@ -72,9 +93,16 @@ fi ynh_store_file_checksum --file "$finalnginxconf" systemctl reload nginx +#================================================= # CREATE DEDICATED USER +#================================================= ynh_script_progression --message="Configuring system user..." -ynh_system_user_create --username "$app" --home_dir "$final_path" +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# SPECIFIC SETUP +#================================================= # create config file syncserver.ini ynh_script_progression --message="Configuring application..." @@ -84,7 +112,9 @@ ln -s "/etc/uwsgi/apps-available/$app.ini" "$final_path/syncserver.ini" # configure uwsgi ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name' +#================================================= # MODIFY A CONFIG FILE +#================================================= # TODO: fix this css patch # ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/firefox_sync-bundle.css # ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/responsive-bundle.css @@ -92,14 +122,38 @@ ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name' #================================================= # GENERIC FINALIZATION #================================================= - # SECURE FILES AND DIRECTORIES +#================================================= ynh_script_progression --message="Protecting directory" + +# Set permissions to app files set_permissions +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_print_info --message="Integrating service in YunoHost..." + +yunohost service add "uwsgi-app@$app.service" --log "/var/log/uwsgi/app/$app" + + +#================================================= # SETUP SSOWAT -# accessible by everyone (authentification is done by firefox accounts) +#================================================= ynh_script_progression --message="Configuring permissions" -ynh_app_setting_set --app $app --key skipped_uris --value "/" +# accessible by everyone (authentification is done by firefox accounts) + +ynh_app_setting_set --app=$app --key=skipped_uris --value="/" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 81371f2..0abfa5e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -3,50 +3,90 @@ #================================================= # GENERIC START #================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source YunoHost helpers -source /usr/share/yunohost/helpers - -# Stop script if errors -set -u - -# Import common cmd source ./experimental_helper.sh source ./_common.sh +source /usr/share/yunohost/helpers +#================================================= # LOAD SETTINGS +#================================================= ynh_script_progression --message="Loading installation settings..." -domain=$(ynh_app_setting_get --app $app --key domain) -final_path=$(ynh_app_setting_get --app $app --key final_path) -db_user=$app -db_name=$app + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= - # REMOVE UWSGI +#================================================= + +# 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 +then + ynh_print_info --message="Removing $app service..." + yunohost service remove uwsgi-app@$app.service +fi + +#================================================= +# STOP AND REMOVE SERVICE +#================================================= ynh_script_progression --message="Removing configuration..." + +# Remove the dedicated systemd config ynh_remove_uwsgi_service +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Removing the MySQL database..." + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name + +#================================================= # REMOVE DEPENDENCIES +#================================================= ynh_script_progression --message="Removing dependencies" --weight=10 + +# Remove metapackage and its dependencies ynh_remove_app_dependencies -# REMOVE THE MYSQL DATABASE -ynh_script_progression --message="Removing databases..." -ynh_mysql_remove_db --db_user "$db_user" --db_name "$db_name" - +#================================================= # REMOVE APP MAIN DIR -ynh_script_progression --message="Backing up the main app directory..." +#================================================= +ynh_script_progression --message="Removing app main directory..." + +# Remove the app directory securely ynh_secure_remove --file="$final_path" +#================================================= # REMOVE NGINX CONFIGURATION -ynh_script_progression --message="Removing nginx configuration" +#================================================= +ynh_script_progression --message="Removing nginx web server configuration..." + +# Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_script_progression --message="Removing the dedicated system user..." + # Delete a system user -ynh_script_progression --message="Removing user..." -ynh_system_user_delete --username "$app" +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index d36d85c..a6206df 100644 --- a/scripts/restore +++ b/scripts/restore @@ -3,26 +3,38 @@ #================================================= # GENERIC START #================================================= - # IMPORT GENERIC HELPERS +#================================================= +source ../settings/scripts/experimental_helper.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Import common cmd -source ../settings/scripts/experimental_helper.sh -source ../settings/scripts/_common.sh - +#================================================= # LOAD SETTINGS +#================================================= ynh_script_progression --message="Loading settings..." -domain=$(ynh_app_setting_get --app $app --key domain) -path_url=$(ynh_app_setting_get --app $app --key path) -final_path=$(ynh_app_setting_get --app $app --key final_path) -db_name=$(ynh_app_setting_get --app $app --key db_name) +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name + +#================================================= # CHECK IF THE APP CAN BE RESTORED -ynh_webpath_available --domain $domain --path_url $path_url || ynh_die --message "$domain/$path_url is not available, please use an other domain or path." +#================================================= +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -32,34 +44,51 @@ ynh_webpath_available --domain $domain --path_url $path_url || ynh_die --message ynh_script_progression --message="Restoring files..." --weight=5 ynh_restore -# RESTORE THE MYSQL DATABASE -ynh_script_progression --message="Restoring database..." --weight=3 -db_pwd=$(ynh_app_setting_get --app $app --key mysqlpwd) -ynh_mysql_setup_db --db_user "$db_name" --db_name "$db_name" --db_pwd "$db_pwd" -ynh_mysql_connect_as --user "$db_name" --password "$db_pwd" --database "$db_name" < ./db.sql - +#================================================= # RECREATE THE DEDICATED USER +#================================================= ynh_script_progression --message="Recreating the dedicated system user..." -ynh_system_user_create --username "$app" +ynh_system_user_create --username="$app" usermod --append --groups www-data "$app" -# REINSTALL DEPENDENCIES -ynh_script_progression --message="Reinstalling dependencies..." --weight=5 -ynh_install_app_dependencies $dependances +#================================================= +# RESTORE USER RIGHTS +#================================================= +ynh_script_progression --message="Restoring user rights..." -# set authorizations -ynh_script_progression --message="Protecting directory..." set_permissions -# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=5 +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring database..." --weight=3 +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= yunohost service add "uwsgi-app@$app.service" --log "/var/log/uwsgi/app/$app" ynh_script_progression --message="Reloading services..." --weight=3 systemctl daemon-reload systemctl enable "uwsgi-app@$app.service" - +#================================================= +# GENERIC FINALIZATION +#================================================= # RELOAD NGINX AND UWSGI +#================================================= + systemctl start "uwsgi-app@$app.service" systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index 01aa0ad..0040219 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -3,46 +3,56 @@ #================================================= # GENERIC START #================================================= - # IMPORT GENERIC HELPERS -source /usr/share/yunohost/helpers +#================================================= -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -# Import common cmd source ./experimental_helper.sh source ./_common.sh +source /usr/share/yunohost/helpers +#================================================= # LOAD SETTINGS +#================================================= ynh_script_progression --message="Loading installation settings..." -domain=$(ynh_app_setting_get --app $app --key domain) -path_url=$(ynh_app_setting_get --app $app --key path) -db_name=$(ynh_app_setting_get --app $app --key db_name) -db_pwd=$(ynh_app_setting_get --app $app --key mysqlpwd) -db_user=$app -final_path=$(ynh_app_setting_get --app $app --key final_path) -secret=$(ynh_app_setting_get --app $app --key secret) -path_url=$(ynh_normalize_url_path "$path_url") +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app $app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +secret=$(ynh_app_setting_get --app $app --key=secret) +db_pwd=$(ynh_app_setting_get --app=$app --key mysqlpwd) +db_user=$app + +#================================================= +# CHECK VERSION +#================================================= +ynh_print_info --message="Checking version..." + +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= ynh_script_progression --message="Checking backware compatibility..." --weight=10 # If db_name doesn't exist, create it if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid "$app") - ynh_app_setting_set --app $app --key db_name --value "$db_name" + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then final_path=/opt/yunohost/$app - ynh_app_setting_set --app $app --key final_path --value "$final_path" + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # If path_url doesn't exist, create it if [ -z "$path_url" ]; then - path_url=$(ynh_app_setting_get --app $app --key path) - ynh_app_setting_set --app $app --key path --value "$path_url" + path_url=$(ynh_app_setting_get --app=$app --key=path) + ynh_app_setting_set --app=$app --key=path --value="$path_url" ynh_app_setting_delete "$app" path fi @@ -58,27 +68,42 @@ if [ -e /etc/init.d/ffsync ]; then yunohost service remove "$app" fi -# Backup the current version of the ap +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 + +# Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # restore it if the upgrade fails ynh_restore_upgradebackup } +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= -# Check depends installation + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies $dependances +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= # Download, check integrity, uncompress and patch the source from app.src ynh_script_progression --message="Upgrading source files..." --weight=6 install_sources +#================================================= # NGINX CONFIGURATION +#================================================= ynh_script_progression --message="Configuring nginx..." ynh_add_nginx_config @@ -92,11 +117,18 @@ fi ynh_store_file_checksum --file "$finalnginxconf" systemctl reload nginx -# Create a system user -ynh_system_user_create "$app" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_system_user_create --username="$app" + +#================================================= +# SPECIFIC UPGRADE +#================================================= # SETUP UWSGI ynh_script_progression --message="Configuring application..." + # create config file syncserver.ini rm "$final_path/syncserver.ini" ln -s "/etc/uwsgi/apps-available/$app.ini" "$final_path/syncserver.ini" @@ -107,12 +139,21 @@ ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name' #================================================= # GENERIC FINALIZATION #================================================= - # SECURE FILES AND DIRECTORIES -ynh_script_progression --message="Protecting directory..." +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions on app files set_permissions +#================================================= # SETUP SSOWAT -ynh_app_setting_set --app $app --key skipped_uris --value "/" +#================================================= + +ynh_app_setting_set --app=$app --key=skipped_uris --value="/" + +#================================================= +# END OF SCRIPT +#================================================= ynh_script_progression --message="Upgrade of $app completed" --last