diff --git a/check_process b/check_process index da4e358..26168f7 100644 --- a/check_process +++ b/check_process @@ -1,7 +1,7 @@ -;; Test name +;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) + domain="domain.tld" + path="/path" ; Checks pkg_linter=1 setup_sub_dir=1 @@ -10,10 +10,12 @@ setup_private=0 setup_public=1 upgrade=1 + # 1.9.1~ynh2 + upgrade=1 from_commit=cb0e04c7fbfd02f58516a88396bb1dd6c79469c0 backup_restore=1 multi_instance=1 port_already_use=0 change_url=0 ;;; Options -Email=jean-baptiste@holcroft.fr -Notification=fail +Email= +Notification=none diff --git a/conf/nginx.conf b/conf/nginx.conf index 460eb29..1d6171a 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,18 +1,13 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - # Path to source - alias __FINALPATH__/ ; + # Path to source + alias __FINALPATH__/; - # Force usage of https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - - include uwsgi_params; - # Needed for long running operations in admin interface - uwsgi_read_timeout 3600; - __IS_SUBPATH__uwsgi_param SCRIPT_NAME __PATH__; - __IS_SUBPATH__uwsgi_modifier1 30; - uwsgi_pass unix:///run/__NAME__/app.socket; + include uwsgi_params; + # Needed for long running operations in admin interface + uwsgi_read_timeout 3600; + __IS_SUBPATH__uwsgi_param SCRIPT_NAME __PATH__; + __IS_SUBPATH__uwsgi_modifier1 30; + uwsgi_pass unix:///run/__NAME__/app.socket; } diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..668e07c --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,3 @@ +The Sync Server provides a replacement for Firefox’s default server (hosted at Mozilla). + +By default, a server set up will defer authentication to the Mozilla-hosted accounts server at [https://accounts.firefox.com](https://accounts.firefox.com). So you will still have to authenticate at Mozilla, but _the storage of your information will be done on your host_. diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..5b09d03 --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1,3 @@ +Le serveur de synchronisation permet un remplacement du serveur par défaut de Firefox (hébergé par Mozilla). + +Par défaut, le serveur reporte l'authentification aux serveurs de comptes de Mozilla à https://accounts.firefox.com. vous vous authentifierez donc sur les serveurs de Mozilla, mais _le stockage de vos informations se fera sur votre serveur_. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..443a08d --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,23 @@ +## Configuration + +Once installed, reaching `http://domain.tld/path` should show a page explaining how to configure it. + +### Solving problems with Android + +The sure-fire way to know what Sync on Android is really doing is to observe the Android device log using adb logcat. You’ll want to bump your log-level: +``` +adb shell setprop log.tag.FxAccounts VERBOSE +``` + +Then, you can observe the log using: +``` +adb logcat | grep FxAccounts +``` + +It’s best to observe the log while you force a sync from the Android Settings App. You should see output like: + +``` +D FxAccounts(...) fennec :: BaseResource :: HTTP GET https://token.stage.mozaws.net/1.0/sync/1.5 +... +D FxAccounts(...) fennec :: BaseResource :: HTTP GET https://sync-4-us-east-1.stage.mozaws.net/ +``` diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md new file mode 100644 index 0000000..d600053 --- /dev/null +++ b/doc/DISCLAIMER_fr.md @@ -0,0 +1,4 @@ +## Configuration + +Une fois installé, la page `http://domain.tld/path` vous explique comment l'utiliser. + diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index 0f3bf0d..648ebf1 100644 --- a/manifest.json +++ b/manifest.json @@ -6,8 +6,14 @@ "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.9.1~ynh2", + "version": "1.9.1~ynh3", "url": "https://github.com/mozilla-services/syncserver", + "upstream": { + "license": "GPL-3.0", + "website": "http://get-simple.info", + "admindoc": "http://get-simple.info/wiki/fr:start", + "code": "https://github.com/GetSimpleCMS/GetSimpleCMS" + }, "license": "MPL-2.0", "maintainer": { "name": "Josué Tille", @@ -21,30 +27,21 @@ "email": "jean-baptiste@holcroft.fr" }], "requirements": { - "yunohost": ">= 4.1" - }, + "yunohost": ">= 4.3.0" + }, "multi_instance": true, - "services": [ + "services": [ "nginx" - ], + ], "arguments": { - "install" : [ + "install": [ { "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain for Firefox-Sync Server", - "fr": "Choisissez un domaine pour Firefox-Sync" - }, - "example": "domain.org" + "type": "domain" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Firefox-Sync Server", - "fr": "Choisissez un chemin pour Firefox-Sync" - }, "example": "/ffsync", "default": "/ffsync" } diff --git a/scripts/_common.sh b/scripts/_common.sh index 172f1cb..bbf01ea 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,7 +4,6 @@ # COMMON VARIABLES #================================================= - # Note that we also need some specific pkg_dependencies for build with arm architectures # dependencies used by the app pkg_dependencies="python2.7 python2.7-dev python-virtualenv virtualenv uwsgi uwsgi-plugin-python build-essential libssl-dev libffi-dev libmariadbclient-dev-compat" @@ -50,6 +49,139 @@ set_permissions() { # EXPERIMENTAL HELPERS #================================================= +# Check if system wide templates are available and correcly configured +# +# 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" + + cat > /etc/systemd/system/uwsgi-app@.service < uwsgi-app@$app` +ynh_add_uwsgi_service () { + ynh_check_global_uwsgi_config + + local others_var=${1:-} + 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" + + ynh_backup_if_checksum_is_different --file="$finaluwsgiini" + cp ../conf/uwsgi.ini "$finaluwsgiini" + + # 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 "${final_path:-}"; then + ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finaluwsgiini" + fi + if test -n "${path_url:-}"; then + ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$finaluwsgiini" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finaluwsgiini" + fi + + # Replace all other variable given as arguments + for var_to_replace in $others_var + 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" + done + + ynh_store_file_checksum --file="$finaluwsgiini" + + chown $app:root "$finaluwsgiini" + + # make sure the folder for logs exists and set authorizations + mkdir -p /var/log/uwsgi/$app + chown $app:root /var/log/uwsgi/$app + chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app + + # Setup specific Systemd rules if necessary + test -e ../conf/uwsgi-app@override.service && \ + mkdir /etc/systemd/system/uwsgi-app@$app.service.d && \ + cp ../conf/uwsgi-app@override.service /etc/systemd/system/uwsgi-app@$app.service.d/override.conf + + systemctl daemon-reload + systemctl enable "uwsgi-app@$app.service" + + # Add as a service + yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" +} + +# Remove the dedicated uwsgi ini file +# +# usage: ynh_remove_uwsgi_service +ynh_remove_uwsgi_service () { + local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" + if [ -e "$finaluwsgiini" ]; then + yunohost service remove "uwsgi-app@$app" + systemctl stop "uwsgi-app@$app.service" + systemctl disable "uwsgi-app@$app.service" + + 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" + fi +} + +ynh_restore_uwsgi_service () { + ynh_check_global_uwsgi_config + systemctl enable "uwsgi-app@$app" --quiet + yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 5b51f01..7eb13d7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,8 +6,7 @@ # 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 +# 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 @@ -29,37 +28,41 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_print_info --message="Backing up the main app directory..." + ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_print_info --message="Backing up nginx web server configuration..." + ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP VARIOUS FILES +#================================================= + +ynh_backup --src_path="/var/log/uwsgi/$app" + +# BACKUP THE UWSGI FILES +ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" +ynh_backup --src_path="/etc/systemd/system/uwsgi-app@.service" + #================================================= # BACKUP THE MYSQL DATABASE #================================================= ynh_print_info --message="Backing up the MySQL database..." + ynh_mysql_dump_db --database="$db_name" > db.sql -#================================================= -# SPECIFIC BACKUP -#================================================= -# Backup Log -ynh_print_info --message="Backing up logs" -ynh_backup --src_path="/var/log/uwsgi/$app" - -# BACKUP THE UWSGI FILES -ynh_print_info --message="Backing up UWSGI..." -ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" -ynh_backup --src_path="/etc/systemd/system/uwsgi-app@.service" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh deleted file mode 100644 index 9c71494..0000000 --- a/scripts/experimental_helper.sh +++ /dev/null @@ -1,132 +0,0 @@ -# Check if system wide templates are available and correcly configured -# -# 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" - - cat > /etc/systemd/system/uwsgi-app@.service < uwsgi-app@$app` -ynh_add_uwsgi_service () { - ynh_check_global_uwsgi_config - - local others_var=${1:-} - 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" - - ynh_backup_if_checksum_is_different --file="$finaluwsgiini" - cp ../conf/uwsgi.ini "$finaluwsgiini" - - # 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 "${final_path:-}"; then - ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finaluwsgiini" - fi - if test -n "${path_url:-}"; then - ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$finaluwsgiini" - fi - if test -n "${app:-}"; then - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finaluwsgiini" - fi - - # Replace all other variable given as arguments - for var_to_replace in $others_var - 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" - done - - ynh_store_file_checksum --file="$finaluwsgiini" - - chown $app:root "$finaluwsgiini" - - # make sure the folder for logs exists and set authorizations - mkdir -p /var/log/uwsgi/$app - chown $app:root /var/log/uwsgi/$app - chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app - - # Setup specific Systemd rules if necessary - test -e ../conf/uwsgi-app@override.service && \ - mkdir /etc/systemd/system/uwsgi-app@$app.service.d && \ - cp ../conf/uwsgi-app@override.service /etc/systemd/system/uwsgi-app@$app.service.d/override.conf - - systemctl daemon-reload - systemctl enable "uwsgi-app@$app.service" - - # Add as a service - yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" -} - -# Remove the dedicated uwsgi ini file -# -# usage: ynh_remove_uwsgi_service -ynh_remove_uwsgi_service () { - local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" - if [ -e "$finaluwsgiini" ]; then - yunohost service remove "uwsgi-app@$app" - systemctl stop "uwsgi-app@$app.service" - systemctl disable "uwsgi-app@$app.service" - - 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" - fi -} - -ynh_restore_uwsgi_service () { - ynh_check_global_uwsgi_config - systemctl enable "uwsgi-app@$app" --quiet - yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" -} diff --git a/scripts/install b/scripts/install index 090abd6..9048be1 100644 --- a/scripts/install +++ b/scripts/install @@ -6,13 +6,16 @@ # IMPORT GENERIC HELPERS #================================================= -source ./experimental_helper.sh -source ./_common.sh +source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= + +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -22,9 +25,11 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -secret=$(ynh_string_random) + app=$YNH_APP_INSTANCE_NAME +secret=$(ynh_string_random) + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -39,6 +44,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url @@ -46,14 +52,21 @@ 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 $pkg_dependencies +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -67,8 +80,7 @@ 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_script_progression --message="Setting up source files..." --weight=10 ynh_app_setting_set --app=$app --key=final_path --value=$final_path install_sources @@ -77,10 +89,15 @@ install_sources # 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" {} \; +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx" +ynh_script_progression --message="Configuring NGINX web server..." + if [ "$path_url" == "/" ] then # $finalnginxconf comes from ynh_add_nginx_config @@ -89,36 +106,30 @@ then else is_subpath=" " fi -ynh_add_nginx_config 'is_subpath' - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= - -# create config file syncserver.ini +# CONFIGURE APPLICATION +#================================================= ynh_script_progression --message="Configuring application..." -rm "$final_path/syncserver.ini" + +ynh_secure_remove --file="$final_path/syncserver.ini" 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 +# ADD A CONFIGURATION #================================================= +#ynh_script_progression --message="Adding a configuration 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 -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -127,23 +138,30 @@ ynh_script_progression --message="Protecting directory" # Set permissions to app files set_permissions +#================================================= +# GENERIC FINALIZATION +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=3 + +# Start a systemd service +ynh_systemd_action --service_name "uwsgi-app@$app.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" + #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions" -# accessible by everyone (authentification is done by firefox accounts) +# Everyone can access the app. (authentification is done by firefox accounts) ynh_permission_update --permission=main --add=visitors --protected=true --show_tile=true #================================================= -# RELOAD Services +# RELOAD NGINX #================================================= -ynh_script_progression --message="Restart services..." -ynh_systemd_action --service_name=nginx --action=reload +ynh_script_progression --message="Reloading NGINX web server..." -ynh_script_progression --message="Starting $app services..." --weight=3 -ynh_systemd_action --service_name "uwsgi-app@$app.service" \ - --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 39f10dc..e1ec3e6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,8 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source ./experimental_helper.sh -source ./_common.sh +source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -38,7 +37,7 @@ fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Removing configuration..." +ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_uwsgi_service @@ -51,14 +50,6 @@ 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 APP MAIN DIR #================================================= @@ -70,11 +61,19 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." +ynh_script_progression --message="Removing NGINX web server configuration..." -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." --weight=10 + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 56004b5..d684619 100644 --- a/scripts/restore +++ b/scripts/restore @@ -5,25 +5,30 @@ #================================================= # IMPORT GENERIC HELPERS #================================================= -source ../settings/scripts/experimental_helper.sh + +# 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 #================================================= # MANAGE SCRIPT FAILURE #================================================= + +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app $app --key path) +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 @@ -31,26 +36,29 @@ db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" +ynh_script_progression --message="Validating restoration parameters..." + test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS -#================================================= - -# Restore all config and data -ynh_script_progression --message="Restoring files..." --weight=5 -ynh_restore - #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression --message="Recreating the dedicated system user..." -ynh_system_user_create --username="$app" + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" usermod --append --groups www-data "$app" +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring files..." --weight=5 + +ynh_restore + #================================================= # RESTORE USER RIGHTS #================================================= @@ -78,22 +86,30 @@ 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 +# RESTORE SYSTEMD #================================================= - -ynh_script_progression --message="Reloading services..." --weight=3 +ynh_script_progression --message="Restoring the systemd configuration..." --weight=3 ynh_restore_uwsgi_service +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=3 + +ynh_systemd_action --service_name "uwsgi-app@$app.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" + #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND UWSGI +# RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading NGINX web server..." -ynh_script_progression --message="Starting pgadmin services..." --weight=3 -ynh_systemd_action --service_name "uwsgi-app@$app.service" \ - --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# END OF SCRIPT +#================================================= + ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 6736e53..d2474c1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,8 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source ./experimental_helper.sh -source ./_common.sh +source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -18,24 +17,41 @@ ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_normalize_url_path --path_url $(ynh_app_setting_get --app $app --key path)) -final_path=$(ynh_app_setting_get --app $app --key=final_path) +path_url=$(ynh_normalize_url_path --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 +db_pwd=$(ynh_app_setting_get --app=$app --key mysqlpwd) +secret=$(ynh_app_setting_get --app $app --key=secret) #================================================= # CHECK VERSION #================================================= -ynh_print_info --message="Checking version..." +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_clean_check_starting + # 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 #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Checking backware compatibility..." --weight=10 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=10 # If db_name doesn't exist, create it if [ -z "$db_name" ]; then @@ -74,43 +90,40 @@ then yunohost service remove uwsgi-app@$app.service fi -#================================================= -# 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 +if ynh_legacy_permissions_exists +then + ynh_legacy_permissions_delete_all + ynh_app_setting_delete --app=$app --key=is_public +fi +ynh_permission_update --permission=main --add=visitors --protected=true --show_tile=true #================================================= -# STANDARD UPGRADE STEPS +# CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Upgrading source files..." --weight=6 + +install_sources #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." + 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" + if [ "$path_url" == "/" ] then # $finalnginxconf comes from ynh_add_nginx_config @@ -119,18 +132,13 @@ then else is_subpath=" " fi -ynh_add_nginx_config 'is_subpath' - -#================================================= -# CREATE DEDICATED USER -#================================================= - -ynh_system_user_create --username="$app" +ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE #================================================= -# SETUP UWSGI +# CONFIGURE APPLICATION +#================================================= ynh_script_progression --message="Configuring application..." # create config file syncserver.ini @@ -144,8 +152,6 @@ ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name' ynh_mysql_execute_as_root --sql='ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `keys_changed_at` BIGINT NULL AFTER `replaced_at`;' --database=$db_name ynh_mysql_execute_as_root --sql='ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `node` VARCHAR(255) NULL AFTER `keys_changed_at`;' --database=$db_name -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -155,21 +161,20 @@ ynh_script_progression --message="Securing files and directories..." set_permissions #================================================= -# Migrate legacy permissions to new system +# GENERIC FINALIZATION #================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=3 -ynh_script_progression --message="Set permissions..." -if ynh_legacy_permissions_exists -then - ynh_legacy_permissions_delete_all - ynh_app_setting_delete --app=$app --key=is_public -fi -ynh_permission_update --permission=main --add=visitors --protected=true --show_tile=true +ynh_systemd_action --service_name "uwsgi-app@$app.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." -ynh_script_progression --message="Restarting $app services..." --weight=3 -ynh_systemd_action --service_name "uwsgi-app@$app.service" \ - --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT