From c9c2b1f479d9358955e6e68219dfbaa5bb2b7d89 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 27 May 2022 17:03:32 +0200 Subject: [PATCH] Apply last example_ynh --- .github/workflows/updater.sh | 76 ++++++++++++------------ check_process | 13 ++-- conf/nginx.conf | 22 +++---- doc/DESCRIPTION.md | 4 -- doc/DESCRIPTION_fr.md | 5 +- doc/DISCLAIMER.md | 12 ---- doc/DISCLAIMER_fr.md | 13 ---- manifest.json | 10 +--- scripts/backup | 18 +++--- scripts/change_url | 31 ++++++---- scripts/install | 85 +++++++++++++------------- scripts/remove | 2 + scripts/restore | 112 ++++++++++++++++++----------------- scripts/upgrade | 102 +++++++++++++++---------------- 14 files changed, 234 insertions(+), 271 deletions(-) diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index c4d53fc..1e2d171 100755 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -34,6 +34,7 @@ fi echo "Current version: $current_version" echo "Latest release from upstream: $version" echo "VERSION=$version" >> $GITHUB_ENV +echo "REPO=$repo" >> $GITHUB_ENV # For the time being, let's assume the script will fail echo "PROCEED=false" >> $GITHUB_ENV @@ -60,46 +61,45 @@ echo "${#assets[@]} available asset(s)" # Let's loop over the array of assets URLs for asset_url in ${assets[@]}; do -echo "Handling asset at $asset_url" + echo "Handling asset at $asset_url" -# Assign the asset to a source file in conf/ directory -# Here we base the source file name upon a unique keyword in the assets url (admin vs. update) -# Leave $src empty to ignore the asset -case $asset_url in - *"admin"*) - src="app" - ;; - *"update"*) - src="app-upgrade" - ;; - *) - src="" - ;; -esac + # Assign the asset to a source file in conf/ directory + # Here we base the source file name upon a unique keyword in the assets url (admin vs. update) + # Leave $src empty to ignore the asset + case $asset_url in + *"admin"*) + src="app" + ;; + *"update"*) + src="app-upgrade" + ;; + *) + src="" + ;; + esac -# If $src is not empty, let's process the asset -if [ ! -z "$src" ]; then + # If $src is not empty, let's process the asset + if [ ! -z "$src" ]; then + # Create the temporary directory + tempdir="$(mktemp -d)" -# Create the temporary directory -tempdir="$(mktemp -d)" + # Download sources and calculate checksum + filename=${asset_url##*/} + curl --silent -4 -L $asset_url -o "$tempdir/$filename" + checksum=$(sha256sum "$tempdir/$filename" | head -c 64) -# Download sources and calculate checksum -filename=${asset_url##*/} -curl --silent -4 -L $asset_url -o "$tempdir/$filename" -checksum=$(sha256sum "$tempdir/$filename" | head -c 64) + # Delete temporary directory + rm -rf $tempdir -# Delete temporary directory -rm -rf $tempdir + # Get extension + if [[ $filename == *.tar.gz ]]; then + extension=tar.gz + else + extension=${filename##*.} + fi -# Get extension -if [[ $filename == *.tar.gz ]]; then - extension=tar.gz -else - extension=${filename##*.} -fi - -# Rewrite source file -cat < conf/$src.src + # Rewrite source file + cat < conf/$src.src SOURCE_URL=$asset_url SOURCE_SUM=$checksum SOURCE_SUM_PRG=sha256sum @@ -107,11 +107,11 @@ SOURCE_FORMAT=$extension SOURCE_IN_SUBDIR=true SOURCE_FILENAME= EOT -echo "... conf/$src.src updated" + echo "... conf/$src.src updated" -else -echo "... asset ignored" -fi + else + echo "... asset ignored" + fi done diff --git a/check_process b/check_process index b6eb2da..249d3a2 100644 --- a/check_process +++ b/check_process @@ -1,26 +1,21 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest domain="domain.tld" - path="/" - admin="armadietto" - language="fr" is_public=1 is_signup=0 - port="8008" ; Checks pkg_linter=1 + setup_sub_dir=0 setup_root=1 + setup_nourl=0 setup_private=1 setup_public=1 upgrade=1 # 0.0.2~ynh5 upgrade=1 from_commit=d185b84698a9f7e83eff6bf6dd5606f35282a536 backup_restore=1 + multi_instance=0 + port_already_use=0 change_url=1 ;;; Options Email= diff --git a/conf/nginx.conf b/conf/nginx.conf index bc145c9..7857989 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,15 +1,15 @@ -location __PATH__ { - - proxy_pass http://127.0.0.1:__PORT__; - proxy_set_header Host $host; +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { - proxy_set_header X-Forwarded-Ssl on; - proxy_set_header X-Forwarded-Proto https; - proxy_set_header X-Forwarded-Scheme https; + proxy_pass http://127.0.0.1:__PORT__; + proxy_set_header Host $host; - proxy_buffering off; + proxy_set_header X-Forwarded-Ssl on; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-Scheme https; + + proxy_buffering off; - # Include SSOWAT user panel. - # include conf.d/yunohost_panel.conf.inc; + # Include SSOWAT user panel. + # include conf.d/yunohost_panel.conf.inc; } - \ No newline at end of file diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md index d5dea9d..e8b4267 100644 --- a/doc/DESCRIPTION.md +++ b/doc/DESCRIPTION.md @@ -1,4 +1,3 @@ - [Armadietto](https://github.com/remotestorage/armadietto/) is a [remoteStorage](https://remotestorage.io) server written for Node.js. Armadietto is maintained by the remoteStorage community, ([IRC](https://web.libera.chat/#remotestorage), [forums](https://community.remotestorage.io/)). @@ -10,8 +9,6 @@ Armadietto is maintained by the remoteStorage community, ([IRC](https://web.libe > SHOULD expect that its APIs and storage schemas will change before it is > labelled stable. -**Shipped version:** 0.1.5 - ### Installation option User registration is not allowed out of the box. @@ -20,4 +17,3 @@ This option can be enabled in the configuration panel. ### Application for remoteStorage [Here](https://remotestorage.io/apps/) is a non-exhaustive list of apps that have integrated remoteStorage as a storage/sync option. - diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md index a5fc1f9..99a90c9 100644 --- a/doc/DESCRIPTION_fr.md +++ b/doc/DESCRIPTION_fr.md @@ -1,4 +1,3 @@ - [Armadietto](https://github.com/remotestorage/armadietto/) est un serveur [remoteStorage](https://remotestorage.io) écrit pour Node.js. Armadietto est maintenu par la communauté remoteStorage, ([IRC](https://web.libera.chat/#remotestorage), [forums](https://community.remotestorage.io/)). @@ -10,8 +9,6 @@ Armadietto est maintenu par la communauté remoteStorage, ([IRC](https://web.lib > Vous devez vous attendre à ce que ses API et ses schémas de stockage changent avant qu'il ne soit > étiqueté comme stable. -**Version livrée:** 0.1.5 - ### Option d'installation L'inscription des utilisateurs n'est pas autorisée par défault. @@ -19,4 +16,4 @@ Cette option peut être activée via le panneau de configutration. ### Application pour remoteStorage -[Cliquez ici](https://remotestorage.io/apps/) pour voir une liste non exhaustive d'applications ayant intégré remoteStorage comme option de stockage/synchronisation. \ No newline at end of file +[Cliquez ici](https://remotestorage.io/apps/) pour voir une liste non exhaustive d'applications ayant intégré remoteStorage comme option de stockage/synchronisation. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index 75d177a..26c80a2 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -28,15 +28,3 @@ The Armadietto_ynh package is still under development, so you should expect some - Don't forget to update your DNS if you manage them manually. - RemoteStorage requires browser-approved SSL certificates. If you have certificates not issued by [Let's Encrypt](https://letsencrypt.org/), install them manually as usual. - -## TODO - -* Any known limitations, constraints or non-functioning elements, such as (but not limited to) : - * Unsupported architectures? - * Single sign-on or LDAP integration not working? - * etc... - -* Other information that people should know, such as. : - * any specific steps to be performed after installation (like manually terminating the installation, specific admin credentials, ...) - * How to configure / administer the application if it is not obvious. - * Specifics, things to know? diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md index 26068a0..94421be 100644 --- a/doc/DISCLAIMER_fr.md +++ b/doc/DISCLAIMER_fr.md @@ -28,16 +28,3 @@ Le paquet Armadietto_ynh est toujours en cours de développement, vous devez don - N'oubliez pas de mettre à jour vos DNS si vous les gérez manuellement. - RemoteStorage nécessite des certificats SSL approuvés par le navigateur. Si vous disposez de certificats qui ne sont pas émis par [Let's Encrypt](https://letsencrypt.org/), installez-les manuellement comme d'habitude. - - -## TODO - -* Toute limitation ou contrainte connue ou tout élément ne fonctionnant pas, tel que (mais non limité à) : - * architectures non prises en charge ? - * L'authentification unique ou l'intégration LDAP ne fonctionnent pas ? - * etc... - -* D'autres informations que les gens devraient connaître, comme.. : - * toute étape spécifique à effectuer après l'installation (comme terminer manuellement l'installation, des identifiants d'administration spécifiques, ...) - * Comment configurer / administrer l'application si ce n'est pas évident. - * Spécificités, les choses à savoir ? \ No newline at end of file diff --git a/manifest.json b/manifest.json index ffe63d0..2d54a78 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A remoteStorage server running as a nodejs web service with systemd", "fr": "Un serveur remoteStorage excécuté en tant que service web nodejs par systemd" }, - "version": "0.0.7~ynh1", + "version": "0.1.5~ynh1", "url": "https://github.com/remotestorage/armadietto", "upstream": { "license": "MIT", @@ -27,7 +27,7 @@ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -35,11 +35,7 @@ { "name": "is_public", "type": "boolean", - "default": true, - "help": { - "en": "Would you like to restrein the access to this web site?", - "fr": "Souhaitez-vous limiter l'accès à ce site web ?" - } + "default": true }, { "name": "is_signup", diff --git a/scripts/backup b/scripts/backup index ca43193..67278fd 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -47,13 +46,7 @@ ynh_backup --src_path="$final_path" # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="$datadir" - -#================================================= -# BACKUP THE ARMADIETTO SERVER -#================================================= - -ynh_backup --src_path="$final_path/server.js" +ynh_backup --src_path="$datadir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION @@ -61,6 +54,14 @@ ynh_backup --src_path="$final_path/server.js" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SYSTEMD #================================================= @@ -70,4 +71,5 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= # END OF SCRIPT #================================================= + ynh_print_info --message="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 6645cc7..100667f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -17,7 +17,7 @@ old_domain=$YNH_APP_OLD_DOMAIN old_path=$YNH_APP_OLD_PATH new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH +new_path="/" app=$YNH_APP_INSTANCE_NAME @@ -29,6 +29,11 @@ ynh_script_progression --message="Loading installation settings..." --weight=2 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) +# Add settings here as needed by your application +port=$(ynh_app_setting_get --app=$app --key=port) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) +is_signup=$(ynh_app_setting_get --app=$app --key=is_signup) + #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= @@ -37,6 +42,7 @@ ynh_script_progression --message="Backing up the app before changing its URL (ma # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" @@ -103,8 +109,19 @@ fi #================================================= # SPECIFIC MODIFICATIONS #================================================= -# ... +# UPDATE A CONFIG FILE #================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=2 + +domain=$new_domain +ynh_use_nodejs +# Define armadietto module path +module_path="$node_version_path/$nodejs_version/lib/node_modules/armadietto/lib" + +ynh_add_config --template="../conf/server.js" --destination="$final_path/server.js" + +chmod 400 "$final_path/server.js" +chown $app:$app "$final_path/server.js" #================================================= # GENERIC FINALISATION @@ -113,6 +130,7 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= @@ -122,15 +140,8 @@ ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload -#================================================= -# RESTART ARMADIETTO -#================================================= -ynh_script_progression --message="Start armadietto web server..." --weight=1 - -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 2b306f1..a4e757d 100755 --- a/scripts/install +++ b/scripts/install @@ -14,8 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -31,16 +30,12 @@ is_signup=$YNH_APP_ARG_IS_SIGNUP app=$YNH_APP_INSTANCE_NAME -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" - #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=2 final_path=/opt/yunohost/$app - test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path @@ -54,7 +49,6 @@ ynh_script_progression --message="Storing installation settings..." --weight=1 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=is_signup --value=$is_signup -ynh_app_setting_set --app=$app --key=datadir --value=$datadir #================================================= # STANDARD MODIFICATIONS @@ -75,16 +69,27 @@ ynh_script_progression --message="Installing dependencies..." --weight=23 ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_use_nodejs +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=2 + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CHECK AND CREATE FINAL_PATH #================================================= ynh_script_progression --message="Setting up and create final app path..." --weight=1 ynh_app_setting_set --app=$app --key=final_path --value=$final_path - # Create final_path mkdir -p "$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -94,35 +99,35 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 ynh_add_nginx_config #================================================= -# CREATE DEDICATED USER +# SPECIFIC SETUP #================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 - -# Create a system user -ynh_system_user_create --username=$app - +# INSTALL ARMADIETTO #================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=3 +ynh_script_progression --message="Install armadietto with npm..." --weight=1 -# Create a dedicated systemd config -ynh_add_systemd_config +pushd $final_path + upstream_version=$(ynh_app_upstream_version) + ynh_npm -g i armadietto@$upstream_version +popd #================================================= # CREATE DATA DIRECTORY #================================================= ynh_script_progression --message="Creating a data directory..." --weight=1 +datadir="/home/yunohost.app/${app}/storage" ynh_app_setting_set --app=$app --key=datadir --value=$datadir -# Create app data folder mkdir -p $datadir +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:$app "$datadir" + #================================================= -# SETUP ARMADIETTO AS A SERVICE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring armadietto as a service..." --weight=2 +ynh_script_progression --message="Adding a configuration file..." --weight=2 # Define armadietto module path module_path="$node_version_path/$nodejs_version/lib/node_modules/armadietto/lib" @@ -133,13 +138,12 @@ chmod 400 "$final_path/server.js" chown $app:$app "$final_path/server.js" #================================================= -# INSTALL ARMADIETTO +# SETUP SYSTEMD #================================================= -ynh_script_progression --message="Install armadietto with npm..." --weight=1 +ynh_script_progression --message="Configuring a systemd service..." --weight=3 -pushd $final_path - ynh_npm -g i armadietto@0.1.5 -popd +# Create a dedicated systemd config +ynh_add_systemd_config #================================================= # GENERIC FINALIZATION @@ -151,16 +155,6 @@ ynh_script_progression --message="Configuring log rotation..." --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Secure files and directories" --weight=1 - -# Set permissions to app files -chown -R $app:$app "$final_path" -chmod 0700 "$datadir" -chown $app:$app "$datadir" - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -168,6 +162,14 @@ ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="Armadietto run a remotestorage server as service" --log="/var/log/$app/$app.log" +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # SETUP SSOWAT #================================================= @@ -188,15 +190,8 @@ ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload -#================================================= -# START ARMADIETTO -#================================================= -ynh_script_progression --message="Start armadietto web server..." --weight=1 - -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index beec3c8..8aa11d3 100755 --- a/scripts/remove +++ b/scripts/remove @@ -82,6 +82,7 @@ ynh_remove_nginx_config #================================================= ynh_script_progression --message="Removing dependencies..." --weight=2 +# Remove metapackage and its dependencies ynh_remove_nodejs --nodejs_version=$NODEJS_VERSION #================================================= @@ -97,4 +98,5 @@ 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 303a3a9..517b1bf 100755 --- a/scripts/restore +++ b/scripts/restore @@ -15,8 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -38,22 +37,15 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d "$final_path" || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=21 - -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_use_nodejs +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1 +ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -63,7 +55,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR @@ -72,6 +64,44 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." + +ynh_restore_file --origin_path="$datadir" --not_mandatory + +mkdir -p $datadir + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:$app "$datadir" + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=21 + +# Define and install dependencies +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_use_nodejs + +#================================================= +# INSTALL ARMADIETTO +#================================================= +ynh_script_progression --message="Install armadietto with npm..." --weight=1 + +pushd $final_path + upstream_version=$(ynh_app_upstream_version) + ynh_npm -g i armadietto@$upstream_version +popd + #================================================= # RESTORE SYSTEMD #================================================= @@ -81,41 +111,11 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet #================================================= -# RESTORE ARMADIETTO AS A SERVICE +# RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Restoring armadietto as a service..." --weight=1 +ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 -ynh_restore_file --origin_path="$final_path/server.js" --not_mandatory -ynh_restore_file --origin_path="$datadir" --not_mandatory - -#================================================= -# REINSTALL ARMADIETTO -#================================================= -ynh_script_progression --message="REinstall armadietto with npm..." --weight=1 - -pushd $final_path - ynh_npm -g i armadietto@0.1.5 -popd - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Secure files and directories" --weight=1 - -# Set permissions to app files -chown -R $app:$app "$final_path" -chmod 0700 $datadir -chown $app:$app $datadir +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -125,21 +125,23 @@ ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 yunohost service add $app --description="Armadietto run a remotestorage server as service" --log="/var/log/$app/$app.log" #================================================= -# RELOAD NGINX +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload -#================================================= -# START ARMADIETTO -#================================================= -ynh_script_progression --message="Start armadietto web server..." --weight=1 - -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 139b309..b2bd4c6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -37,6 +37,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # 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 } @@ -66,23 +67,25 @@ fi # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all + ynh_app_setting_delete --app=$app --key=is_public fi # Remove old log file ynh_secure_remove --file="/var/log/$app/" -# -# N.B. : the followings setting migrations snippets are provided as *EXAMPLES* -# of what you may want to do in some cases (e.g. a setting was not defined on -# some legacy installs and you therefore want to initiaze stuff during upgrade) -# +if [ -z "$datadir" ]; then + ynh_script_progression --message="Creating a data directory..." --weight=1 -# If final_path doesn't exist, create it -#if [ -z "$final_path" ]; then -# final_path=/var/www/$app -# ynh_app_setting_set --app=$app --key=final_path --value=$final_path -#fi + ynh_app_setting_set --app=$app --key=datadir --value=$datadir + + # Create app data folder + mkdir -p $datadir + + chmod 750 "$datadir" + chmod -R o-rwx "$datadir" + chown -R $app:www-data "$datadir" +fi #================================================= # CREATE DEDICATED USER @@ -90,18 +93,28 @@ ynh_secure_remove --file="/var/log/$app/" ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # CHECK AND CREATE FINAL_PATH #================================================= ynh_script_progression --message="Setting up and create final app path..." --weight=1 -ynh_app_setting_set $app final_path $final_path - # Create final_path mkdir -p "$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." + +# Create a dedicated NGINX config +ynh_add_nginx_config + #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -113,22 +126,23 @@ ynh_use_nodejs #================================================= # SPECIFIC UPGRADE #================================================= -# CREATE DATA DIRECTORY +# UPGRADE ARMADIETTO #================================================= -if [ -z "$datadir" ]; then - ynh_script_progression --message="Creating a data directory..." --weight=1 +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrade armadietto with npm..." --weight=1 - ynh_app_setting_set --app=$app --key=datadir --value=$datadir - - # Create app data folder - mkdir -p $datadir + pushd $final_path + upstream_version=$(ynh_app_upstream_version) + ynh_npm -g i armadietto@$upstream_version + popd fi #================================================= -# DEFINE ARMADIETTO OPTIONS & CREATE DATA DIRECTORY +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Configuring armadietto as a service..." --weight=2 +ynh_script_progression --message="Updating a configuration file..." --weight=2 # Define armadietto module path module_path="$node_version_path/$nodejs_version/lib/node_modules/armadietto/lib" @@ -138,18 +152,6 @@ ynh_add_config --template="../conf/server.js" --destination="$final_path/server. chmod 400 "$final_path/server.js" chown $app:$app "$final_path/server.js" -#================================================= -# UPGRADE ARMADIETTO -#================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrade armadietto with npm..." --weight=1 - - pushd $final_path - ynh_npm -g i armadietto@0.1.5 - popd -fi - #================================================= # SETUP SYSTEMD #================================================= @@ -163,20 +165,10 @@ ynh_add_systemd_config #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=2 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=2 -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Secure files and directories" --weight=1 - -# Set permissions to app files -chown -R $app:$app "$final_path" -chmod 0700 "$datadir" -chown $app:$app "$datadir" +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -185,6 +177,13 @@ ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="Armadietto run a remotestorage server as service" --log="/var/log/$app/$app.log" +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # RELOAD NGINX #================================================= @@ -192,15 +191,8 @@ ynh_script_progression --message="Reloading NGINX web server..." --weight=2 ynh_systemd_action --service_name=nginx --action=reload -#================================================= -# RESTART ARMADIETTO -#================================================= -ynh_script_progression --message="Start armadietto web server..." --weight=1 - -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Upgrade of $app completed" --last