From 0214e35e5d6451aef1655cca55d3c4c340a3e27c Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 19:34:30 +0200 Subject: [PATCH 01/15] Upgrade to 3.22.8 --- conf/app.src | 4 ++-- manifest.json | 2 +- sources/patches/app-02-fix-gemfile-mimemagic.patch | 14 -------------- 3 files changed, 3 insertions(+), 17 deletions(-) delete mode 100644 sources/patches/app-02-fix-gemfile-mimemagic.patch diff --git a/conf/app.src b/conf/app.src index f4ff841..4d80c26 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/standardnotes/syncing-server/archive/3.20.5.zip -SOURCE_SUM=86B9A423FD910B1C1D65ED4B98FAE9459B70E78B110E3ACEC8B6EF4627C5E0B1 +SOURCE_URL=https://github.com/standardnotes/syncing-server/archive/3.22.8.zip +SOURCE_SUM=DBAB9503D2E52392DB1A272D3C00AE267C9515119F48E2F20BF56E44FA1ECD28 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true diff --git a/manifest.json b/manifest.json index 7d2186c..3ab4ab5 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "The Standard Notes syncing server. An end-to-end encrypted note-taking app." }, - "version": "3.20.5~ynh2", + "version": "3.22.8~ynh1", "url": "https://github.com/standardnotes/syncing-server", "license": "AGPL-3.0-or-later", "maintainer": { diff --git a/sources/patches/app-02-fix-gemfile-mimemagic.patch b/sources/patches/app-02-fix-gemfile-mimemagic.patch deleted file mode 100644 index cde6ed7..0000000 --- a/sources/patches/app-02-fix-gemfile-mimemagic.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/Gemfile.lock b/Gemfile.lock -index d209769..a6c9687 100644 ---- a/Gemfile.lock -+++ b/Gemfile.lock -@@ -132,7 +132,8 @@ GEM - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (1.0.0) -- mimemagic (0.3.5) -+ mimemagic (0.3.8) -+ nokogiri (~> 1) - mini_mime (1.0.2) - mini_portile2 (2.5.0) - minitest (5.14.2) From 927e3589664e10c72c89f5c9f1951c90e2c857dd Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 20:11:59 +0200 Subject: [PATCH 02/15] Remove unneeded code --- scripts/change_url | 10 ++-------- scripts/install | 15 +++------------ scripts/upgrade | 15 +++------------ 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index a9b7488..0d9b672 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -95,10 +95,7 @@ then domain="$old_domain" path_url="$new_path" # Create a dedicated nginx config - ynh_add_nginx_config "\ - port \ - access_domain\ - " + ynh_add_nginx_config fi # Change the domain for nginx @@ -152,10 +149,7 @@ domain=$new_domain path_url=$new_path # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" -ynh_add_fail2ban_config --use_template --others_var="\ - domain \ - path_url \ - " +ynh_add_fail2ban_config --use_template #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 1727de3..d3a2e08 100755 --- a/scripts/install +++ b/scripts/install @@ -102,10 +102,7 @@ ynh_setup_source --dest_dir="$final_path/live" ynh_script_progression --message="Configuring nginx web server..." --weight=3 # Create a dedicated nginx config -ynh_add_nginx_config "\ - port \ - access_domain \ - " +ynh_add_nginx_config #================================================= # CREATE DEDICATED USER @@ -205,10 +202,7 @@ done ynh_script_progression --message="Configuring a systemd service..." --weight=4 # Create a dedicated systemd config -ynh_add_systemd_config --others_var="\ - port \ - RUBY_VERSION \ -" +ynh_add_systemd_config #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -261,10 +255,7 @@ ynh_script_progression --message="Configuring fail2ban..." --weight=1 # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" -ynh_add_fail2ban_config --use_template --others_var="\ - domain \ - path_url \ - " +ynh_add_fail2ban_config --use_template #================================================= # SETUP SSOWAT diff --git a/scripts/upgrade b/scripts/upgrade index 59c4749..563ade6 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -202,10 +202,7 @@ fi ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 # Create a dedicated nginx config -ynh_add_nginx_config "\ - port \ - access_domain \ - " +ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES @@ -305,10 +302,7 @@ done ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config -ynh_add_systemd_config --others_var="\ - port \ - RUBY_VERSION \ -" +ynh_add_systemd_config #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -358,10 +352,7 @@ ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1 # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" -ynh_add_fail2ban_config --use_template --others_var="\ - domain \ - path_url \ - " +ynh_add_fail2ban_config --use_template #================================================= # START SYSTEMD SERVICE From 2b765cfbd9320b3e920d34c8f1f7c8aad79caa93 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 21:37:41 +0200 Subject: [PATCH 03/15] Update to ynh_install_ruby__2 --- scripts/install | 23 +-- scripts/remove | 2 +- scripts/restore | 11 +- scripts/upgrade | 23 +-- scripts/ynh_install_ruby__2 | 305 ++++++++++++++++++++++++++++++++++++ 5 files changed, 339 insertions(+), 25 deletions(-) create mode 100644 scripts/ynh_install_ruby__2 diff --git a/scripts/install b/scripts/install index d3a2e08..034e54f 100755 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,7 @@ #================================================= source _common.sh -source ynh_install_ruby +source ynh_install_ruby__2 source ynh_redis source /usr/share/yunohost/helpers @@ -75,6 +75,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port ynh_script_progression --message="Installing dependencies..." --weight=17 ynh_install_app_dependencies $pkg_dependencies +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # CREATE A MYSQL DATABASE @@ -119,9 +120,11 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 -ynh_install_ruby --ruby_version=$RUBY_VERSION -/opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document -/opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler --no-document +pushd "$final_path/live" + ynh_use_ruby + ynh_gem update --system --no-document + ynh_gem install bundler --no-document +popd #================================================= # Setup @@ -162,12 +165,12 @@ ynh_script_progression --message="Installing Standard Notes - Synicing Server... chown -R $app: "$final_path" pushd "$final_path/live" - exec_as $app /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set --local path 'vendor/bundle' - exec_as $app /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' - exec_as $app /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - exec_as $app RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:migrate --quiet - exec_as $app RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:seed --quiet -# exec_as $app RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet + exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' + exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' + exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate --quiet + exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:seed --quiet +# exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet popd #================================================= diff --git a/scripts/remove b/scripts/remove index 90dcfbe..75ae030 100755 --- a/scripts/remove +++ b/scripts/remove @@ -7,7 +7,7 @@ #================================================= source _common.sh -source ynh_install_ruby +source ynh_install_ruby__2 source ynh_redis source /usr/share/yunohost/helpers diff --git a/scripts/restore b/scripts/restore index 2e211e5..e2d51a7 100755 --- a/scripts/restore +++ b/scripts/restore @@ -8,7 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_install_ruby +source ../settings/scripts/ynh_install_ruby__2 source ../settings/scripts/ynh_redis source /usr/share/yunohost/helpers @@ -98,15 +98,18 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=17 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # INSTALLING RUBY #================================================= ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 -ynh_install_ruby --ruby_version=$RUBY_VERSION -/opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document -/opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler --no-document +pushd "$final_path/live" + ynh_use_ruby + ynh_gem update --system --no-document + ynh_gem install bundler --no-document +popd #================================================= # RESTORE THE MYSQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 563ade6..d9ffe01 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,7 @@ #================================================= source _common.sh -source ynh_install_ruby +source ynh_install_ruby__2 source ynh_redis source /usr/share/yunohost/helpers @@ -210,15 +210,18 @@ ynh_add_nginx_config ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # INSTALL RUBY #================================================= ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 -ynh_install_ruby --ruby_version=$RUBY_VERSION -/opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document -/opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler --no-document +pushd "$final_path/live" + ynh_use_ruby + ynh_gem update --system --no-document + ynh_gem install bundler --no-document +popd #================================================= # CREATE DEDICATED USER @@ -262,12 +265,12 @@ then chown -R $app: "$final_path" pushd "$final_path/live" - exec_as $app /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set --local path 'vendor/bundle' - exec_as $app /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' - exec_as $app /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - exec_as $app RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:migrate --quiet - exec_as $app RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:seed --quiet -# exec_as $app RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet + exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' + exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' + exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate --quiet + exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:seed --quiet +# exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet popd fi diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 new file mode 100644 index 0000000..5357cf5 --- /dev/null +++ b/scripts/ynh_install_ruby__2 @@ -0,0 +1,305 @@ +#!/bin/bash + +ynh_ruby_try_bash_extension() { + if [ -x src/configure ]; then + src/configure && make -C src || { + ynh_print_info --message="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" + +# 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. +# This helper will provide alias and variables to use in your scripts. +# +# 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 3.2.2 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 + pushd $final_path + $rbenv_install_dir/bin/rbenv local $ruby_version + popd +} + +# Install a specific version of Ruby +# +# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. +# +# 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) +# +# Don't forget to execute ruby-dependent command in a login environment +# (e.g. sudo --login option) +# 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=ruby_version +# | arg: -v, --ruby_version= - Version of ruby to install. +# +# Requires YunoHost version 3.2.2 or higher. +ynh_install_ruby () { + # 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 "$@" + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing Ruby binary, to avoid to block rbenv + test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv + + # 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 "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 + 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 + 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 "https://github.com/rbenv/ruby-build.git"; 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 + + 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 "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 + 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 + + 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 "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 + 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 + + # And replace the old Ruby binary + test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/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 + + # 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` + then + rbenv alias $YNH_APP_INSTANCE_NAME --remove + fi + + # Create app virtualenv + rbenv alias $YNH_APP_INSTANCE_NAME $final_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 + + # Load the environment + eval "$(rbenv init -)" +} + +# Remove the version of Ruby used by the app. +# +# This helper will also cleanup Ruby versions +# +# usage: ynh_remove_ruby +ynh_remove_ruby () { + local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + rbenv alias $YNH_APP_INSTANCE_NAME --remove + + # 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 no more needed versions of Ruby used by the app. +# +# 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_cleanup_ruby +ynh_cleanup_ruby () { + + # List required Ruby versions + 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=$(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}" + fi + done + + # 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" + $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version + fi + done + + # 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" + ynh_secure_remove --file="/etc/profile.d/rbenv.sh" + fi +} + From 1171f6c770e3bcdcccc230029b198ed4aa6a647f Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 21:43:45 +0200 Subject: [PATCH 04/15] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 755bb5b..32ac30b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Standard Notes syncing server You can run your own Standard Notes server and use it with any Standard Notes app. This allows you to have 100% control of your data. -**Shipped version:** 3.20.5 +**Shipped version:** 3.22.8 * Apps available for free. https://standardnotes.org/ * Desktop (Windows, Mac, Linux) * Mobile (Android and iOS) @@ -52,8 +52,8 @@ How to configure this app: #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/snserver%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/snserver/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/snserver%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/snserver/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/snserver.svg)](https://ci-apps.yunohost.org/ci/apps/snserver/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/snserver.svg)](https://ci-apps-arm.yunohost.org/ci/apps/snserver/) ## Limitations From efd5e7e66248cba943cb686b55c330f54b78bc92 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 21:48:58 +0200 Subject: [PATCH 05/15] Typo - Fix #17 --- scripts/install | 4 ++-- scripts/upgrade | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/install b/scripts/install index 034e54f..88040b2 100755 --- a/scripts/install +++ b/scripts/install @@ -158,9 +158,9 @@ ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --targ ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/live/app/views/user_mailer/welcome.html.erb" #================================================= -# INSTALLING Standard Notes - Synicing Server +# INSTALLING Standard Notes - Syncing Server #================================================= -ynh_script_progression --message="Installing Standard Notes - Synicing Server..." --weight=93 +ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93 chown -R $app: "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade index d9ffe01..69c285b 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -256,11 +256,11 @@ ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --targ ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/live/app/views/user_mailer/welcome.html.erb" #================================================= -# INSTALLING Standard Notes - Synicing Server +# INSTALLING Standard Notes - Syncing Server #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Installing Standard Notes - Synicing Server..." --weight=93 + ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93 chown -R $app: "$final_path" @@ -397,7 +397,7 @@ Please setup the Access-Domain for the extensions in the __URL_TAG1__config-pane echo -e "\ Standard Notes - Syncing Server was successfully upgraded.\n\ -Please configure the Standard Notes web app or mobile app to use this syning server: https://$domain$path_url/\n\ +Please configure the Standard Notes web app or mobile app to use this syncing server: https://$domain$path_url/\n\ $config_panel\n\n\ $admin_mail_info\ " > message From d6093af701e4610b93c4acc04ca14fb7bcc46491 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 22:04:34 +0200 Subject: [PATCH 06/15] Set permissions --- scripts/install | 7 +++++-- scripts/restore | 8 ++++++-- scripts/upgrade | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 88040b2..fcb659b 100755 --- a/scripts/install +++ b/scripts/install @@ -225,8 +225,11 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Securing files and directories..." --weight=1 # Set permissions to app files -chown -R root: $final_path -chown $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root: "$final_path" +chown $app: "$final_path" + mkdir -p "$final_path/live/log" chown -R $app: "$final_path/live/log/" mkdir -p "$final_path/live/tmp" diff --git a/scripts/restore b/scripts/restore index e2d51a7..a83f92c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -80,12 +80,16 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # Restore permissions on app files -chown -R root: $final_path -chown $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root: "$final_path" +chown $app: "$final_path" + mkdir -p "$final_path/live/log" chown -R $app: "$final_path/live/log/" mkdir -p "$final_path/live/tmp" chown -R $app: "$final_path/live/tmp/" + mkdir -p "/var/log/$app" chown -R $app: "/var/log/$app" diff --git a/scripts/upgrade b/scripts/upgrade index 69c285b..b566fff 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -323,8 +323,11 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # Set permissions to app files -chown -R root: $final_path -chown $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root: "$final_path" +chown $app: "$final_path" + mkdir -p "$final_path/live/log" chown -R $app: "$final_path/live/log/" mkdir -p "$final_path/live/tmp" From 78f480a4c85f93171e319707b32b1c9eba9d0d10 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 22:39:00 +0200 Subject: [PATCH 07/15] Re-add variables for now --- scripts/install | 15 ++++++++++++--- scripts/upgrade | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index fcb659b..9fccd43 100755 --- a/scripts/install +++ b/scripts/install @@ -103,7 +103,10 @@ ynh_setup_source --dest_dir="$final_path/live" ynh_script_progression --message="Configuring nginx web server..." --weight=3 # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "\ + port \ + access_domain \ + " #================================================= # CREATE DEDICATED USER @@ -205,7 +208,10 @@ done ynh_script_progression --message="Configuring a systemd service..." --weight=4 # Create a dedicated systemd config -ynh_add_systemd_config +ynh_add_systemd_config --others_var="\ + port \ + RUBY_VERSION \ +" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -261,7 +267,10 @@ ynh_script_progression --message="Configuring fail2ban..." --weight=1 # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" -ynh_add_fail2ban_config --use_template +ynh_add_fail2ban_config --use_template --others_var="\ + domain \ + path_url \ + " #================================================= # SETUP SSOWAT diff --git a/scripts/upgrade b/scripts/upgrade index b566fff..95f9101 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -202,7 +202,10 @@ fi ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "\ + port \ + access_domain \ + " #================================================= # UPGRADE DEPENDENCIES @@ -305,7 +308,10 @@ done ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config -ynh_add_systemd_config +ynh_add_systemd_config --others_var="\ + port \ + RUBY_VERSION \ +" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -358,7 +364,10 @@ ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1 # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" -ynh_add_fail2ban_config --use_template +ynh_add_fail2ban_config --use_template --others_var="\ + domain \ + path_url \ + " #================================================= # START SYSTEMD SERVICE From 8532b3274ddb44f53ad54069fbba2ee041933d60 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 22:47:12 +0200 Subject: [PATCH 08/15] Fix systemd - Ruby path --- conf/systemd.service | 2 +- scripts/install | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 58e06c1..7334e8e 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -11,7 +11,7 @@ Group=__APP__ WorkingDirectory=__FINALPATH__/live Environment=RAILS_ENV=production Environment="PORT=__PORT__" -ExecStart=/opt/rbenv/versions/__RUBY_VERSION__/bin/bundle exec rails server +ExecStart=__RBENV_ROOT__/versions/__APP__/bin/bundle exec rails server ExecReload=/bin/kill -SIGUSR1 $MAINPID StandardOutput=append:/var/log/__APP__/__APP__.log StandardError=append:/var/log/__APP__/__APP__.log diff --git a/scripts/install b/scripts/install index 9fccd43..80dc886 100755 --- a/scripts/install +++ b/scripts/install @@ -210,7 +210,7 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=4 # Create a dedicated systemd config ynh_add_systemd_config --others_var="\ port \ - RUBY_VERSION \ + RBENV_ROOT \ " #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 95f9101..fa1c6c0 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -310,7 +310,7 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config --others_var="\ port \ - RUBY_VERSION \ + RBENV_ROOT \ " #================================================= From 3d94a01ca8a397a325a585f291295e7c21cee2ec Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 23:10:36 +0200 Subject: [PATCH 09/15] Fix permissions --- scripts/install | 3 +-- scripts/restore | 3 +-- scripts/upgrade | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 80dc886..c4c4ab1 100755 --- a/scripts/install +++ b/scripts/install @@ -233,8 +233,7 @@ ynh_script_progression --message="Securing files and directories..." --weight=1 # Set permissions to app files chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R root: "$final_path" -chown $app: "$final_path" +chown -R $app: "$final_path" mkdir -p "$final_path/live/log" chown -R $app: "$final_path/live/log/" diff --git a/scripts/restore b/scripts/restore index a83f92c..515cc8c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -82,8 +82,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path # Restore permissions on app files chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R root: "$final_path" -chown $app: "$final_path" +chown -R $app: "$final_path" mkdir -p "$final_path/live/log" chown -R $app: "$final_path/live/log/" diff --git a/scripts/upgrade b/scripts/upgrade index fa1c6c0..f226d21 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -331,8 +331,7 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" # Set permissions to app files chmod 750 "$final_path" chmod -R o-rwx "$final_path" -chown -R root: "$final_path" -chown $app: "$final_path" +chown -R $app: "$final_path" mkdir -p "$final_path/live/log" chown -R $app: "$final_path/live/log/" From 1c4121034198eccd4807ccfb331be1f57e34a3d2 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sat, 1 May 2021 23:24:47 +0200 Subject: [PATCH 10/15] Update check_process --- check_process | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/check_process b/check_process index a518fee..9105f9c 100644 --- a/check_process +++ b/check_process @@ -17,8 +17,10 @@ setup_private=1 setup_public=1 upgrade=1 + # 3.20.5~ynh2 + upgrade=1 from_commit=e8db15c97db16f68d6453970a9dff74d5136017b # 3.13.6~ynh4 - upgrade=1 from_commit=bdb0c5049c8eacbef68059d2821353d0e0345290 + #upgrade=1 from_commit=bdb0c5049c8eacbef68059d2821353d0e0345290 # 3.13.6~ynh2 #upgrade=1 from_commit=e755357f8306805084317c81e85807ed87fdbd47 # 3.13.6~ynh1 @@ -36,7 +38,7 @@ Email= Notification= ;;; Upgrade options - ; commit=bdb0c5049c8eacbef68059d2821353d0e0345290 - name=3.13.6~ynh4 + ; commit=e8db15c97db16f68d6453970a9dff74d5136017b + name=3.20.5~ynh2 manifest_arg=domain=DOMAIN&path=PATH&is_public=1 From 973ece4e336f252ccbab7a83fe7a78d46bda3f14 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens <46000361+FabianWilkens@users.noreply.github.com> Date: Sat, 1 May 2021 23:35:23 +0200 Subject: [PATCH 11/15] Delete ynh_install_ruby --- scripts/ynh_install_ruby | 147 --------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 scripts/ynh_install_ruby diff --git a/scripts/ynh_install_ruby b/scripts/ynh_install_ruby deleted file mode 100644 index 0e4f85a..0000000 --- a/scripts/ynh_install_ruby +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash - -# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args - -rbenv_install_dir="/opt/rbenv" -# 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 -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 -SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > "../conf/rbenv.src" - # Download and extract rbenv - ynh_setup_source "$rbenv_install_dir" rbenv - - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20201210.tar.gz -SOURCE_SUM=256c7c29afe9ec01850e788ce4e4f496a215ab10083ea7cc9cad6dd8f03b6c5e" > "../conf/ruby-build.src" - # Download and extract ruby-build - ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build - - (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 -# -# 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) -# -# Don't forget to execute ruby-dependent command in a login environment -# (e.g. sudo --login option) -# 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 -# | 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. -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 "$@" - - # Create $rbenv_install_dir - mkdir -p "$rbenv_install_dir/plugins/ruby-build" - - # Load rbenv path in PATH - CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # 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 "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 - - # Restore /usr/local/bin in PATH (if needed) - PATH=$CLEAR_PATH - - # And replace the old ruby binary - test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby - - # Install the requested version of ruby - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version - - # Store the ID of this app and the version of ruby requested for it - echo "$YNH_APP_INSTANCE_NAME:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version" - - # Store ruby_version into the config of this app - ynh_app_setting_set $app ruby_version $ruby_version - - # 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 - - # Load the right environment for the Installation - eval "$(rbenv init -)" - - (cd $final_path - rbenv local $ruby_version) -} - -# 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. -# -# usage: ynh_remove_ruby -ynh_remove_ruby () { - ruby_version=$(ynh_app_setting_get $app ruby_version) - - # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$ruby_version/d" "$rbenv_install_dir/ynh_app_version" - - # 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 - - # 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" - - # Remove rbenv environment configuration - rm /etc/profile.d/rbenv.sh - fi -} - From ff55a8a696b4a308160bf586e80952fd7c5f93f0 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sun, 2 May 2021 11:46:59 +0200 Subject: [PATCH 12/15] Re-add variables for now --- scripts/change_url | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 0d9b672..a9b7488 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -95,7 +95,10 @@ then domain="$old_domain" path_url="$new_path" # Create a dedicated nginx config - ynh_add_nginx_config + ynh_add_nginx_config "\ + port \ + access_domain\ + " fi # Change the domain for nginx @@ -149,7 +152,10 @@ domain=$new_domain path_url=$new_path # Create a dedicated fail2ban config touch "/var/log/$app/$app.log" -ynh_add_fail2ban_config --use_template +ynh_add_fail2ban_config --use_template --others_var="\ + domain \ + path_url \ + " #================================================= # GENERIC FINALISATION From bfeeaa4b6fbe4061ab6e418a9e11072dbdbaa4bc Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sun, 2 May 2021 11:47:41 +0200 Subject: [PATCH 13/15] Switch to ynh_exec_as --- scripts/_common.sh | 21 --------------------- scripts/install | 12 ++++++------ scripts/upgrade | 12 ++++++------ 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 7c70401..42bf07a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -18,27 +18,6 @@ pkg_dependencies="\ # PERSONAL HELPERS #================================================= -# Execute a command as another user with login -# (hence in user home dir, with prior loading of .profile, etc.) -# usage: exec_login_as USER COMMAND [ARG ...] -exec_login_as() { - local user=$1 - shift 1 - exec_as $user --login "$@" -} -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -exec_as() { - local user=$1 - shift 1 - - if [[ $user = $(whoami) ]]; then - eval "$@" - else - sudo -u "$user" "$@" - fi -} - # Check if service is ready is_service_ready() { for ((i = 0 ; i < 15 ; i++)) diff --git a/scripts/install b/scripts/install index c4c4ab1..dd9fc71 100755 --- a/scripts/install +++ b/scripts/install @@ -168,12 +168,12 @@ ynh_script_progression --message="Installing Standard Notes - Syncing Server..." chown -R $app: "$final_path" pushd "$final_path/live" - exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' - exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' - exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate --quiet - exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:seed --quiet -# exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet + ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' + ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' + ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate --quiet + ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:seed --quiet +# ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet popd #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f226d21..84c428f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -268,12 +268,12 @@ then chown -R $app: "$final_path" pushd "$final_path/live" - exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' - exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' - exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate --quiet - exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:seed --quiet -# exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet + ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' + ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' + ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate --quiet + ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:seed --quiet +# ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet popd fi From 88a175c8efd5ff53ef8c82c7c681829775ea0e04 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sun, 2 May 2021 11:57:39 +0200 Subject: [PATCH 14/15] Moved ynh_send_readme_to_admin__2 --- scripts/_common.sh | 137 --------------------------- scripts/change_url | 1 + scripts/install | 1 + scripts/upgrade | 1 + scripts/ynh_send_readme_to_admin__2 | 140 ++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 137 deletions(-) create mode 100644 scripts/ynh_send_readme_to_admin__2 diff --git a/scripts/_common.sh b/scripts/_common.sh index 42bf07a..4c98517 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -35,144 +35,7 @@ is_service_ready() { # EXPERIMENTAL HELPERS #================================================= -# Send an email to inform the administrator -# -# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] -# | arg: -m --app_message= - The file with the content to send to the administrator. -# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root -# example: "root admin@domain" -# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you -# example: "root admin@domain user1 user2" -# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade' -ynh_send_readme_to_admin() { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= ) - local app_message - local recipients - local type - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - app_message="${app_message:-}" - recipients="${recipients:-root}" - type="${type:-install}" - - # Get the value of admin_mail_html - admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) - admin_mail_html="${admin_mail_html:-0}" - - # Retrieve the email of users - find_mails () { - local list_mails="$1" - local mail - local recipients=" " - # Read each mail in argument - for mail in $list_mails - do - # Keep root or a real email address as it is - if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" - then - recipients="$recipients $mail" - else - # But replace an user name without a domain after by its email - if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) - then - recipients="$recipients $mail" - fi - fi - done - echo "$recipients" - } - recipients=$(find_mails "$recipients") - - # Subject base - local mail_subject="☁️🆈🅽🅷☁️: \`$app\`" - - # Adapt the subject according to the type of mail required. - if [ "$type" = "backup" ]; then - mail_subject="$mail_subject has just been backup." - elif [ "$type" = "change_url" ]; then - mail_subject="$mail_subject has just been moved to a new URL!" - elif [ "$type" = "remove" ]; then - mail_subject="$mail_subject has just been removed!" - elif [ "$type" = "restore" ]; then - mail_subject="$mail_subject has just been restored!" - elif [ "$type" = "upgrade" ]; then - mail_subject="$mail_subject has just been upgraded!" - else # install - mail_subject="$mail_subject has just been installed!" - fi - - local mail_message="This is an automated message from your beloved YunoHost server. - -Specific information for the application $app. - -$(if [ -n "$app_message" ] -then - cat "$app_message" -else - echo "...No specific information..." -fi) - ---- -Automatic diagnosis data from YunoHost - -__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__" - - # Store the message into a file for further modifications. - echo "$mail_message" > mail_to_send - - # If a html email is required. Apply html tags to the message. - if [ "$admin_mail_html" -eq 1 ] - then - # Insert 'br' tags at each ending of lines. - ynh_replace_string "$" "
" mail_to_send - - # Insert starting HTML tags - sed --in-place '1s@^@\n\n\n\n@' mail_to_send - - # Keep tabulations - ynh_replace_string " " "\ \ " mail_to_send - ynh_replace_string "\t" "\ \ " mail_to_send - - # Insert url links tags - ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send - - # Insert pre tags - ynh_replace_string "__PRE_TAG1__" "
" mail_to_send
-		ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
-
-		# Insert finishing HTML tags
-		echo -e "\n\n" >> mail_to_send
-
-	# Otherwise, remove tags to keep a plain text.
-	else
-		# Remove URL tags
-		ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
-		ynh_replace_string "__URL_TAG2__" ": " mail_to_send
-
-		# Remove PRE tags
-		ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
-	fi
-
-	# Define binary to use for mail command
-	if [ -e /usr/bin/bsd-mailx ]
-	then
-		local mail_bin=/usr/bin/bsd-mailx
-	else
-		local mail_bin=/usr/bin/mail.mailutils
-	fi
-
-	if [ "$admin_mail_html" -eq 1 ]
-	then
-		content_type="text/html"
-	else
-		content_type="text/plain"
-	fi
-
-	# Send the email to the recipients
-	cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
-}
 
 #=================================================
 # FUTURE OFFICIAL HELPERS
diff --git a/scripts/change_url b/scripts/change_url
index a9b7488..2bb06bf 100644
--- a/scripts/change_url
+++ b/scripts/change_url
@@ -7,6 +7,7 @@
 #=================================================
 
 source _common.sh
+source ynh_send_readme_to_admin__2
 source /usr/share/yunohost/helpers
 
 #=================================================
diff --git a/scripts/install b/scripts/install
index dd9fc71..3d4c995 100755
--- a/scripts/install
+++ b/scripts/install
@@ -9,6 +9,7 @@
 source _common.sh
 source ynh_install_ruby__2
 source ynh_redis
+source ynh_send_readme_to_admin__2
 source /usr/share/yunohost/helpers
 
 #=================================================
diff --git a/scripts/upgrade b/scripts/upgrade
index 84c428f..57f3396 100755
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -9,6 +9,7 @@
 source _common.sh
 source ynh_install_ruby__2
 source ynh_redis
+source ynh_send_readme_to_admin__2
 source /usr/share/yunohost/helpers
 
 #=================================================
diff --git a/scripts/ynh_send_readme_to_admin__2 b/scripts/ynh_send_readme_to_admin__2
new file mode 100644
index 0000000..06cff8c
--- /dev/null
+++ b/scripts/ynh_send_readme_to_admin__2
@@ -0,0 +1,140 @@
+#!/bin/bash
+
+# Send an email to inform the administrator
+#
+# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
+# | arg: -m --app_message= - The file with the content to send to the administrator.
+# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
+#	example: "root admin@domain"
+#	If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
+#	example: "root admin@domain user1 user2"
+# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
+ynh_send_readme_to_admin() {
+	# Declare an array to define the options of this helper.
+	declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
+	local app_message
+	local recipients
+	local type
+	# Manage arguments with getopts
+
+	ynh_handle_getopts_args "$@"
+	app_message="${app_message:-}"
+	recipients="${recipients:-root}"
+	type="${type:-install}"
+
+	# Get the value of admin_mail_html
+	admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
+	admin_mail_html="${admin_mail_html:-0}"
+
+	# Retrieve the email of users
+	find_mails () {
+		local list_mails="$1"
+		local mail
+		local recipients=" "
+		# Read each mail in argument
+		for mail in $list_mails
+		do
+			# Keep root or a real email address as it is
+			if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
+			then
+				recipients="$recipients $mail"
+			else
+				# But replace an user name without a domain after by its email
+				if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
+				then
+					recipients="$recipients $mail"
+				fi
+			fi
+		done
+		echo "$recipients"
+	}
+	recipients=$(find_mails "$recipients")
+
+	# Subject base
+	local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
+
+	# Adapt the subject according to the type of mail required.
+	if [ "$type" = "backup" ]; then
+		mail_subject="$mail_subject has just been backup."
+	elif [ "$type" = "change_url" ]; then
+		mail_subject="$mail_subject has just been moved to a new URL!"
+	elif [ "$type" = "remove" ]; then
+		mail_subject="$mail_subject has just been removed!"
+	elif [ "$type" = "restore" ]; then
+		mail_subject="$mail_subject has just been restored!"
+	elif [ "$type" = "upgrade" ]; then
+		mail_subject="$mail_subject has just been upgraded!"
+	else	# install
+		mail_subject="$mail_subject has just been installed!"
+	fi
+
+	local mail_message="This is an automated message from your beloved YunoHost server.
+
+Specific information for the application $app.
+
+$(if [ -n "$app_message" ]
+then
+	cat "$app_message"
+else
+	echo "...No specific information..."
+fi)
+
+---
+Automatic diagnosis data from YunoHost
+
+__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
+
+	# Store the message into a file for further modifications.
+	echo "$mail_message" > mail_to_send
+
+	# If a html email is required. Apply html tags to the message.
+ 	if [ "$admin_mail_html" -eq 1 ]
+ 	then
+		# Insert 'br' tags at each ending of lines.
+		ynh_replace_string "$" "
" mail_to_send + + # Insert starting HTML tags + sed --in-place '1s@^@\n\n\n\n@' mail_to_send + + # Keep tabulations + ynh_replace_string " " "\ \ " mail_to_send + ynh_replace_string "\t" "\ \ " mail_to_send + + # Insert url links tags + ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send + + # Insert pre tags + ynh_replace_string "__PRE_TAG1__" "
" mail_to_send
+		ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
+
+		# Insert finishing HTML tags
+		echo -e "\n\n" >> mail_to_send
+
+	# Otherwise, remove tags to keep a plain text.
+	else
+		# Remove URL tags
+		ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
+		ynh_replace_string "__URL_TAG2__" ": " mail_to_send
+
+		# Remove PRE tags
+		ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
+	fi
+
+	# Define binary to use for mail command
+	if [ -e /usr/bin/bsd-mailx ]
+	then
+		local mail_bin=/usr/bin/bsd-mailx
+	else
+		local mail_bin=/usr/bin/mail.mailutils
+	fi
+
+	if [ "$admin_mail_html" -eq 1 ]
+	then
+		content_type="text/html"
+	else
+		content_type="text/plain"
+	fi
+
+	# Send the email to the recipients
+	cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
+}

From ac637ae142be33ea501075dbaa5c60cc68e71e1d Mon Sep 17 00:00:00 2001
From: Fabian Wilkens 
Date: Sun, 2 May 2021 12:08:57 +0200
Subject: [PATCH 15/15] Fix wrong required yunohost version

---
 manifest.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/manifest.json b/manifest.json
index 3ab4ab5..7989f35 100644
--- a/manifest.json
+++ b/manifest.json
@@ -13,7 +13,7 @@
         "email": "46000361+FabianWilkens@users.noreply.github.com"
     },
     "requirements": {
-        "yunohost": ">= 4.1.2"
+        "yunohost": ">= 4.1.7"
     },
     "multi_instance": true,
     "services": [