From 22c24235ce5fe5372d73a86c6b2edb301783e491 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 11 Sep 2020 14:26:42 +0200 Subject: [PATCH 01/27] libcurl4-openssl-dev -> libcurl4-dev We're trying to fix some weird cross-apps conflicts because of stupid dependency conflicts ... in particular various app require different versions of libcurl4-*-dev conflicting with each other, but it should be fine to just request libcurl4-dev --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b1c3267..f474c78 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,7 +4,7 @@ # COMMON VARIABLES #================================================= -pkg_dependencies="g++ libjemalloc1|libjemalloc2 libjemalloc-dev zlib1g-dev libreadline-dev libpq-dev libssl-dev libyaml-dev libcurl4-openssl-dev libapr1-dev libxslt1-dev libxml2-dev vim imagemagick postgresql postgresql-server-dev-all postgresql-contrib optipng jhead jpegoptim gifsicle brotli" +pkg_dependencies="g++ libjemalloc1|libjemalloc2 libjemalloc-dev zlib1g-dev libreadline-dev libpq-dev libssl-dev libyaml-dev libcurl4-dev libapr1-dev libxslt1-dev libxml2-dev vim imagemagick postgresql postgresql-server-dev-all postgresql-contrib optipng jhead jpegoptim gifsicle brotli" RUBY_VERSION="2.6.5" From 70c8053cd7400774e2bcc3f59f8630bfbbf4b3cd Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Mon, 23 Nov 2020 10:54:52 +0100 Subject: [PATCH 02/27] [fix] no SSO --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9be4c9e..addd414 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Discourse can now receive mail from `foo@theirexternalmail.com` and give it to t #### Multi-user support -Supported, with LDAP and SSO. +Supported, with LDAP (no SSO). ![Login Popup](https://raw.githubusercontent.com/jonmbake/screenshots/master/discourse-ldap-auth/login.png) From ac0ccbc7c9aef20d1266f694ed750b9656d36f71 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 01:39:02 +0100 Subject: [PATCH 03/27] Apply example_ynh --- README.md | 4 ++-- check_process | 5 ----- issue_template.md | 37 +++++++++++++++++++++++-------------- manifest.json | 4 ++-- pull_request_template.md | 4 +--- scripts/backup | 2 +- scripts/change_url | 18 +++++++++--------- scripts/install | 14 +++++++------- scripts/remove | 6 +++--- scripts/restore | 10 +++++----- scripts/upgrade | 35 ++++++++++++++++++++--------------- 11 files changed, 73 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index f582caf..7224a28 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Discourse for YunoHost [![Integration level](https://dash.yunohost.org/integration/discourse.svg)](https://dash.yunohost.org/appci/app/discourse) ![](https://ci-apps.yunohost.org/ci/badges/discourse.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/discourse.maintain.svg) -[![Install Discourse with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=discourse) +[![Install Discourse with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=discourse) > *This package allows you to install Discourse quickly and simply on a YunoHost server. If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* @@ -133,7 +133,7 @@ systemctl restart discourse ## Links * Report a bug: https://github.com/YunoHost-Apps/discourse_ynh/issues - * Discourse website: https://discourse.org/ + * App website: https://discourse.org/ * Upstream app repository: https://github.com/discourse/discourse * YunoHost website: https://yunohost.org/ diff --git a/check_process b/check_process index 0707237..f80a808 100644 --- a/check_process +++ b/check_process @@ -19,13 +19,8 @@ backup_restore=1 # Activate multi-instance test only if you have more than 2Gb RAM! multi_instance=1 - # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. - # incorrect_path=1 port_already_use=0 change_url=1 -;;; Levels - # If the level 5 (Package linter) is forced to 1. Please add justifications here. - Level 5=auto ;;; Options Email= Notification=none diff --git a/issue_template.md b/issue_template.md index 8a7c77f..75fc3f2 100644 --- a/issue_template.md +++ b/issue_template.md @@ -1,32 +1,34 @@ --- name: Bug report -about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. +about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. --- **How to post a meaningful bug report** 1. *Read this whole template first.* 2. *Determine if you are on the right place:* - - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* - - *Otherwise, the issue may be due to Discourse itself. Refer to its documentation or repository for help.* - - *If you have a doubt, post here, we will figure it out together.* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* + - *Otherwise, the issue may be due to discourse itself. Refer to its documentation or repository for help.* + - *When in doubt, post here and we will figure it out together.* 3. *Delete the italic comments as you write over them below, and remove this guide.* --- -**Describe the bug** +### Describe the bug + *A clear and concise description of what the bug is.* -**Versions** +### Context + - Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* - YunoHost version: x.x.x - I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* -- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes* - If yes, please explain: - Using, or trying to install package version/branch: - If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* -**To Reproduce** -*Steps to reproduce the behavior.* +### Steps to reproduce + - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh sudo yunohost app install discourse @@ -34,13 +36,20 @@ about: Create a report to help us debug, it would be nice to fill the template a - *If you used the webadmin, please perform the equivalent command from the CLI first.* - *If the error occurs in your browser, explain what you did:* 1. *Go to '...'* - 2. *Click on '....'* - 3. *Scroll down to '....'* + 2. *Click on '...'* + 3. *Scroll down to '...'* 4. *See error* -**Expected behavior** +### Expected behavior + *A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* -**Logs** -*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +### Logs + +*When an operation fails, YunoHost provides a simple way to share the logs.* +- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* +- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* + +*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* + *If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index 5c21da1..84adb18 100644 --- a/manifest.json +++ b/manifest.json @@ -30,7 +30,7 @@ "en": "Choose a domain name for Discourse", "fr": "Choisissez un nom de domaine pour Discourse" }, - "example": "domain.org" + "example": "example.com" }, { "name": "path", @@ -49,7 +49,7 @@ "en": "Choose an admin user", "fr": "Choisissez l'administrateur" }, - "example": "homer" + "example": "johndoe" }, { "name": "is_public", diff --git a/pull_request_template.md b/pull_request_template.md index 55e358e..6c28fc5 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -13,6 +13,4 @@ ## 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/discourse_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/discourse_ynh%20PR-NUM-%20(USERNAME)/) +* An automatic package_check will be launch at https://ci-apps-dev.yunohost.org/, when you add a specific comment to your Pull Request: "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!"* diff --git a/scripts/backup b/scripts/backup index 18653c8..d9f717e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 diff --git a/scripts/change_url b/scripts/change_url index b163620..54ac2e8 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -38,7 +38,7 @@ unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -46,7 +46,7 @@ ynh_clean_setup () { # 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" - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -80,19 +80,19 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." +ynh_script_progression --message="Updating NGINX web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the path in the nginx config file +# 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 + # 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 + # Set global variables for NGINX helper domain="$old_domain" path_url="$new_path" - # Create a dedicated nginx config + # Create a dedicated NGINX config ynh_add_nginx_config # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 if [ "$path_url" != "/" ] ; then @@ -101,7 +101,7 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" fi -# Change the domain for nginx +# Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location @@ -153,7 +153,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/ #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/install b/scripts/install index 5cdc028..bf7e674 100644 --- a/scripts/install +++ b/scripts/install @@ -53,7 +53,6 @@ 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 ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # STANDARD MODIFICATIONS @@ -112,9 +111,9 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." +ynh_script_progression --message="Configuring NGINX web server..." -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 @@ -352,19 +351,20 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/ #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring permissions..." # 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=$app --key=skipped_uris --value="/" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/remove b/scripts/remove index 73a031d..d53ebc5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -31,7 +31,7 @@ redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." + ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi @@ -84,9 +84,9 @@ 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 #================================================= diff --git a/scripts/restore b/scripts/restore index 8317aed..b9763ee 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 @@ -52,7 +52,7 @@ check_memory_requirements #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the nginx configuration..." +ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -125,7 +125,7 @@ ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl daemon-reload -systemctl enable $app.service +systemctl enable $app.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -150,7 +150,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/ #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Restoring logrotate configuration..." +ynh_script_progression --message="Restoring the logrotate configuration..." ynh_restore_file --origin_path="/etc/logrotate.d/$app" @@ -159,7 +159,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 7fe1cc5..87bb015 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,7 +19,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) admin=$(ynh_app_setting_get --app=$app --key=admin) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) @@ -55,6 +54,13 @@ then ynh_app_setting_set --app=$app --key=unicorn_workers --value=$unicorn_workers 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 + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -63,7 +69,8 @@ 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 () { - # restore it if the upgrade fails + ynh_clean_check_starting + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -151,9 +158,9 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading NGINX web server configuration..." -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 @@ -167,7 +174,7 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies #================================================= # INSTALL RUBY @@ -332,6 +339,7 @@ fi #================================================= # SETUP SYSTEMD #================================================= + if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Configuring a systemd service..." @@ -375,16 +383,14 @@ chown -R $app: $final_path chmod g-w $final_path/log #================================================= -# SETUP SSOWAT +# SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." +ynh_script_progression --message="Upgrading logrotate configuration..." -# If app is public, add url to SSOWat conf as skipped_uris -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" skipped_uris "/" -fi +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --logfile="$final_path/log/unicorn.stderr.log" +ynh_use_logrotate --logfile="$final_path/log/unicorn.stdout.log" +ynh_use_logrotate --logfile="$final_path/log/production.log" #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -398,7 +404,6 @@ yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_pat #================================================= ynh_script_progression --message="Starting a systemd service..." -# Wait for discourse to be fully started ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" #================================================= @@ -411,7 +416,7 @@ ynh_maintenance_mode_OFF #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload From c5aaef69e52334e2b250a2c95afa55994731660d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 01:41:05 +0100 Subject: [PATCH 04/27] Prevent check_memory requirement during package_check --- scripts/install | 6 ++++-- scripts/restore | 6 ++++-- scripts/upgrade | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index bf7e674..521f71c 100644 --- a/scripts/install +++ b/scripts/install @@ -42,8 +42,10 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url -# Check memory requirements -check_memory_requirements +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then + # Check memory requirements + check_memory_requirements +fi #================================================= # STORE SETTINGS FROM MANIFEST diff --git a/scripts/restore b/scripts/restore index b9763ee..c62b963 100644 --- a/scripts/restore +++ b/scripts/restore @@ -44,8 +44,10 @@ ynh_webpath_available --domain=$domain --path_url=$path_url \ test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " -# Check memory requirements -check_memory_requirements +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then + # Check memory requirements + check_memory_requirements +fi #================================================= # STANDARD RESTORATION STEPS diff --git a/scripts/upgrade b/scripts/upgrade index 87bb015..fc6fab7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,8 +25,10 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) -# Check memory requirements -check_memory_requirements_upgrade +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then + # Check memory requirements + check_memory_requirements_upgrade +fi #================================================= # CHECK VERSION From 111d8899b129e849b9ef2a9806141c08c8cd5ecb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 01:47:27 +0100 Subject: [PATCH 05/27] Spacing normalization --- scripts/change_url | 10 +++++----- scripts/install | 36 ++++++++++++++++++------------------ scripts/restore | 4 ++-- scripts/upgrade | 18 +++++++++--------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 54ac2e8..ce73aaf 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -104,11 +104,11 @@ 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" + # 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 #================================================= diff --git a/scripts/install b/scripts/install index 521f71c..5a36f2e 100644 --- a/scripts/install +++ b/scripts/install @@ -43,8 +43,8 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then - # Check memory requirements - check_memory_requirements + # Check memory requirements + check_memory_requirements fi #================================================= @@ -88,11 +88,11 @@ ynh_script_progression --message="Setting up source files..." # Specific actions on ARM architecture if [ -n "$(uname -m | grep arm)" ] ; then - # Unapply commit cf9b4a789b855b5199e98a13424e409854a8e848 that breaks ARM - # compatibility by pointing to a recent libv8 version - # This is due to this libv8 issue (https://github.com/cowboyd/libv8/issues/261) - # that prevents it from being compiled on ARM hence no binary gem is available yet - cp ../sources/patches_arm/* ../sources/patches + # Unapply commit cf9b4a789b855b5199e98a13424e409854a8e848 that breaks ARM + # compatibility by pointing to a recent libv8 version + # This is due to this libv8 issue (https://github.com/cowboyd/libv8/issues/261) + # that prevents it from being compiled on ARM hence no binary gem is available yet + cp ../sources/patches_arm/* ../sources/patches fi ynh_app_setting_set --app=$app --key=final_path --value=$final_path @@ -120,7 +120,7 @@ ynh_add_nginx_config # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 if [ "$path_url" != "/" ] ; then - ynh_replace_string --match_string='$proxy_add_x_forwarded_for' --replace_string='$http_your_original_ip_header' --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_replace_string --match_string='$proxy_add_x_forwarded_for' --replace_string='$http_your_original_ip_header' --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" fi ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -199,17 +199,17 @@ ynh_store_file_checksum --file="$final_path/config/secrets.yml" chown -R $app: $final_path pushd "$final_path" - # Install bundler, a gems installer - gem install bundler - # Install without documentation - exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" + # Install bundler, a gems installer + gem install bundler + # Install without documentation + exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" popd # Specific actions on ARM architecture if [ -n "$(uname -m | grep arm)" ] ; then - # Define the platform specifically to retrieve binaries - # for libv8 because it currently doesn't compile on ARM devices - exec_login_as $app bundle config specific_platform arm-linux + # Define the platform specifically to retrieve binaries + # for libv8 because it currently doesn't compile on ARM devices + exec_login_as $app bundle config specific_platform arm-linux fi # Install dependencies @@ -220,9 +220,9 @@ exec_login_as $app MAKEFLAGS=-j2 bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible if [ -n "$(uname -m | grep arm)" ] ; then - (cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor - rm libpsl.so - ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so) + (cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor + rm libpsl.so + ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so) fi #================================================= diff --git a/scripts/restore b/scripts/restore index c62b963..900c267 100644 --- a/scripts/restore +++ b/scripts/restore @@ -45,8 +45,8 @@ test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then - # Check memory requirements - check_memory_requirements + # Check memory requirements + check_memory_requirements fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index fc6fab7..bcf6b90 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -167,7 +167,7 @@ ynh_add_nginx_config # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 if [ "$path_url" != "/" ] ; then - ynh_replace_string --match_string='$proxy_add_x_forwarded_for' --replace_string='$http_your_original_ip_header' --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_replace_string --match_string='$proxy_add_x_forwarded_for' --replace_string='$http_your_original_ip_header' --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" fi ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -288,9 +288,9 @@ then ) # Specific actions on ARM architecture if [ -n "$(uname -m | grep arm)" ] ; then - # Define the platform specifically to retrieve binaries - # for libv8 because it currently doesn't compile on ARM devices - exec_login_as $app bundle config specific_platform arm-linux + # Define the platform specifically to retrieve binaries + # for libv8 because it currently doesn't compile on ARM devices + exec_login_as $app bundle config specific_platform arm-linux fi # Install dependencies exec_login_as $app bundle config set path 'vendor/bundle' @@ -300,11 +300,11 @@ then # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible if [ -n "$(uname -m | grep arm)" ] ; then - ( - cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor - rm libpsl.so - ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so - ) + ( + cd $final_path/vendor/bundle/ruby/*/gems/mini_suffix-*/vendor + rm libpsl.so + ln -s $(ldconfig -p | grep libpsl | awk 'END {print $NF}') libpsl.so + ) fi fi From 4454382b0cdbe28988fd2478d55e9ade89c0ecf8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 01:55:03 +0100 Subject: [PATCH 06/27] Implement ynh_add_config --- scripts/install | 6 ++---- scripts/upgrade | 14 +++----------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/scripts/install b/scripts/install index 5a36f2e..7d6154f 100644 --- a/scripts/install +++ b/scripts/install @@ -190,10 +190,8 @@ echo "svgo: false" > $final_path/.image_optim.yml ynh_script_progression --message="Setting up Unicorn..." # Set a secret value -cp ../conf/secrets.yml "$final_path/config/secrets.yml" -ynh_replace_string --match_string="__SECRET__" --replace_string="$(ynh_string_random)" --target_file="$final_path/config/secrets.yml" -# Calculate and store the config file checksum -ynh_store_file_checksum --file="$final_path/config/secrets.yml" +secret="$(ynh_string_random)" +ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files chown -R $app: $final_path diff --git a/scripts/upgrade b/scripts/upgrade index bcf6b90..fbe60ae 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -262,19 +262,11 @@ then # Make a backup of the original config file if modified ynh_backup_if_checksum_is_different "$unicorn_config_file" - # Calculate and store the config file checksum + # Calculate and store the config file checksum ynh_store_file_checksum --file="$unicorn_config_file" - secret_config_file="$final_path/config/secrets.yml" - # Make a backup of the original config file if modified - ynh_backup_if_checksum_is_different "$secret_config_file" - - # Set a secret value - cp ../conf/secrets.yml "$final_path/config/secrets.yml" - ynh_replace_string --match_string="__SECRET__" --replace_string="$(ynh_string_random)" --target_file="$secret_config_file" - - # Calculate and store the config file checksum - ynh_store_file_checksum --file="$secret_config_file" + secret="$(ynh_string_random)" + ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files chown -R $app: $final_path From f455626b85bbb7a0e018cccdfc2286f3d60233d6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 8 Mar 2021 21:38:47 +0100 Subject: [PATCH 07/27] Implement new ynh_install_ruby --- scripts/_common.sh | 331 ++++++++++++++++++++++++++++----------------- scripts/change_url | 3 +- scripts/install | 19 +-- scripts/restore | 9 +- scripts/upgrade | 17 +-- 5 files changed, 222 insertions(+), 157 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index ecc6bb3..3c3e2d2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -163,46 +163,126 @@ ynh_maintenance_mode_OFF () { # RUBY HELPER #================================================= +rbenv_version=1.1.2 +ruby_build_version=20201225 +rbenv_aliases_version=1.1.0 rbenv_install_dir="/opt/rbenv" +ruby_version_path="$rbenv_install_dir/versions" # RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. export RBENV_ROOT="$rbenv_install_dir" -# Install ruby version management +# Install Ruby Version Management # # [internal] # # usage: ynh_install_rbenv +# +# Requires YunoHost version 2.7.12 or higher. ynh_install_rbenv () { - echo "Installation of rbenv - ruby version management" >&2 - # Build an app.src for rbenv - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v1.1.2.tar.gz + ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${ruby_build_version}" + + # Build an app.src for rbenv + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v${rbenv_version}.tar.gz SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > "../conf/rbenv.src" - # Download and extract rbenv - ynh_setup_source "$rbenv_install_dir" rbenv + # Download and extract rbenv + ynh_setup_source --dest_dir="$rbenv_install_dir" --source_id=rbenv - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20200520.tar.gz -SOURCE_SUM=52be6908a94fbd4a94f5064e8b19d4a3baa4b773269c3884165518d83bcc8922" > "../conf/ruby-build.src" - # Download and extract ruby-build - ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build + # Build an app.src for ruby-build + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v${ruby_build_version}.tar.gz +SOURCE_SUM=54cae123c2758e7714c66aca7ef8bc7f29cda8583891191ceb3053c6d098ecf1" > "../conf/ruby-build.src" + # Download and extract ruby-build + ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/ruby-build" --source_id=ruby-build - (cd $rbenv_install_dir - ./src/configure && make -C src) + # Build an app.src for rbenv-aliases + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz +SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > "../conf/rbenv-aliases.src" + # Download and extract rbenv-aliases + ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases -# Create shims directory if needed -if [ ! -d $rbenv_install_dir/shims ] ; then - mkdir $rbenv_install_dir/shims -fi + (cd $rbenv_install_dir + ./src/configure && make -C src) + + # Create shims directory if needed + if [ ! -d $rbenv_install_dir/shims ] ; then + mkdir $rbenv_install_dir/shims + fi } -# Install a specific version of ruby +# Load the version of Ruby for an app, and set variables. # -# ynh_install_ruby will install the version of ruby provided as argument by using rbenv. +# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. +# This helper will provide alias and variables to use in your scripts. # -# rbenv (ruby version management) stores the target ruby version in a .ruby_version file created in the target folder (using rbenv local ) -# It then uses that information for every ruby user that uses rbenv provided ruby command +# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby` +# Those alias will use the correct version installed for the app +# For example: use `ynh_gem install` instead of `gem install` +# +# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_ruby` +# And propagate $PATH to sudo with $ynh_ruby_load_path +# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install` +# +# $PATH contains the path of the requested version of Ruby. +# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH +# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version +# in $PATH for an usage into a separate script. +# Exemple: $ynh_ruby_load_path $final_path/script_that_use_gem.sh` +# +# +# Finally, to start a Ruby service with the correct version, 2 solutions +# Either the app is dependent of Ruby or gem, but does not called it directly. +# In such situation, you need to load PATH +# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"` +# `ExecStart=__FINALPATH__/my_app` +# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path +# +# Or Ruby start the app directly, then you don't need to load the PATH variable +# `ExecStart=__YNH_RUBY__ my_app run` +# You will replace __YNH_RUBY__ with $ynh_ruby +# +# +# one other variable is also available +# - $ruby_path: The absolute path to Ruby binaries for the chosen version. +# +# usage: ynh_use_ruby +# +# Requires YunoHost version 2.7.12 or higher. +ynh_use_ruby () { + ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) + + # Get the absolute path of this version of Ruby + ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" + + # Allow alias to be used into bash script + shopt -s expand_aliases + + # Create an alias for the specific version of Ruby and a variable as fallback + ynh_ruby="$ruby_path/ruby" + alias ynh_ruby="$ynh_ruby" + # And gem + ynh_gem="$ruby_path/gem" + alias ynh_gem="$ynh_gem" + + # Load the path of this version of Ruby in $PATH + if [[ :$PATH: != *":$ruby_path"* ]]; then + PATH="$ruby_path:$PATH" + fi + # Create an alias to easily load the PATH + ynh_ruby_load_path="PATH=$PATH" + + # Sets the local application-specific Ruby version + (cd $final_path + rbenv local $ruby_version) +} + +# Install a specific version of Ruby +# +# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. +# +# rbenv (Ruby Version Management) stores the target Ruby version in a .ruby_version file created in the target folder (using rbenv local ) +# It then uses that information for every Ruby user that uses rbenv provided Ruby command # # This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv # for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) @@ -212,142 +292,141 @@ fi # When not possible (e.g. in systemd service definition), please use direct path # to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) # -# usage: ynh_install_ruby ruby_version user +# usage: ynh_install_ruby --ruby_version=ruby_version # | arg: -v, --ruby_version= - Version of ruby to install. -# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0). -# The crontab will handle the update of minor versions when needed. +# +# Requires YunoHost version 2.7.12 or higher. ynh_install_ruby () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [v]=ruby_version= ) - # Use rbenv, https://github.com/rbenv/rbenv to manage the ruby versions - local ruby_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=v + local -A args_array=( [v]=ruby_version= ) + local ruby_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Create $rbenv_install_dir - mkdir -p "$rbenv_install_dir/plugins/ruby-build" + # Store ruby_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version - # Load rbenv path in PATH - CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + # Create $rbenv_install_dir if doesn't exist already + mkdir -p "$rbenv_install_dir/plugins/ruby-build" - # Remove /usr/local/bin in PATH in case of ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - # Move an existing ruby binary, to avoid to block rbenv - test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - # If rbenv is not previously setup, install it - if ! type rbenv > /dev/null 2>&1 - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt "1.1.2" - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt "20200520" - then - ynh_install_rbenv - fi + # Move an existing Ruby binary, to avoid to block rbenv + test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - # Restore /usr/local/bin in PATH (if needed) - PATH=$CLEAR_PATH + # If rbenv is not previously setup, install it + if ! type rbenv > /dev/null 2>&1 + then + ynh_install_rbenv + elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt $rbenv_version + then + ynh_install_rbenv + elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt $ruby_build_version + then + ynh_install_rbenv + fi - # And replace the old ruby binary - test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH - # Install the requested version of ruby - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version + # And replace the old Ruby binary + test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby - # Store the ID of this app and the version of ruby requested for it - echo "$YNH_APP_ID:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version" + # Install the requested version of Ruby + ynh_print_info --message="Installation of Ruby-"$ruby_version + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version - # Store ruby_version into the config of this app - ynh_app_setting_set $app ruby_version $ruby_version + # Remove app virtualenv + if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME" 1>/dev/null 2>&1` + then + rbenv alias $YNH_APP_INSTANCE_NAME --remove + fi - # Set environment for ruby users - echo "#rbenv + # Create app virtualenv + rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby + + # Set environment for Ruby users + echo "#rbenv export RBENV_ROOT=$rbenv_install_dir export PATH=\"$rbenv_install_dir/bin:$PATH\" eval \"\$(rbenv init -)\" -#rbenv" > /etc/profile.d/rbenv.sh + #rbenv" > /etc/profile.d/rbenv.sh - # Load the right environment for the Installation - eval "$(rbenv init -)" - - (cd $final_path - rbenv local $ruby_version) + # Load the environment + eval "$(rbenv init -)" } -# Remove the version of ruby used by the app. +# Remove the version of Ruby used by the app. # -# This helper will check if another app uses the same version of ruby, -# if not, this version of ruby will be removed. -# If no other app uses ruby, rbenv will be also removed. +# This helper will also cleanup Ruby versions # # usage: ynh_remove_ruby ynh_remove_ruby () { - ruby_version=$(ynh_app_setting_get $app ruby_version) + local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) - # Remove the line for this app - sed --in-place "/$YNH_APP_ID:$ruby_version/d" "$rbenv_install_dir/ynh_app_version" + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - # If no other app uses this version of ruby, remove it. - if ! grep --quiet "$ruby_version" "$rbenv_install_dir/ynh_app_version" - then - $rbenv_install_dir/bin/rbenv uninstall --force $ruby_version - fi + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - # Remove rbenv environment configuration - rm /etc/profile.d/rbenv.sh + rbenv alias $YNH_APP_INSTANCE_NAME --remove - # If no other app uses rbenv, remove rbenv and dedicated group - if [ ! -s "$rbenv_install_dir/ynh_app_version" ] - then - ynh_secure_remove "$rbenv_install_dir" - fi + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby } -# Remove the version of ruby used by the app. +# Remove no more needed versions of Ruby used by the app. # -# This helper will check if another app uses the same version of ruby, -# if not, this version of ruby will be removed. -# If no other app uses ruby, rbenv will be also removed. +# This helper will check what Ruby version are no more required, +# and uninstall them +# If no app uses Ruby, rbenv will be also removed. # -# usage: ynh_remove_ruby -ynh_remove_ruby () { - ruby_version=$(ynh_app_setting_get $app ruby_version) +# usage: ynh_cleanup_ruby +ynh_cleanup_ruby () { - # Remove the line for this app - sed --in-place "/$YNH_APP_ID:$ruby_version/d" "$rbenv_install_dir/ynh_app_version" + # List required Ruby version + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_ruby_versions="" + for installed_app in $installed_apps + do + local installed_app_ruby_version=$(yunohost app setting $installed_app ruby_version) + if [[ $installed_app_ruby_version ]] + then + required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" + fi + done + + # Remove no more needed Ruby version + local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') + for installed_ruby_version in $installed_ruby_versions + do + if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` + then + ynh_print_info --message="Removing of Ruby-"$installed_ruby_version + $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version + fi + done - # If no other app uses this version of ruby, remove it. - if ! grep --quiet "$ruby_version" "$rbenv_install_dir/ynh_app_version" - then - $rbenv_install_dir/bin/rbenv uninstall --force $ruby_version - fi - - # Remove rbenv environment configuration - rm /etc/profile.d/rbenv.sh - - # If no other app uses rbenv, remove rbenv and dedicated group - if [ ! -s "$rbenv_install_dir/ynh_app_version" ] - then - ynh_secure_remove "$rbenv_install_dir" - fi -} - -# Returns true if upstream version is up to date -# -# This helper should be used to avoid an upgrade of the upstream version -# when it's not needed (but yet allowing to upgrade other parts of the -# YunoHost application (e.g. nginx conf) -# -# usage: ynh_is_upstream_up_to_date (returns a boolean) -ynh_is_upstream_up_to_date () { - local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) - version="${version/~ynh*/}" - local last_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) - last_version="${last_version/~ynh*/}" - [ "$version" = "$last_version" ] + # If none Ruby version is required + if [[ ! $required_ruby_versions ]] + then + # Remove rbenv environment configuration + ynh_print_info --message="Removing of rbenv-"$rbenv_version + ynh_secure_remove --file="$rbenv_install_dir" + rm /etc/profile.d/rbenv.sh + fi } #================================================= diff --git a/scripts/change_url b/scripts/change_url index ce73aaf..60a3cd5 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -128,8 +128,9 @@ ynh_store_file_checksum --file="$discourse_config_file" ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "UPDATE site_settings SET value = replace(value, '${old_path%/}/images/', '${new_path%/}/images/'); UPDATE site_settings SET value = '${new_path}' WHERE name='long_polling_base_url';" +ynh_use_ruby # Remap URLs in forum posts -exec_login_as $app RAILS_ENV=production bundle exec script/discourse remap ${old_path%/}/uploads ${new_path%/}/uploads <<< "YES +exec_login_as $app RAILS_ENV=production bin/bundle exec script/discourse remap ${old_path%/}/uploads ${new_path%/}/uploads <<< "YES # " rake_exec="exec_login_as $app RAILS_ENV=production bin/rake" diff --git a/scripts/install b/scripts/install index 7d6154f..318818e 100644 --- a/scripts/install +++ b/scripts/install @@ -64,6 +64,7 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # CREATE A POSTGRESQL DATABASE @@ -103,13 +104,6 @@ ynh_setup_source --dest_dir="$final_path" mkdir -p "$final_path/plugins/discourse-ldap-auth" ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth -#================================================= -# INSTALL RUBY -#================================================= -ynh_script_progression --message="Installing Ruby..." - -ynh_install_ruby --ruby_version=$RUBY_VERSION - #================================================= # NGINX CONFIGURATION #================================================= @@ -197,8 +191,9 @@ ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/confi chown -R $app: $final_path pushd "$final_path" + ynh_use_ruby # Install bundler, a gems installer - gem install bundler + ynh_gem install bundler # Install without documentation exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" popd @@ -207,13 +202,13 @@ popd if [ -n "$(uname -m | grep arm)" ] ; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - exec_login_as $app bundle config specific_platform arm-linux + exec_login_as $app bin/bundle config specific_platform arm-linux fi # Install dependencies -exec_login_as $app bundle config set path 'vendor/bundle' -exec_login_as $app bundle config set with 'development' -exec_login_as $app MAKEFLAGS=-j2 bundle install --jobs 2 +exec_login_as $app bin/bundle config set path 'vendor/bundle' +exec_login_as $app bin/bundle config set with 'development' +exec_login_as $app MAKEFLAGS=-j2 bin/bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible diff --git a/scripts/restore b/scripts/restore index 900c267..90af673 100644 --- a/scripts/restore +++ b/scripts/restore @@ -90,12 +90,6 @@ ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# INSTALL RUBY -#================================================= -ynh_script_progression --message="Install Ruby..." - ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= @@ -104,7 +98,8 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION ynh_script_progression --message="Reinstall Bundle Gem..." (cd "$final_path" -gem install bundler) +ynh_use_ruby +ynh_gem install bundler) #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index fbe60ae..e1cd224 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -177,12 +177,6 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# INSTALL RUBY -#================================================= -ynh_script_progression --message="Installing Ruby..." - ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= @@ -273,8 +267,9 @@ then ( cd "$final_path" + ynh_use_ruby # Install bundler, a gems installer - gem install bundler + ynh_gem install bundler # Install without documentation exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" ) @@ -282,12 +277,12 @@ then if [ -n "$(uname -m | grep arm)" ] ; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - exec_login_as $app bundle config specific_platform arm-linux + exec_login_as $app bin/bundle config specific_platform arm-linux fi # Install dependencies - exec_login_as $app bundle config set path 'vendor/bundle' - exec_login_as $app bundle config set with 'development' - exec_login_as $app MAKEFLAGS=-j2 bundle install --jobs 2 + exec_login_as $app bin/bundle config set path 'vendor/bundle' + exec_login_as $app bin/bundle config set with 'development' + exec_login_as $app MAKEFLAGS=-j2 bin/bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible From b576c4c0bd8e34f5c3b9d132822378466b4194d2 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 8 Mar 2021 21:40:57 +0100 Subject: [PATCH 08/27] Revert prevent check_memory --- scripts/install | 6 ++---- scripts/restore | 6 ++---- scripts/upgrade | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/scripts/install b/scripts/install index 318818e..e232ce9 100644 --- a/scripts/install +++ b/scripts/install @@ -42,10 +42,8 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then - # Check memory requirements - check_memory_requirements -fi +# Check memory requirements +check_memory_requirements #================================================= # STORE SETTINGS FROM MANIFEST diff --git a/scripts/restore b/scripts/restore index 90af673..8a956fa 100644 --- a/scripts/restore +++ b/scripts/restore @@ -44,10 +44,8 @@ ynh_webpath_available --domain=$domain --path_url=$path_url \ test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then - # Check memory requirements - check_memory_requirements -fi +# Check memory requirements +check_memory_requirements #================================================= # STANDARD RESTORATION STEPS diff --git a/scripts/upgrade b/scripts/upgrade index e1cd224..56c94a7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,10 +25,8 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then - # Check memory requirements - check_memory_requirements_upgrade -fi +# Check memory requirements +check_memory_requirements_upgrade #================================================= # CHECK VERSION From 60aabdcaafcb597ccd9615755335584cf9b9652d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 10 Mar 2021 19:49:23 +0100 Subject: [PATCH 09/27] Fix restore and upgrade removing (cd tio make ynh_gem available --- scripts/restore | 7 ++++--- scripts/upgrade | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/restore b/scripts/restore index 8a956fa..b240d4e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -95,9 +95,10 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= ynh_script_progression --message="Reinstall Bundle Gem..." -(cd "$final_path" -ynh_use_ruby -ynh_gem install bundler) +pushd "$final_path" + ynh_use_ruby + ynh_gem install bundler +popd #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 56c94a7..2a90acf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -263,14 +263,14 @@ then # Set permissions to app files chown -R $app: $final_path - ( - cd "$final_path" + pushd "$final_path" ynh_use_ruby # Install bundler, a gems installer ynh_gem install bundler # Install without documentation exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" - ) + popd + # Specific actions on ARM architecture if [ -n "$(uname -m | grep arm)" ] ; then # Define the platform specifically to retrieve binaries From 299888f01c262ae192f81045e06966cc1d5f2fe1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 11 Mar 2021 02:35:15 +0100 Subject: [PATCH 10/27] Fix upgrade --- scripts/_common.sh | 5 +++-- scripts/upgrade | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 3c3e2d2..62dd046 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -273,8 +273,9 @@ ynh_use_ruby () { ynh_ruby_load_path="PATH=$PATH" # Sets the local application-specific Ruby version - (cd $final_path - rbenv local $ruby_version) + pushd $final_path + rbenv local $ruby_version + popd } # Install a specific version of Ruby diff --git a/scripts/upgrade b/scripts/upgrade index 2a90acf..15fedd2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -176,6 +176,7 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies ynh_install_ruby --ruby_version=$RUBY_VERSION +ynh_use_ruby #================================================= # CREATE DEDICATED USER @@ -264,7 +265,6 @@ then chown -R $app: $final_path pushd "$final_path" - ynh_use_ruby # Install bundler, a gems installer ynh_gem install bundler # Install without documentation From c7ffa1f342648abd344f92c967df7c2d1b55f0e4 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Mar 2021 22:51:53 +0100 Subject: [PATCH 11/27] Switch to git --- scripts/_common.sh | 164 ++++++++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 69 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 62dd046..5f676e3 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -163,54 +163,19 @@ ynh_maintenance_mode_OFF () { # RUBY HELPER #================================================= -rbenv_version=1.1.2 -ruby_build_version=20201225 -rbenv_aliases_version=1.1.0 +ynh_ruby_try_bash_extension() { + if [ -x src/configure ]; then + src/configure && make -C src || { + echo "Optional bash extension failed to build, but things will still work normally." + } + fi +} + rbenv_install_dir="/opt/rbenv" ruby_version_path="$rbenv_install_dir/versions" # RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. export RBENV_ROOT="$rbenv_install_dir" -# Install Ruby Version Management -# -# [internal] -# -# usage: ynh_install_rbenv -# -# Requires YunoHost version 2.7.12 or higher. -ynh_install_rbenv () { - ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${ruby_build_version}" - - # Build an app.src for rbenv - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v${rbenv_version}.tar.gz -SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > "../conf/rbenv.src" - # Download and extract rbenv - ynh_setup_source --dest_dir="$rbenv_install_dir" --source_id=rbenv - - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v${ruby_build_version}.tar.gz -SOURCE_SUM=54cae123c2758e7714c66aca7ef8bc7f29cda8583891191ceb3053c6d098ecf1" > "../conf/ruby-build.src" - # Download and extract ruby-build - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/ruby-build" --source_id=ruby-build - - # Build an app.src for rbenv-aliases - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz -SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > "../conf/rbenv-aliases.src" - # Download and extract rbenv-aliases - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases - - (cd $rbenv_install_dir - ./src/configure && make -C src) - - # Create shims directory if needed - if [ ! -d $rbenv_install_dir/shims ] ; then - mkdir $rbenv_install_dir/shims - fi -} - # Load the version of Ruby for an app, and set variables. # # ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. @@ -274,7 +239,7 @@ ynh_use_ruby () { # Sets the local application-specific Ruby version pushd $final_path - rbenv local $ruby_version + $rbenv_install_dir/bin/rbenv local $ruby_version popd } @@ -305,12 +270,6 @@ ynh_install_ruby () { # Manage arguments with getopts ynh_handle_getopts_args "$@" - # Store ruby_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version - - # Create $rbenv_install_dir if doesn't exist already - mkdir -p "$rbenv_install_dir/plugins/ruby-build" - # Load rbenv path in PATH local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" @@ -320,18 +279,81 @@ ynh_install_ruby () { # Move an existing Ruby binary, to avoid to block rbenv test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - # If rbenv is not previously setup, install it - if ! type rbenv > /dev/null 2>&1 - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt $rbenv_version - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt $ruby_build_version - then - ynh_install_rbenv + # Instal or update rbenv + rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | head -1)" + if [ -n "$rbenv" ]; then + ynh_print_info --message="rbenv already seems installed in \`$rbenv'." + pushd "${rbenv%/*/*}" + if git remote -v 2>/dev/null | grep -q rbenv; then + echo "Trying to update with git..." + git pull -q --tags origin master + cd .. + ynh_ruby_try_bash_extension + fi + popd + else + ynh_print_info --message="Installing rbenv with git..." + mkdir -p $rbenv_install_dir + pushd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv + popd fi + ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" + if [ -n "$ruby_build" ]; then + ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." + pushd "${ruby_build%/*/*}" + if git remote -v 2>/dev/null | grep -q ruby-build; then + ynh_print_info --message="Trying to update rbenv with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing ruby-build with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" + fi + + rb_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + if [ -n "$rb_alias" ]; then + ynh_print_info --message="\`rbenv alias' command already available in \`$rb_alias'." + pushd "${rb_alias%/*/*}" + if git remote -v 2>/dev/null | grep -q rbenv-aliases; then + ynh_print_info --message="Trying to update rbenv-aliases with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing rbenv-aliases with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" + fi + + rb_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + if [ -n "$rb_latest" ]; then + ynh_print_info --message="\`rbenv latest' command already available in \`$rb_latest'." + pushd "${rb_latest%/*/*}" + if git remote -v 2>/dev/null | grep -q xxenv-latest; then + ynh_print_info --message="Trying to update xxenv-latest with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing xxenv-latest with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" + fi + + # Enable caching + mkdir -p "${rbenv_install_dir}/cache" + + # Create shims directory if needed + mkdir -p "${rbenv_install_dir}/shims" + # Restore /usr/local/bin in PATH PATH=$CLEAR_PATH @@ -339,17 +361,21 @@ ynh_install_ruby () { test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby # Install the requested version of Ruby - ynh_print_info --message="Installation of Ruby-"$ruby_version - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version + local final_ruby_version=$(rbenv latest --print $ruby_version) + ynh_print_info --message="Installing Ruby-$final_ruby_version" + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 + + # Store ruby_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$final_ruby_version # Remove app virtualenv - if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME" 1>/dev/null 2>&1` + if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` then rbenv alias $YNH_APP_INSTANCE_NAME --remove fi # Create app virtualenv - rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version + rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version # Cleanup Ruby versions ynh_cleanup_ruby @@ -397,7 +423,7 @@ ynh_remove_ruby () { # usage: ynh_cleanup_ruby ynh_cleanup_ruby () { - # List required Ruby version + # List required Ruby versions local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local required_ruby_versions="" for installed_app in $installed_apps @@ -409,13 +435,13 @@ ynh_cleanup_ruby () { fi done - # Remove no more needed Ruby version + # Remove no more needed Ruby versions local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') for installed_ruby_version in $installed_ruby_versions do if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` then - ynh_print_info --message="Removing of Ruby-"$installed_ruby_version + ynh_print_info --message="Removing of Ruby-$installed_ruby_version" $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version fi done @@ -424,9 +450,9 @@ ynh_cleanup_ruby () { if [[ ! $required_ruby_versions ]] then # Remove rbenv environment configuration - ynh_print_info --message="Removing of rbenv-"$rbenv_version + ynh_print_info --message="Removing of rbenv-$rbenv_version" ynh_secure_remove --file="$rbenv_install_dir" - rm /etc/profile.d/rbenv.sh + ynh_secure_remove --file="/etc/profile.d/rbenv.sh" fi } From 2128978f4cb97880c237916ba1d1228161ac4bc8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Mar 2021 23:50:33 +0100 Subject: [PATCH 12/27] Update _common.sh --- scripts/_common.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5f676e3..5e9924a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -318,10 +318,10 @@ ynh_install_ruby () { git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" fi - rb_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" - if [ -n "$rb_alias" ]; then - ynh_print_info --message="\`rbenv alias' command already available in \`$rb_alias'." - pushd "${rb_alias%/*/*}" + rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + if [ -n "$rbenv_alias" ]; then + ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." + pushd "${rbenv_alias%/*/*}" if git remote -v 2>/dev/null | grep -q rbenv-aliases; then ynh_print_info --message="Trying to update rbenv-aliases with git..." git pull -q origin master @@ -333,10 +333,10 @@ ynh_install_ruby () { git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" fi - rb_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" - if [ -n "$rb_latest" ]; then - ynh_print_info --message="\`rbenv latest' command already available in \`$rb_latest'." - pushd "${rb_latest%/*/*}" + rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + if [ -n "$rbenv_latest" ]; then + ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." + pushd "${rbenv_latest%/*/*}" if git remote -v 2>/dev/null | grep -q xxenv-latest; then ynh_print_info --message="Trying to update xxenv-latest with git..." git pull -q origin master @@ -385,7 +385,7 @@ ynh_install_ruby () { export RBENV_ROOT=$rbenv_install_dir export PATH=\"$rbenv_install_dir/bin:$PATH\" eval \"\$(rbenv init -)\" - #rbenv" > /etc/profile.d/rbenv.sh +#rbenv" > /etc/profile.d/rbenv.sh # Load the environment eval "$(rbenv init -)" From 29be65c72e86d79b690d908c4e32483e62e06084 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 13:01:36 +0100 Subject: [PATCH 13/27] manage previous rbenv instllations --- scripts/_common.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5e9924a..ea8208e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -166,7 +166,7 @@ ynh_maintenance_mode_OFF () { ynh_ruby_try_bash_extension() { if [ -x src/configure ]; then src/configure && make -C src || { - echo "Optional bash extension failed to build, but things will still work normally." + ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." } fi } @@ -247,9 +247,6 @@ ynh_use_ruby () { # # ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. # -# rbenv (Ruby Version Management) stores the target Ruby version in a .ruby_version file created in the target folder (using rbenv local ) -# It then uses that information for every Ruby user that uses rbenv provided Ruby command -# # This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv # for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) # @@ -279,16 +276,26 @@ ynh_install_ruby () { # Move an existing Ruby binary, to avoid to block rbenv test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - # Instal or update rbenv - rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | head -1)" + # Install or update rbenv + rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" if [ -n "$rbenv" ]; then ynh_print_info --message="rbenv already seems installed in \`$rbenv'." pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep -q rbenv; then - echo "Trying to update with git..." + if git remote -v 2>/dev/null | grep -q "origin https://github.com/rbenv/rbenv.git"; then + ynh_print_info --message="Trying to update with git..." git pull -q --tags origin master - cd .. ynh_ruby_try_bash_extension + else + ynh_print_info --message="Reinstalling rbenv with git..." + cd .. + ynh_secure_remove --file=$rbenv_install_dir + mkdir -p $rbenv_install_dir + cd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv fi popd else From 277ee5344ec2b267459ff8645f030466fbc9f662 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 15:06:39 +0100 Subject: [PATCH 14/27] Fix new rbenv install --list-all --- scripts/_common.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index ea8208e..d6887f3 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -369,6 +369,9 @@ ynh_install_ruby () { # Install the requested version of Ruby local final_ruby_version=$(rbenv latest --print $ruby_version) + if ! [ -n "$final_ruby_version" ]; then + final_ruby_version=$ruby_version + fi ynh_print_info --message="Installing Ruby-$final_ruby_version" CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 From fc1192d4aea756b3ed2ef19484f016aa686d5ffe Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Mar 2021 00:48:24 +0100 Subject: [PATCH 15/27] Do not use 'yunohost app setting' --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index d6887f3..e344105 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -438,7 +438,7 @@ ynh_cleanup_ruby () { local required_ruby_versions="" for installed_app in $installed_apps do - local installed_app_ruby_version=$(yunohost app setting $installed_app ruby_version) + local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") if [[ $installed_app_ruby_version ]] then required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" From ba2a147a1d0e75e75ef1aeff5512df961867815f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Mar 2021 05:59:30 +0100 Subject: [PATCH 16/27] Fix repository detection --- scripts/_common.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index e344105..fb39781 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -281,7 +281,7 @@ ynh_install_ruby () { if [ -n "$rbenv" ]; then ynh_print_info --message="rbenv already seems installed in \`$rbenv'." pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep -q "origin https://github.com/rbenv/rbenv.git"; then + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then ynh_print_info --message="Trying to update with git..." git pull -q --tags origin master ynh_ruby_try_bash_extension @@ -314,7 +314,7 @@ ynh_install_ruby () { if [ -n "$ruby_build" ]; then ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." pushd "${ruby_build%/*/*}" - if git remote -v 2>/dev/null | grep -q ruby-build; then + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then ynh_print_info --message="Trying to update rbenv with git..." git pull -q origin master fi @@ -329,7 +329,7 @@ ynh_install_ruby () { if [ -n "$rbenv_alias" ]; then ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." pushd "${rbenv_alias%/*/*}" - if git remote -v 2>/dev/null | grep -q rbenv-aliases; then + if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then ynh_print_info --message="Trying to update rbenv-aliases with git..." git pull -q origin master fi @@ -344,7 +344,7 @@ ynh_install_ruby () { if [ -n "$rbenv_latest" ]; then ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." pushd "${rbenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep -q xxenv-latest; then + if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then ynh_print_info --message="Trying to update xxenv-latest with git..." git pull -q origin master fi From 1bf6eb67d07d3e88af258dafda0ebf5763d74829 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 1 Apr 2021 20:33:13 +0200 Subject: [PATCH 17/27] Check upgrade from current version --- check_process | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/check_process b/check_process index f80a808..88d45c7 100644 --- a/check_process +++ b/check_process @@ -16,6 +16,8 @@ upgrade=1 from_commit=de467cfa38791f43215ffea88d4b85460e5c0457 # 2.3.10~ynh1 upgrade=1 from_commit=086de718f49a506c66498d2f7610f5fd0ce07d50 + # 2.6.0~ynh1 + upgrade=1 from_commit=b2e6633e0145c7eed2eb8c645ca7dbbd6c26fc06 backup_restore=1 # Activate multi-instance test only if you have more than 2Gb RAM! multi_instance=1 @@ -30,3 +32,5 @@ Notification=none manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1& ; commit=086de718f49a506c66498d2f7610f5fd0ce07d50 name=2.3.10~ynh1 + ; commit=b2e6633e0145c7eed2eb8c645ca7dbbd6c26fc06 + name=2.6.0~ynh1 From ca0e8c2000adaae610e8bfe7fbac3f4086996f44 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 10 Apr 2021 01:48:01 +0200 Subject: [PATCH 18/27] Apply last example_ynh --- README.md | 4 ++-- check_process | 6 +++--- issue_template.md | 2 +- manifest.json | 16 ---------------- scripts/backup | 1 - scripts/change_url | 2 +- scripts/install | 22 +++++++++++++--------- scripts/remove | 2 +- scripts/restore | 32 +++++++++++++------------------- scripts/upgrade | 22 +++++++++++++--------- 10 files changed, 47 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 9a16802..78b7ff1 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ When disabling Local Login and other authentication services, clicking the `Logi #### Supported architectures -* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/discourse%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/discourse/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/discourse%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/discourse/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/discourse.svg)](https://ci-apps.yunohost.org/ci/apps/discourse/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/discourse.svg)](https://ci-apps-arm.yunohost.org/ci/apps/discourse/) ## Limitations diff --git a/check_process b/check_process index 88d45c7..ad37462 100644 --- a/check_process +++ b/check_process @@ -13,11 +13,11 @@ setup_public=1 upgrade=1 # 2.2.3~ynh1 - upgrade=1 from_commit=de467cfa38791f43215ffea88d4b85460e5c0457 + upgrade=1 from_commit=de467cfa38791f43215ffea88d4b85460e5c0457 # 2.3.10~ynh1 - upgrade=1 from_commit=086de718f49a506c66498d2f7610f5fd0ce07d50 + upgrade=1 from_commit=086de718f49a506c66498d2f7610f5fd0ce07d50 # 2.6.0~ynh1 - upgrade=1 from_commit=b2e6633e0145c7eed2eb8c645ca7dbbd6c26fc06 + upgrade=1 from_commit=b2e6633e0145c7eed2eb8c645ca7dbbd6c26fc06 backup_restore=1 # Activate multi-instance test only if you have more than 2Gb RAM! multi_instance=1 diff --git a/issue_template.md b/issue_template.md index 75fc3f2..52dacef 100644 --- a/issue_template.md +++ b/issue_template.md @@ -8,7 +8,7 @@ about: When creating a bug report, please use the following template to provide 1. *Read this whole template first.* 2. *Determine if you are on the right place:* - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* - - *Otherwise, the issue may be due to discourse itself. Refer to its documentation or repository for help.* + - *Otherwise, the issue may be due to Discourse itself. Refer to its documentation or repository for help.* - *When in doubt, post here and we will figure it out together.* 3. *Delete the italic comments as you write over them below, and remove this guide.* --- diff --git a/manifest.json b/manifest.json index 84adb18..c4a6f45 100644 --- a/manifest.json +++ b/manifest.json @@ -26,38 +26,22 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain name for Discourse", - "fr": "Choisissez un nom de domaine pour Discourse" - }, "example": "example.com" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Discourse", - "fr": "Choisissez un chemin pour Discourse" - }, "example": "/forum", "default": "/forum" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose an admin user", - "fr": "Choisissez l'administrateur" - }, "example": "johndoe" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, "default": true } ] diff --git a/scripts/backup b/scripts/backup index d9f717e..1f4c370 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - # Clean remainings not handled by remove script ynh_clean_check_starting } # Exit if an error occurs during the execution of the script diff --git a/scripts/change_url b/scripts/change_url index 60a3cd5..1a5dbd5 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -36,7 +36,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." diff --git a/scripts/install b/scripts/install index e232ce9..b5767f4 100644 --- a/scripts/install +++ b/scripts/install @@ -64,6 +64,14 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies ynh_install_ruby --ruby_version=$RUBY_VERSION +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell + #================================================= # CREATE A POSTGRESQL DATABASE #================================================= @@ -102,6 +110,10 @@ ynh_setup_source --dest_dir="$final_path" mkdir -p "$final_path/plugins/discourse-ldap-auth" ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -116,14 +128,6 @@ if [ "$path_url" != "/" ] ; then fi ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path --use_shell - #================================================= # SPECIFIC SETUP #================================================= @@ -331,7 +335,7 @@ ynh_use_logrotate --logfile="$final_path/log/production.log" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" +yunohost service add $app --log="$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index d53ebc5..9f8a08c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -28,7 +28,7 @@ redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then ynh_script_progression --message="Removing $app service integration..." diff --git a/scripts/restore b/scripts/restore index b240d4e..6a2a2e1 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - # Clean remainings not handled by remove script ynh_clean_check_starting } # Exit if an error occurs during the execution of the script @@ -24,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -56,6 +55,14 @@ ynh_script_progression --message="Restoring the NGINX web server configuration.. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -63,21 +70,9 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path --use_shell - -#================================================= -# RESTORE USER RIGHTS -#================================================= -ynh_script_progression --message="Restoring user rights..." - -# Restore permissions on app files -chown -R $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" #================================================= # SPECIFIC RESTORATION @@ -120,7 +115,6 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl daemon-reload systemctl enable $app.service --quiet #================================================= @@ -128,7 +122,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" +yunohost service add $app --log="$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 15fedd2..1a915b8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -92,6 +92,14 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="$final_path/log/unicorn.stderr.log" +#================================================= +# 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" --use_shell + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -155,6 +163,10 @@ then ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -178,14 +190,6 @@ ynh_install_app_dependencies $pkg_dependencies ynh_install_ruby --ruby_version=$RUBY_VERSION ynh_use_ruby -#================================================= -# 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 --use_shell - #================================================= # SPECIFIC UPGRADE #================================================= @@ -384,7 +388,7 @@ ynh_use_logrotate --logfile="$final_path/log/production.log" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" +yunohost service add $app --log="$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" #================================================= # START SYSTEMD SERVICE From 9b46853f5787e839a7f70fcb10cf52740c58ed5d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 10 Apr 2021 23:41:49 +0200 Subject: [PATCH 19/27] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index c4a6f45..0163137 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "" }, "requirements": { - "yunohost": ">= 4.0" + "yunohost": ">= 4.1.3" }, "multi_instance": true, "services": [ From a44196906a1b49acfa5da4068e5722fd293154f1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 11 Apr 2021 20:13:36 +0200 Subject: [PATCH 20/27] Fix yunohost: error: unrecognized arguments --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index b5767f4..d5ec815 100644 --- a/scripts/install +++ b/scripts/install @@ -335,7 +335,7 @@ ynh_use_logrotate --logfile="$final_path/log/production.log" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log="$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" +yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/restore b/scripts/restore index 6a2a2e1..cf162bc 100644 --- a/scripts/restore +++ b/scripts/restore @@ -122,7 +122,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log="$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" +yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 1a915b8..634e1e4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -388,7 +388,7 @@ ynh_use_logrotate --logfile="$final_path/log/production.log" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log="$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" +yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log" #================================================= # START SYSTEMD SERVICE From d2bd65007097b09e1d1f25958719298141469332 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 13 Apr 2021 01:13:51 +0200 Subject: [PATCH 21/27] Fix rights --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index d5ec815..81a76de 100644 --- a/scripts/install +++ b/scripts/install @@ -112,7 +112,7 @@ ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_i chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R root:$app "$final_path" +chown -R $app:$app "$final_path" #================================================= # NGINX CONFIGURATION diff --git a/scripts/restore b/scripts/restore index cf162bc..87f32e0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -72,7 +72,7 @@ ynh_restore_file --origin_path="$final_path" chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R root:$app "$final_path" +chown -R $app:$app "$final_path" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index 634e1e4..ab0236c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -165,7 +165,7 @@ fi chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R root:$app "$final_path" +chown -R $app:$app "$final_path" #================================================= # NGINX CONFIGURATION From 7bd7499559ca97c42d2d74b8f7e90b88c5032f08 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Apr 2021 20:12:05 +0200 Subject: [PATCH 22/27] fix rights --- conf/systemd.service | 2 +- scripts/install | 4 ++-- scripts/restore | 2 +- scripts/upgrade | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 1962bc5..655e184 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -14,7 +14,7 @@ Environment=RAILS_ENV=production Environment=UNICORN_SIDEKIQS=1 Environment=LD_PRELOAD=__LIBJEMALLOC__ Environment=UNICORN_LISTENER=__FINALPATH__/tmp/sockets/unicorn.sock -ExecStart=__RBENVROOT__/shims/bundle exec unicorn --config config/unicorn.conf.rb -E production +ExecStart=__RBENV_ROOT__/shims/bundle exec unicorn --config config/unicorn.conf.rb -E production Restart=always RestartSec=10 diff --git a/scripts/install b/scripts/install index 81a76de..bf6f6a2 100644 --- a/scripts/install +++ b/scripts/install @@ -112,7 +112,7 @@ ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_i chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" +chown -R $app:www-data "$final_path" #================================================= # NGINX CONFIGURATION @@ -278,7 +278,7 @@ patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch) #================================================= ynh_script_progression --message="Configuring a systemd service..." -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service" +ynh_replace_string --match_string="__RBENV_ROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service" # We assume for the moment that ARM devices are only dual core, so # we restrict the number of workers to 2 (the default is 3) diff --git a/scripts/restore b/scripts/restore index 87f32e0..22feb02 100644 --- a/scripts/restore +++ b/scripts/restore @@ -72,7 +72,7 @@ ynh_restore_file --origin_path="$final_path" chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index ab0236c..efbe806 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -165,7 +165,7 @@ fi chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" +chown -R $app:www-data "$final_path" #================================================= # NGINX CONFIGURATION @@ -335,7 +335,7 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Configuring a systemd service..." - ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service" + ynh_replace_string --match_string="__RBENV_ROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service" additional_env="UNICORN_WORKERS=$unicorn_workers" ynh_replace_string --match_string="__ADDITIONAL_ENV__" --replace_string="$additional_env" --target_file="../conf/systemd.service" From 44a9cd0041e4edb48d8ebcb7aaee4086fc7ebb85 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 15 Apr 2021 02:35:10 +0200 Subject: [PATCH 23/27] Fix install --- scripts/install | 12 ++++++------ scripts/upgrade | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/install b/scripts/install index bf6f6a2..113f47e 100644 --- a/scripts/install +++ b/scripts/install @@ -190,7 +190,9 @@ secret="$(ynh_string_random)" ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files -chown -R $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" pushd "$final_path" ynh_use_ruby @@ -314,11 +316,9 @@ mkdir -p "public/forum" cd public/forum && ln -s ../uploads && ln -s ../backups ) -# Set permissions to app files -chown -R $app: $final_path - -# Restrict rights to log directory (needed by logrotate) -chmod g-w $final_path/log +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SETUP LOGROTATE diff --git a/scripts/upgrade b/scripts/upgrade index efbe806..dc182b8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -266,7 +266,9 @@ then ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files - chown -R $app: $final_path + chmod 750 "$final_path" + chmod -R o-rwx "$final_path" + chown -R $app:www-data "$final_path" pushd "$final_path" # Install bundler, a gems installer @@ -369,9 +371,9 @@ mkdir -p "$final_path/tmp/sockets" ) # Set permissions to app files -chown -R $app: $final_path -# Restrict rights to log directory (needed by logrotate) -chmod g-w $final_path/log +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SETUP LOGROTATE From a4d4f770846f1da87e1d08ac0ae965e94b37e97b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 15 Apr 2021 20:27:45 +0200 Subject: [PATCH 24/27] Fix chmod --- scripts/install | 6 +++--- scripts/restore | 2 +- scripts/upgrade | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/install b/scripts/install index 113f47e..6cefc96 100644 --- a/scripts/install +++ b/scripts/install @@ -110,7 +110,7 @@ ynh_setup_source --dest_dir="$final_path" mkdir -p "$final_path/plugins/discourse-ldap-auth" ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -190,7 +190,7 @@ secret="$(ynh_string_random)" ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -316,7 +316,7 @@ mkdir -p "public/forum" cd public/forum && ln -s ../uploads && ln -s ../backups ) -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" diff --git a/scripts/restore b/scripts/restore index 22feb02..ebb2be7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -70,7 +70,7 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade index dc182b8..60d45a5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -163,7 +163,7 @@ then ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth fi -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -266,7 +266,7 @@ then ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files - chmod 750 "$final_path" + chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -371,7 +371,7 @@ mkdir -p "$final_path/tmp/sockets" ) # Set permissions to app files -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" From e407a0330d6a0353880c754c3794eca855803086 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 17 Apr 2021 18:31:03 +0200 Subject: [PATCH 25/27] Fix recursive chmod --- scripts/install | 6 +++--- scripts/restore | 2 +- scripts/upgrade | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/install b/scripts/install index 6cefc96..113f47e 100644 --- a/scripts/install +++ b/scripts/install @@ -110,7 +110,7 @@ ynh_setup_source --dest_dir="$final_path" mkdir -p "$final_path/plugins/discourse-ldap-auth" ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -190,7 +190,7 @@ secret="$(ynh_string_random)" ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -316,7 +316,7 @@ mkdir -p "public/forum" cd public/forum && ln -s ../uploads && ln -s ../backups ) -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" diff --git a/scripts/restore b/scripts/restore index ebb2be7..22feb02 100644 --- a/scripts/restore +++ b/scripts/restore @@ -70,7 +70,7 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade index 60d45a5..dc182b8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -163,7 +163,7 @@ then ynh_setup_source --dest_dir="$final_path/plugins/discourse-ldap-auth" --source_id=ldap-auth fi -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -266,7 +266,7 @@ then ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" # Set permissions to app files - chmod -R 750 "$final_path" + chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -371,7 +371,7 @@ mkdir -p "$final_path/tmp/sockets" ) # Set permissions to app files -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" From 1da2132c7766ecc9c4a267428fbcfd3789e747fb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 23 Apr 2021 17:51:04 +0200 Subject: [PATCH 26/27] Update check_process --- check_process | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_process b/check_process index ad37462..990b709 100644 --- a/check_process +++ b/check_process @@ -13,9 +13,9 @@ setup_public=1 upgrade=1 # 2.2.3~ynh1 - upgrade=1 from_commit=de467cfa38791f43215ffea88d4b85460e5c0457 + #upgrade=1 from_commit=de467cfa38791f43215ffea88d4b85460e5c0457 # 2.3.10~ynh1 - upgrade=1 from_commit=086de718f49a506c66498d2f7610f5fd0ce07d50 + #upgrade=1 from_commit=086de718f49a506c66498d2f7610f5fd0ce07d50 # 2.6.0~ynh1 upgrade=1 from_commit=b2e6633e0145c7eed2eb8c645ca7dbbd6c26fc06 backup_restore=1 From 72e8e077a1bad3471ddf41466bf02b4751c106df Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 11 May 2021 19:53:42 +0200 Subject: [PATCH 27/27] Fix YunoHost version Using official helper ynh_exec_as implies requiring at least version 4.1.7, but manifest only requires 4.1.3 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 0163137..4f8db83 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "" }, "requirements": { - "yunohost": ">= 4.1.3" + "yunohost": ">= 4.1.7" }, "multi_instance": true, "services": [