diff --git a/README.md b/README.md index 08139be..f65d6d3 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,74 @@ -The Lounge for YunoHost -==================== -

- The Lounge -

+# The Lounge for YunoHost - -[![Integration level](https://dash.yunohost.org/integration/thelounge.svg)](https://ci-apps.yunohost.org/jenkins/job/thelounge%20%28Community%29/lastBuild/consoleFull) +[![Integration level](https://dash.yunohost.org/integration/thelounge.svg)](https://dash.yunohost.org/appci/app/thelounge) [![Install The Lounge with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=thelounge) +*[Lire ce readme en français.](./README_fr.md)* + > *This package allow you to install The Lounge 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 Lounge is a self hosted IRC client. +- **Modern features brought to IRC.** Push notifications, link previews, new message markers, and more bring IRC to the 21st century. +- **Always connected.** Remains connected to IRC servers while you are offline. +- **Cross platform.** It doesn't matter what OS you use, it just works wherever Node.js runs. +- **Responsive interface.** The client works smoothly on every desktop, smartphone and tablet. +- **Synchronized experience.** Always resume where you left off no matter what device. +**Shipped version:** 3.2.0 -**Shipped version:** 3.0.0 +## Screenshots -YunoHost specific features --------------------------- +![](https://raw.githubusercontent.com/thelounge/thelounge.github.io/master/img/thelounge-screenshot.png) -### Multi-users support +## Demo -Supported with LDAP. +* [Official demo](https://demo.thelounge.chat/) -### Supported architectures +## Configuration -- Tested on x86_64 -- Tested on ARM +How to configure this app: by an admin panel +## Documentation + * Official documentation: https://thelounge.chat/docs + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-users support + +LDAP is supported + +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/thelounge%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/thelounge/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/thelounge%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/thelounge/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/thelounge%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/thelounge/) + +**More information on the documentation page:** +https://yunohost.org/packaging_apps + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/thelounge_ynh/issues + * App website: https://thelounge.chat/ + * Upstream app repository: https://github.com/thelounge/thelounge + * YunoHost website: https://yunohost.org/ + +--- + +Developers info +---------------- + +**Only if you want to use a testing branch for coding, instead of merging directly into master.** +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/thelounge_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/thelounge_ynh/tree/testing --debug +or +sudo yunohost app upgrade thelounge -u https://github.com/YunoHost-Apps/thelounge_ynh/tree/testing --debug +``` \ No newline at end of file diff --git a/check_process b/check_process index 8e3ccee..ea5f645 100644 --- a/check_process +++ b/check_process @@ -19,24 +19,14 @@ setup_public=1 upgrade=1 upgrade=1 from_commit=7a4ce3de66d44b45ea08e8feb07b925a821ec760 - backup_restore=0 - multi_instance=0 + backup_restore=1 + multi_instance=1 incorrect_path=1 port_already_use=1 - change_url=0 + change_url=1 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Level 4: https://github.com/Rafi594/thelounge_ynh/blob/master/conf/config.js#L391-L452 - Level 4=1 -# Level 5: + # If the level 5 (Package linter) is forced to 1. Please add justifications here. Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options Email= Notification=none diff --git a/conf/app.src b/conf/app.src index 789cda2..e9f7e0f 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/thelounge/thelounge/archive/v3.0.0.tar.gz -SOURCE_SUM=39cd6beaaad732c5dd5cdfabbcb78795406971977b29e109f2afc25e51f2df3f +SOURCE_URL=https://github.com/thelounge/thelounge/archive/v3.2.0.tar.gz +SOURCE_SUM=9dbf6a05f2a30c83b87b3976e318399842ef047314f45725b16ad600c7dc60b1 SOURCE_SUM_PRG=sha256sum ARCH_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/config.js b/conf/config.js index fa7a9f8..0b3b353 100644 --- a/conf/config.js +++ b/conf/config.js @@ -67,7 +67,7 @@ module.exports = { // @type boolean // @default false // - prefetch: false, + prefetch: true, // // Store and proxy prefetched images and thumbnails. @@ -84,7 +84,7 @@ module.exports = { // @type boolean // @default false // - prefetchStorage: false, + prefetchStorage: true, // // Prefetch URLs Image Preview size limit diff --git a/conf/pull_request_template.md b/conf/pull_request_template.md new file mode 100644 index 0000000..f8635f5 --- /dev/null +++ b/conf/pull_request_template.md @@ -0,0 +1,18 @@ +## Problem +- *Description of why you made this PR* + +## Solution +- *And how do you fix that problem* + +## PR Status +- [ ] Code finished. +- [ ] Tested with Package_check. +- [ ] Fix or enhancement tested. +- [ ] Upgrade from last version tested. +- [ ] Can be reviewed and tested. + +## Package_check results +--- +*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* + +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/APP_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/APP_ynh%20PR-NUM-%20(USERNAME)/) \ No newline at end of file diff --git a/manifest.json b/manifest.json index 8efcedf..edd3c21 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "The Lounge is a web IRC client.", "fr": "The Lounge est un client web IRC." }, - "version": "3.0.0~ynh1", + "version": "3.2.0~ynh1", "url": "https://thelounge.chat/", "license": "MIT", "maintainer": { @@ -19,7 +19,7 @@ "email": "beudbeud@beudibox.fr" }, "requirements": { - "yunohost": ">= 3.3.3" + "yunohost": ">= 3.5" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..1bfd2f0 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= + +# nodejs version +nodejs_version=8 + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= \ No newline at end of file diff --git a/scripts/_variables b/scripts/_variables deleted file mode 100644 index 16181df..0000000 --- a/scripts/_variables +++ /dev/null @@ -1 +0,0 @@ -nodejs_version=8 diff --git a/scripts/backup b/scripts/backup index d8e5bf5..3466358 100644 --- a/scripts/backup +++ b/scripts/backup @@ -19,7 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -29,45 +29,59 @@ domain=$(ynh_app_setting_get $app domain) #================================================= # STANDARD BACKUP STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_print_info "Backing up the main app directory..." +ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_print_info "Backing up nginx web server configuration..." +ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= # BACKUP LOGROTATE #================================================= -ynh_print_info "Backing up logrotate configuration..." +ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 -ynh_backup "/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_print_info "Backing up systemd configuration..." +ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 -ynh_backup "/etc/systemd/system/$app.service" +ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= # BACKUP CONFIG #================================================= -ynh_print_info "Backing up config path..." +ynh_script_progression --message="Backing up config path..." --time --weight=1 -ynh_backup "$config_path" +ynh_backup --src_path="$config_path" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..2cae48c --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,117 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$YNH_APP_NEW_PATH + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 + +# 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 +#db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name +#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +if [ $change_path -eq 1 ] +then + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# ... +#================================================= + +#================================================= +# GENERIC FINALISATION +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --time --last \ No newline at end of file diff --git a/scripts/install b/scripts/install index 5a117d1..917f284 100644 --- a/scripts/install +++ b/scripts/install @@ -6,7 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -source _variables source _common.sh source /usr/share/yunohost/helpers @@ -40,6 +39,15 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +### About --weight and --time +### ynh_script_progression will show to your final users the progression of each scripts. +### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script. +### --time is a packager option, it will show you the execution time since the previous call. +### This option should be removed before releasing your app. +### Use the execution time, given by --time, to estimate the weight of a step. +### A common way to do it is to set a weight equal to the execution time in second +1. +### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. +ynh_script_progression --message="Validating installation parameters..." --time --weight=1 final_path=/var/www/$app config_path=/home/yunohost.app/$app/ @@ -56,17 +64,18 @@ ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." --time --weight=1 -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app is_public $is_public - +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_public --value=$is_public #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Configuring firewall..." --time --weight=1 # Find a free port port=$(ynh_find_port 9009) @@ -77,47 +86,23 @@ ynh_app_setting_set $app port $port #================================================= # INSTALL DEPENDENCIES #================================================= - +ynh_script_progression --message="Installing dependencies..." --time --weight=1 ynh_install_nodejs $nodejs_version #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --time --weight=1 -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set --app=$app --key=final_path --value=$final_path mkdir -p $final_path mkdir -p $config_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source $final_path +ynh_setup_source --dest_dir="$final_path" #================================================= -# NGINX CONFIGURATION -#================================================= - -# Create a dedicated nginx config -ynh_add_nginx_config - -#================================================= -# CREATE DEDICATED USER -#================================================= - -# Create a system user -ynh_system_user_create $app - -#================================================= -# SETUP SYSTEMD -#================================================= - -# Create a dedicated systemd config -ynh_use_nodejs -ynh_replace_string "__NODEJS__" "$nodejs_version" "../conf/systemd.service" -ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" -ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" -ynh_add_systemd_config - -#================================================= -# MODIFY A CONFIG FILE +# COPY A CONFIG FILE #================================================= cp -a ../conf/config.js $config_path @@ -125,7 +110,9 @@ cp -a ../conf/config.js $config_path #================================================= # INSTALL THE LOUNGE #================================================= -cd $final_path +ynh_script_progression --message="Installing The Lounge..." --time --weight=1 + +pushd $final_path npm install --unsafe-perm # Install webpack @@ -136,6 +123,36 @@ npm install copy-webpack-plugin # Build The Lounge NODE_ENV=production npm run build +popd + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --time --weight=1 + +# Create a system user +ynh_system_user_create $app + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." --time --weight=1 + +# Create a dedicated systemd config +ynh_use_nodejs +ynh_replace_string "__NODEJS__" "$nodejs_version" "../conf/systemd.service" +ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" +ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" +ynh_add_systemd_config + #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= @@ -156,6 +173,7 @@ chown -R $app: $config_path #================================================= # SETUP LOGROTATE #================================================= +ynh_script_progression --message="Configuring log rotation..." --time --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate @@ -164,26 +182,55 @@ ynh_use_logrotate # ADVERTISE SERVICE IN ADMIN PANEL #================================================= +### `yunohost service add` is a CLI yunohost command to add a service in the admin panel. +### You'll find the service in the 'services' section of YunoHost admin panel. +### This CLI command would be useless if the app does not have any services (systemd or sysvinit) +### If you're not using these lines: +### - You can remove these files in conf/. +### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script +### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script +yunohost service add $app --log "/var/log/$app/$app.log" +# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added +#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +### `ynh_systemd_action` is used to start a systemd service for an app. +### Only needed if you have configure a systemd service +### If you're not using these lines: +### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script +### - As well as the section "START SYSTEMD SERVICE" in the restore script +### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script +### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 -if [ $is_public -eq 0 ] -then # Remove the public access - ynh_app_setting_delete $app skipped_uris -fi # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= -systemctl start thelounge -sleep 20 -systemctl reload nginx +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --time --last diff --git a/scripts/remove b/scripts/remove index 67a238d..ecbd0d3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,50 +12,63 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +# Remove a service from the admin panel, added by `yunohost service add` +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service..." --time --weight=1 + yunohost service remove $app +fi + #================================================= # STOP AND REMOVE SERVICE #================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." --time --weight=1 # Remove the dedicated systemd config ynh_remove_systemd_config #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." --time --weight=1 -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi +# Remove metapackage and its dependencies +ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." --time --weight=1 # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config - #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 # Remove the app-specific logrotate config ynh_remove_logrotate @@ -66,23 +79,27 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then - echo "Close port $port" - yunohost firewall disallow TCP $port 2>&1 + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port fi #================================================= # SPECIFIC REMOVE #================================================= -ynh_use_nodejs -npm uninstall $app -ynh_remove_nodejs - #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1 # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --time --last + diff --git a/scripts/restore b/scripts/restore index 04ff82b..f6c3182 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,4 +1,3 @@ - #!/bin/bash #================================================= @@ -20,7 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -32,12 +31,12 @@ config_path=$(ynh_app_setting_get $app config_path) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -45,22 +44,22 @@ test ! -d $final_path \ # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_print_info "Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS @@ -75,44 +74,55 @@ chown -R $app: $config_path #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_print_info "Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 ynh_install_nodejs $nodejs_version #================================================= # RESTORE THE CONFIG #================================================= -ynh_print_info "Restoring the config path..." +ynh_script_progression --message="Restoring the config path..." --time --weight=1 -ynh_restore_file "$config_path" +ynh_restore_file --origin_path="$config_path" #================================================= # RESTORE SYSTEMD #================================================= -ynh_print_info "Restoring the systemd configuration..." +ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 -ynh_restore_file "/etc/systemd/system/$app.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app --log "/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_restore_file "/etc/logrotate.d/$app" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PHP-FPM +# RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server and The Lounge..." +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl restart thelounge -sleep 4 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Restoration completed for $app" \ No newline at end of file +ynh_script_progression --message="Restoration completed for $app" --time --last \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index cf14a6f..085c259 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,11 +8,11 @@ source _common.sh source /usr/share/yunohost/helpers -source _variables #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -22,34 +22,49 @@ is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) +#================================================= +# CHECK VERSION +#================================================= + +### This helper will compare the version of the currently installed app and the version of the upstream package. +### $upgrade_type can have 2 different values +### - UPGRADE_APP if the upstream app version has changed +### - UPGRADE_PACKAGE if only the YunoHost package has changed +### ynh_check_app_version_changed will stop the upgrade if the app is up to date. +### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # If config_path doesn't exist, create it -if [ -z $config_path ]; then - config_path=/home/yunohost.app/$app - ynh_app_setting_set $app config_path $config_path +if [ -z "$config_path" ]; then + final_path=/home/yunohost.app/$app + ynh_app_setting_set --app=$app --key=final_path --value=$config_path fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -70,9 +85,55 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --time --weight=1 + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi + +#================================================= +# UPGRADE NODEJS +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 + +ynh_cron_upgrade_node + +#================================================= +# UPGRADE THE LOUNGE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then +pushd $final_path +npm install --unsafe-perm + +# Install webpack +npm upgrade webpack +npm upgrade webpack-cli +npm upgrade copy-webpack-plugin + +# Build The Lounge +NODE_ENV=production npm run build + +popd +fi + #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 # Create a dedicated nginx config ynh_add_nginx_config @@ -80,16 +141,10 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 # Create a system user -ynh_system_user_create $app - -#================================================= -# UPGRADE NODEJS -#================================================= - -systemctl stop thelounge -ynh_cron_upgrade_node +ynh_system_user_create --username=$app #================================================= # SETUP SYSTEMD @@ -101,33 +156,14 @@ ynh_replace_string "__NODEJS__" "$nodejs_version" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" ynh_add_systemd_config -cat /etc/systemd/system/$app.service -echo $nodejs_version -echo $PATH -echo $nodejs_path #================================================= -# MODIFY A CONFIG FILE +# CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 -cp -a ../conf/config.js $config_path - -#================================================= -# UPGRADE THE LOUNGE -#================================================= - - -ynh_setup_source $final_path -cd $final_path -npm install --unsafe-perm - -# Install webpack -npm upgrade webpack -npm upgrade webpack-cli -npm upgrade copy-webpack-plugin - -# Build The Lounge -NODE_ENV=production npm run build +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= # SPECIFIC UPGRADE @@ -135,14 +171,22 @@ NODE_ENV=production npm run build # ... #================================================= -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$config_path/config.js" -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$config_path/config.js" +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. +### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. +ynh_backup_if_checksum_is_different --file="$config_path/config.js" +# Recalculate and store the checksum of the file for the next upgrade. +ynh_store_file_checksum --file="$config_path/config.js" + +cp -a ../conf/config.js $config_path #================================================= # SETUP LOGROTATE #================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -160,22 +204,31 @@ chown -R $app: $config_path #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1 -if [ $is_public -eq 0 ] -then # Remove the public access - ynh_app_setting_delete $app skipped_uris -fi # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl start thelounge -sleep 30 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --time --last