From 5ce2a24649e12a087ce2a424d418262b1425ffb5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:10:38 +0100 Subject: [PATCH 01/29] ynh_ruby_3 --- conf/cron | 10 +- scripts/install | 27 +-- scripts/remove | 2 +- scripts/upgrade | 26 +-- scripts/ynh_install_ruby__2 | 322 ++++++++++++++++++++++-------------- 5 files changed, 231 insertions(+), 156 deletions(-) diff --git a/conf/cron b/conf/cron index 776808b..a15c428 100644 --- a/conf/cron +++ b/conf/cron @@ -1,5 +1,5 @@ -@daily cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove-orphans -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl accounts cull -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl statuses remove -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl preview_cards remove +@daily cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl media remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl media remove-orphans +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl accounts cull +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl statuses remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl preview_cards remove diff --git a/scripts/install b/scripts/install index 7d21d45..204bb52 100644 --- a/scripts/install +++ b/scripts/install @@ -75,9 +75,10 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream #================================================= ynh_script_progression --message="Installing dependencies..." -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # CREATE A POSTGRESQL DATABASE @@ -142,10 +143,10 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Installing Ruby..." -ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" - $RBENV_ROOT/versions/$app/bin/gem update --system - $RBENV_ROOT/versions/$app/bin/gem install bundler:$BUNDLER_VERSION --no-document + ynh_use_ruby + $ynh_gem update --system + $ynh_gem install bundler:$BUNDLER_VERSION --no-document popd #================================================= @@ -181,17 +182,17 @@ ynh_script_progression --message="Installing Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" + sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config deployment 'true' + sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config without 'development test' + sudo -u $app $ynh_ruby_load_path $ruby_path/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_use_nodejs - sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config deployment 'true' - sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config without 'development test' - sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - sudo -u $app PATH=$PATH yarn install --pure-lockfile + sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile echo "SAFETY_ASSURED=1">> $config - sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails db:setup --quiet - sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:precompile --quiet - sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt - sudo -u $app RAILS_ENV=production PATH=$PATH bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null - sudo -u $app RAILS_ENV=production PATH=$PATH bin/tootctl accounts modify "$admin" --approve + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails db:setup --quiet + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:precompile --quiet + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/tootctl accounts modify "$admin" --approve popd vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") diff --git a/scripts/remove b/scripts/remove index 6b16380..8a465a4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -73,8 +73,8 @@ ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_ruby -ynh_remove_app_dependencies ynh_remove_nodejs +ynh_remove_app_dependencies ynh_remove_extra_repo #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index bbbe50b..27aaff0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -184,10 +184,10 @@ ynh_add_nginx_config 'port_web port_stream' #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_remove_nodejs -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # CREATE DEDICATED USER @@ -220,10 +220,10 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Installing Ruby..." -ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" - gem update --system - gem install bundler:$BUNDLER_VERSION --no-document + ynh_use_ruby + $ynh_gem update --system + $ynh_gem install bundler:$BUNDLER_VERSION --no-document popd #================================================= @@ -243,15 +243,15 @@ ynh_script_progression --message="Upgrading Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" + sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config deployment 'true' + sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config without 'development test' + sudo -u $app $ynh_ruby_load_path $ruby_path/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_use_nodejs - sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config deployment 'true' - sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config without 'development test' - sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - sudo -u $app PATH=$PATH yarn install --pure-lockfile - sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:clean - sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:precompile - sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails db:migrate - sudo -u $app RAILS_ENV=production PATH=$PATH bin/tootctl cache clear + sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:clean + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:precompile + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails db:migrate + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/tootctl cache clear popd #================================================= diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 1d9bf8d..b8de713 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -1,11 +1,10 @@ #!/bin/bash -# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args - rbenv_version=1.1.2 -rbenv_rubybuild_version=20201225 +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" @@ -14,37 +13,104 @@ export RBENV_ROOT="$rbenv_install_dir" # [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-${rbenv_rubybuild_version}" + 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 + # 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 + # 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${rbenv_rubybuild_version}.tar.gz + # 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 + # 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 ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz + # 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 ruby-build - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases + # 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) + (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 + # 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. +# 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 2.7.12 or higher. +ynh_use_ruby () { + # 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 + ruby_path="$PATH" + # Create an alias to easily load the PATH + ynh_ruby_load_path="PATH=$ruby_path" + + # Sets the local application-specific Ruby version + (cd $final_path + rbenv local $ruby_version) } # Install a specific version of Ruby @@ -64,132 +130,140 @@ fi # # usage: ynh_install_ruby --ruby_version=ruby_version # | arg: -v, --ruby_version= - Version of ruby to install. +# +# 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= ) - 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 "$@" - # Store ruby_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version + # 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" + # Create $rbenv_install_dir if doesn't exist already + mkdir -p "$rbenv_install_dir/plugins/ruby-build" - # Create the file if doesn't exist already - touch "$rbenv_install_dir/ynh_app_version" + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - # 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:@@') - # 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 - # 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 ${rbenv_rubybuild_version} - 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 - 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 - - # Do not add twice the same line - if ! grep --quiet "$YNH_APP_INSTANCE_NAME:$ruby_version" "$rbenv_install_dir/ynh_app_version" - then - - # Remove previous version - if grep --quiet "$YNH_APP_INSTANCE_NAME:" "$rbenv_install_dir/ynh_app_version" + # 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 + elif dpkg --compare-versions "$($rbenv_install_dir/plugins/rbenv-aliases/bin/rbenv-aliases --version | cut -d" " -f2)" lt $rbenv_aliases_version + then + ynh_install_rbenv + fi + + # 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 + 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 + + # Remove app virtualenv + if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME" 1>/dev/null 2>&1` then - if grep --quiet "$YNH_APP_INSTANCE_NAME" $(rbenv alias --list) - then rbenv alias $YNH_APP_INSTANCE_NAME --remove - fi - sed --in-place "/$YNH_APP_INSTANCE_NAME:/d" "$rbenv_install_dir/ynh_app_version" fi - # 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" - fi + # Create app virtualenv + rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version - # Remove no more needed Ruby version - installed_ruby_version=$(rbenv versions --bare --skip-aliases | grep -Ev '/') - for installed_version in $installed_ruby_version - do - if ! grep --quiet "$installed_version" "$rbenv_install_dir/ynh_app_version" - then - ynh_print_info --message="Removing of ruby-"$installed_version - $rbenv_install_dir/bin/rbenv uninstall --force $installed_version - fi - done + # Cleanup Ruby versions + ynh_cleanup_ruby - # Set environment for Ruby users - echo "#rbenv + # 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 environment - eval "$(rbenv init -)" - - (cd $final_path - rbenv local $ruby_version) - - rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version + # Load the environment + eval "$(rbenv init -)" } # 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 () { - local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) + local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) - # Load rbenv path in PATH - CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + # 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:@@') + # 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 + rbenv alias $YNH_APP_INSTANCE_NAME --remove - # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$ruby_version/d" "$rbenv_install_dir/ynh_app_version" + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version - # If no other app uses this version of Ruby, remove it. - if ! grep --quiet "$ruby_version" "$rbenv_install_dir/ynh_app_version" - then - ynh_print_info --message="Removing of Ruby-"$ruby_version - $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_print_info --message="Removing of rbenv" - ynh_secure_remove --file="$rbenv_install_dir" - # Remove rbenv environment configuration - rm /etc/profile.d/rbenv.sh - fi + # 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 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 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 +} \ No newline at end of file From 9d612530cae529c94281cc089f13e5cf8eb56719 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:37:12 +0100 Subject: [PATCH 02/29] Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b8de713..0488d3c 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -87,6 +87,7 @@ SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > " # # 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" From 8e84376b47555be3c88b1475f54f0fa232d115b8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:52:44 +0100 Subject: [PATCH 03/29] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 204bb52..208b0d2 100644 --- a/scripts/install +++ b/scripts/install @@ -125,7 +125,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # ADD SWAP IF NEEDED #================================================= -ynh_script_progression --message="Adding swap is needed..." +ynh_script_progression --message="Adding swap if needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 From 05e04a31490bb0ce04b0ad2d0d9133c83614650d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:52:48 +0100 Subject: [PATCH 04/29] Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 0488d3c..78f65ad 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -105,9 +105,8 @@ ynh_use_ruby () { if [[ :$PATH: != *":$ruby_path"* ]]; then PATH="$ruby_path:$PATH" fi - ruby_path="$PATH" # Create an alias to easily load the PATH - ynh_ruby_load_path="PATH=$ruby_path" + ynh_ruby_load_path="PATH=$PATH" # Sets the local application-specific Ruby version (cd $final_path From 560506c3e74bc7a2f7923b537d27c2b66079ce47 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 02:15:48 +0100 Subject: [PATCH 05/29] fix bin/tootctl --- conf/cron | 10 +++++----- scripts/install | 4 ++-- scripts/upgrade | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/conf/cron b/conf/cron index a15c428..776808b 100644 --- a/conf/cron +++ b/conf/cron @@ -1,5 +1,5 @@ -@daily cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl media remove -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl media remove-orphans -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl accounts cull -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl statuses remove -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production __RUBY_PATH__/tootctl preview_cards remove +@daily cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove-orphans +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl accounts cull +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl statuses remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl preview_cards remove diff --git a/scripts/install b/scripts/install index 208b0d2..977f0b6 100644 --- a/scripts/install +++ b/scripts/install @@ -191,8 +191,8 @@ pushd "$final_path/live" sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails db:setup --quiet sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:precompile --quiet sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/tootctl accounts modify "$admin" --approve + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts modify "$admin" --approve popd vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") diff --git a/scripts/upgrade b/scripts/upgrade index 27aaff0..2e8753b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -251,7 +251,7 @@ pushd "$final_path/live" sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:clean sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:precompile sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails db:migrate - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/tootctl cache clear + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl cache clear popd #================================================= From 0fbd6a19a1f413cfa05480cf44f33f4edff0f655 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 18:44:44 +0100 Subject: [PATCH 06/29] Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 78f65ad..b517fd3 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -163,9 +163,6 @@ ynh_install_ruby () { 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 - elif dpkg --compare-versions "$($rbenv_install_dir/plugins/rbenv-aliases/bin/rbenv-aliases --version | cut -d" " -f2)" lt $rbenv_aliases_version then ynh_install_rbenv fi @@ -266,4 +263,4 @@ ynh_cleanup_ruby () { ynh_secure_remove --file="$rbenv_install_dir" rm /etc/profile.d/rbenv.sh fi -} \ No newline at end of file +} From c4c79475213f752a42d427a9be4be25b5dcca02e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 20:17:05 +0100 Subject: [PATCH 07/29] simplification --- scripts/_common.sh | 2 +- scripts/install | 22 +++++++++++----------- scripts/restore | 4 ++-- scripts/upgrade | 20 ++++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 1c28aec..b6f4796 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,7 +10,7 @@ pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git MEMORY_NEEDED="2560" RUBY_VERSION="2.7.2" -BUNDLER_VERSION="1.17.3" + NODEJS_VERSION="12" #================================================= diff --git a/scripts/install b/scripts/install index 977f0b6..a390c66 100644 --- a/scripts/install +++ b/scripts/install @@ -145,8 +145,8 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - $ynh_gem update --system - $ynh_gem install bundler:$BUNDLER_VERSION --no-document + ynh_gem update --system + ynh_gem install bundler --no-document popd #================================================= @@ -182,17 +182,17 @@ ynh_script_progression --message="Installing Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" - sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config deployment 'true' - sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config without 'development test' - sudo -u $app $ynh_ruby_load_path $ruby_path/bundle install -j$(getconf _NPROCESSORS_ONLN) + sudo -u $app bin/bundle config deployment 'true' + sudo -u $app bin/bundle config without 'development test' + sudo -u $app bin/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_use_nodejs sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile echo "SAFETY_ASSURED=1">> $config - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails db:setup --quiet - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:precompile --quiet - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts modify "$admin" --approve + sudo -u $app RAILS_ENV=production bin/bundle exec rails db:setup --quiet + sudo -u $app RAILS_ENV=production bin/bundle exec rails assets:precompile --quiet + sudo -u $app RAILS_ENV=production bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt + sudo -u $app RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null + sudo -u $app RAILS_ENV=production bin/tootctl accounts modify "$admin" --approve popd vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") @@ -254,7 +254,7 @@ yunohost service add "$app-streaming" --description "$app streaming service" #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on" ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" diff --git a/scripts/restore b/scripts/restore index 6744ddb..19a7715 100644 --- a/scripts/restore +++ b/scripts/restore @@ -113,7 +113,7 @@ ynh_script_progression --message="Installing Ruby..." ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" gem update --system - gem install bundler:$BUNDLER_VERSION --no-document + gem install bundler --no-document popd #================================================= @@ -150,7 +150,7 @@ yunohost service add "$app-streaming" --description "$app streaming service" #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on" ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" diff --git a/scripts/upgrade b/scripts/upgrade index 2e8753b..3f81e57 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -222,8 +222,8 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - $ynh_gem update --system - $ynh_gem install bundler:$BUNDLER_VERSION --no-document + ynh_gem update --system + ynh_gem install bundler --no-document popd #================================================= @@ -243,15 +243,15 @@ ynh_script_progression --message="Upgrading Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" - sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config deployment 'true' - sudo -u $app $ynh_ruby_load_path $ruby_path/bundle config without 'development test' - sudo -u $app $ynh_ruby_load_path $ruby_path/bundle install -j$(getconf _NPROCESSORS_ONLN) + sudo -u $app bin/bundle config deployment 'true' + sudo -u $app bin/bundle config without 'development test' + sudo -u $app bin/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_use_nodejs sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:clean - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails assets:precompile - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path $ruby_path/bundle exec rails db:migrate - sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl cache clear + sudo -u $app RAILS_ENV=production bin/bundle exec rails assets:clean + sudo -u $app RAILS_ENV=production bin/bundle exec rails assets:precompile + sudo -u $app RAILS_ENV=production bin/bundle exec rails db:migrate + sudo -u $app RAILS_ENV=production bin/tootctl cache clear popd #================================================= @@ -295,7 +295,7 @@ yunohost service add "$app-streaming" --description "$app streaming service" #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on" ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" From 91ef58fdea28d22e16999e72d2990281fb52b3c2 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 8 Mar 2021 00:45:35 +0100 Subject: [PATCH 08/29] Several fixes --- scripts/install | 22 +++++++++++----------- scripts/restore | 9 +++++---- scripts/upgrade | 18 +++++++++--------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/scripts/install b/scripts/install index a390c66..a3bc479 100644 --- a/scripts/install +++ b/scripts/install @@ -75,9 +75,9 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream #================================================= ynh_script_progression --message="Installing dependencies..." -ynh_install_app_dependencies $pkg_dependencies -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= @@ -145,7 +145,7 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - ynh_gem update --system + # ynh_gem update --system ynh_gem install bundler --no-document popd @@ -182,17 +182,17 @@ ynh_script_progression --message="Installing Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" - sudo -u $app bin/bundle config deployment 'true' - sudo -u $app bin/bundle config without 'development test' - sudo -u $app bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + sudo -u $app $ynh_ruby_load_path bin/bundle config deployment 'true' + sudo -u $app $ynh_ruby_load_path bin/bundle config without 'development test' + sudo -u $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_use_nodejs sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile echo "SAFETY_ASSURED=1">> $config - sudo -u $app RAILS_ENV=production bin/bundle exec rails db:setup --quiet - sudo -u $app RAILS_ENV=production bin/bundle exec rails assets:precompile --quiet - sudo -u $app RAILS_ENV=production bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt - sudo -u $app RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null - sudo -u $app RAILS_ENV=production bin/tootctl accounts modify "$admin" --approve + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:setup --quiet + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts modify "$admin" --approve popd vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") diff --git a/scripts/restore b/scripts/restore index 19a7715..64ac8f8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -101,19 +101,20 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Reinstalling dependencies..." +ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # INSTALLING RUBY AND BUNDLER #================================================= ynh_script_progression --message="Installing Ruby..." -ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" - gem update --system - gem install bundler --no-document + ynh_use_ruby + # ynh_gem update --system + ynh_gem install bundler --no-document popd #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3f81e57..7a095ad 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -185,8 +185,8 @@ ynh_add_nginx_config 'port_web port_stream' ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= @@ -222,7 +222,7 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - ynh_gem update --system + # ynh_gem update --system ynh_gem install bundler --no-document popd @@ -243,15 +243,15 @@ ynh_script_progression --message="Upgrading Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" - sudo -u $app bin/bundle config deployment 'true' - sudo -u $app bin/bundle config without 'development test' - sudo -u $app bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + sudo -u $app $ynh_ruby_load_path bin/bundle config deployment 'true' + sudo -u $app $ynh_ruby_load_path bin/bundle config without 'development test' + sudo -u $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_use_nodejs sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile - sudo -u $app RAILS_ENV=production bin/bundle exec rails assets:clean - sudo -u $app RAILS_ENV=production bin/bundle exec rails assets:precompile - sudo -u $app RAILS_ENV=production bin/bundle exec rails db:migrate - sudo -u $app RAILS_ENV=production bin/tootctl cache clear + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:clean + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate + sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl cache clear popd #================================================= From e4332ad1371693519afce985a7ac8a3b1853022b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 8 Mar 2021 00:57:36 +0100 Subject: [PATCH 09/29] ynh_gem update --- 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 a3bc479..a37bbba 100644 --- a/scripts/install +++ b/scripts/install @@ -145,7 +145,7 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - # ynh_gem update --system + ynh_gem update --system ynh_gem install bundler --no-document popd diff --git a/scripts/restore b/scripts/restore index 64ac8f8..a8cfd30 100644 --- a/scripts/restore +++ b/scripts/restore @@ -113,7 +113,7 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - # ynh_gem update --system + ynh_gem update --system ynh_gem install bundler --no-document popd diff --git a/scripts/upgrade b/scripts/upgrade index 7a095ad..aa96bef 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -222,7 +222,7 @@ ynh_script_progression --message="Installing Ruby..." pushd "$final_path/live" ynh_use_ruby - # ynh_gem update --system + ynh_gem update --system ynh_gem install bundler --no-document popd From a8cc57fe43d0de1e021fd22504cd28e0bd91a462 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 8 Mar 2021 21:38:00 +0100 Subject: [PATCH 10/29] spacing --- scripts/ynh_install_ruby__2 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b517fd3..1f965e3 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -88,6 +88,7 @@ SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > " # 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" From c4d58a6ba36fecffc7f5a0340ef969ffa3334adb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Mar 2021 22:51:42 +0100 Subject: [PATCH 11/29] Switch to git --- scripts/ynh_install_ruby__2 | 167 +++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 70 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 1f965e3..b3e3922 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -1,53 +1,18 @@ #!/bin/bash -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. @@ -110,8 +75,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_install_dir/bin/rbenv local $ruby_version + popd } # Install a specific version of Ruby @@ -141,12 +107,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" @@ -156,18 +116,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 @@ -175,17 +198,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 @@ -233,7 +260,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 @@ -245,13 +272,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 @@ -260,8 +287,8 @@ 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 05b6dc21ffacec0e7b97270bf80cc6a8a1753f65 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Mar 2021 23:41:08 +0100 Subject: [PATCH 12/29] Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b3e3922..89fbd05 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -155,10 +155,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 @@ -170,10 +170,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 @@ -222,7 +222,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 3fa6a835b570b181a2b5a95ac98c3b38f5738c3d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 13:00:18 +0100 Subject: [PATCH 13/29] Manage previous rbenv installation --- scripts/ynh_install_ruby__2 | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 89fbd05..7afe7b5 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -3,7 +3,7 @@ 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 } @@ -84,9 +84,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) # @@ -116,16 +113,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 9588b8da9393f874f8678b2aa56cdfea8da794a7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 15:05:48 +0100 Subject: [PATCH 14/29] Fix new rbenv install --list-all --- scripts/ynh_install_ruby__2 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 7afe7b5..f9cc22a 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -206,6 +206,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 5ce2de89b9f32a0bd18efbc498c94af3f9d64d84 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Mar 2021 00:48:54 +0100 Subject: [PATCH 15/29] Do not use 'yunohost app setting' --- scripts/ynh_install_ruby__2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index f9cc22a..9a63c67 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -275,7 +275,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 2c6c2c02a131700dd1a243e6c94af7d78274174a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Mar 2021 06:00:31 +0100 Subject: [PATCH 16/29] Fix repository detection --- scripts/ynh_install_ruby__2 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 9a63c67..a946903 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -118,7 +118,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 @@ -151,7 +151,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 @@ -166,7 +166,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 @@ -181,7 +181,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 b01227d32602fe2239f1c74fa8ac06940230c52e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Mar 2021 20:54:09 +0100 Subject: [PATCH 17/29] Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index a946903..fae1755 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -50,7 +50,7 @@ export RBENV_ROOT="$rbenv_install_dir" # # usage: ynh_use_ruby # -# Requires YunoHost version 2.7.12 or higher. +# Requires YunoHost version 3.2.2 or higher. ynh_use_ruby () { ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) @@ -95,7 +95,7 @@ ynh_use_ruby () { # usage: ynh_install_ruby --ruby_version=ruby_version # | arg: -v, --ruby_version= - Version of ruby to install. # -# Requires YunoHost version 2.7.12 or higher. +# 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 From 91ad69fd115476853be326470d230e3798ea8ec0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 23 Mar 2021 20:41:14 +0100 Subject: [PATCH 18/29] Upgrade version --- check_process | 4 ++++ manifest.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/check_process b/check_process index 72f8049..64394f4 100644 --- a/check_process +++ b/check_process @@ -26,6 +26,8 @@ upgrade=1 from_commit=74908bf3e70c134bc838c7db3ae8b5aa0938cd75 # 3.2.2~ynh1 upgrade=1 from_commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c + # 3.3.0~ynh1 + upgrade=1 from_commit=a7eb98db3fac0697b923072dcd78c1ca04bf0a12 backup_restore=1 multi_instance=1 port_already_use=0 @@ -48,3 +50,5 @@ Notification=all name=3.2.1~ynh2 ; commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c name=3.2.2~ynh1 + ; commit=a7eb98db3fac0697b923072dcd78c1ca04bf0a12 + name=3.3.0~ynh1 diff --git a/manifest.json b/manifest.json index 2d38584..5b89865 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A libre and federated social network.", "fr": "Un réseau social libre et fédéré." }, - "version": "3.3.0~ynh1", + "version": "3.3.0~ynh2", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": [ From b07683cc0130e0b5038371472aef015162759961 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 24 Mar 2021 19:58:27 +0100 Subject: [PATCH 19/29] Fix manually modified file --- scripts/install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index a37bbba..0b79b96 100644 --- a/scripts/install +++ b/scripts/install @@ -201,6 +201,8 @@ ynh_app_setting_set --app="$app" --key=vapid_private_key --value="$vapid_private vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt") ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_key" +ynh_delete_file_checksum --file="$config" + ynh_add_config --template="../conf/.env.production.sample" --destination="$config" ynh_secure_remove --file="$final_path/live/key.txt" From f376290f1397f56e8d12bad5d15ac952fbdc25c6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 10 Apr 2021 00:18:53 +0200 Subject: [PATCH 20/29] Apply example_ynh --- README.md | 4 ++-- README_fr.md | 4 ++-- check_process | 6 +++++- manifest.json | 22 +++++----------------- scripts/backup | 2 +- scripts/install | 42 +++++++++++++++++++----------------------- scripts/remove | 6 +++--- scripts/restore | 40 ++++++++++++++++++---------------------- scripts/upgrade | 41 ++++++++++++++++++----------------------- 9 files changed, 73 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index 5336221..a4bd460 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ LDAP authentication is activated. All YunoHost users can authenticate. #### Supported architectures -* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/) ## Links diff --git a/README_fr.md b/README_fr.md index 6553753..1f1fc84 100644 --- a/README_fr.md +++ b/README_fr.md @@ -59,8 +59,8 @@ L'authentification LDAP est activée. Tous les utilisateurs YunoHost peuvent s'a #### Architectures supportées -* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/) ## Liens diff --git a/check_process b/check_process index 72f8049..e187789 100644 --- a/check_process +++ b/check_process @@ -26,10 +26,12 @@ upgrade=1 from_commit=74908bf3e70c134bc838c7db3ae8b5aa0938cd75 # 3.2.2~ynh1 upgrade=1 from_commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c + # 3.3.0~ynh1 + upgrade=1 from_commit=1b7de8c3acc9607c619c02aae49a2485e40eef4d backup_restore=1 multi_instance=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Options Email=yalh@yahoo.com Notification=all @@ -48,3 +50,5 @@ Notification=all name=3.2.1~ynh2 ; commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c name=3.2.2~ynh1 + ; commit=1b7de8c3acc9607c619c02aae49a2485e40eef4d + name=3.3.0~ynh1 diff --git a/manifest.json b/manifest.json index 2d38584..d6aa9f1 100644 --- a/manifest.json +++ b/manifest.json @@ -6,10 +6,13 @@ "en": "A libre and federated social network.", "fr": "Un réseau social libre et fédéré." }, - "version": "3.3.0~ynh1", + "version": "3.3.0~ynh2", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", - "maintainer": [ + "maintainer": { + "name": "yalh76" + }, + "previous_maintainer": [ { "name": "cyp", "email": "cyp@rouquin.me" @@ -17,9 +20,6 @@ { "name": "nemsia", "email": "nemsia@nemsia.org" - }, - { - "name": "yalh76" } ], "requirements": { @@ -34,28 +34,16 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for Mastodon", - "fr": "Choisissez un domaine pour Mastodon" - }, "example": "example.com" }, { "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 c1d4f6f..590ce0f 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/install b/scripts/install index 7d21d45..da81c3b 100644 --- a/scripts/install +++ b/scripts/install @@ -76,9 +76,17 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream ynh_script_progression --message="Installing dependencies..." ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies +ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A POSTGRESQL DATABASE #================================================= @@ -103,22 +111,18 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path/live" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" + #================================================= # 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 'port_web port_stream' -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= # SPECIFIC SETUP #================================================= @@ -231,22 +235,14 @@ ynh_store_file_checksum --file="$config" #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions to app files -chown -R "$app": "$final_path" - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add "$app-web" --description "$app web service" -yunohost service add "$app-sidekiq" --description "$app sidekiq service" -yunohost service add "$app-streaming" --description "$app streaming service" +yunohost service add "$app-web" --description="$app web service" +yunohost service add "$app-sidekiq" --description="$app sidekiq service" +yunohost service add "$app-streaming" --description="$app streaming service" #================================================= # START SYSTEMD SERVICE @@ -275,7 +271,7 @@ ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --aut #================================================= # 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 6b16380..44c3bde 100644 --- a/scripts/remove +++ b/scripts/remove @@ -29,7 +29,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # 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-web" >/dev/null then ynh_script_progression --message="Removing $app-web service integration..." @@ -88,9 +88,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 6744ddb..f51537a 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 ../settings/scripts/ynh_install_ruby__2 source ../settings/scripts/ynh_add_swap @@ -25,7 +25,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 @@ -51,10 +51,18 @@ test ! -d $final_path \ #================================================= # 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" +#================================================= +# 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" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -62,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 - -#================================================= -# 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 @@ -102,7 +98,7 @@ ynh_add_swap --size=$swap_needed ynh_script_progression --message="Reinstalling dependencies..." ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies +ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= @@ -141,9 +137,9 @@ systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add "$app-web" --description "$app web service" -yunohost service add "$app-sidekiq" --description "$app sidekiq service" -yunohost service add "$app-streaming" --description "$app streaming service" +yunohost service add "$app-web" --description="$app web service" +yunohost service add "$app-sidekiq" --description="$app sidekiq service" +yunohost service add "$app-streaming" --description="$app streaming service" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index bbbe50b..c2c0819 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -49,7 +49,6 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." - # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all @@ -124,7 +123,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take ynh_backup_before_upgrade ynh_clean_setup () { ynh_clean_check_starting - # 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 @@ -141,6 +140,14 @@ ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped" ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -171,10 +178,14 @@ then ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" + #================================================= # 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 ynh_add_nginx_config 'port_web port_stream' @@ -189,14 +200,6 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -#================================================= -# 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 - #================================================= # SPECIFIC UPGRADE #================================================= @@ -273,22 +276,14 @@ ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions on app files -chown -R $app: $final_path - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add "$app-web" --description "$app web service" -yunohost service add "$app-sidekiq" --description "$app sidekiq service" -yunohost service add "$app-streaming" --description "$app streaming service" +yunohost service add "$app-web" --description="$app web service" +yunohost service add "$app-sidekiq" --description="$app sidekiq service" +yunohost service add "$app-streaming" --description="$app streaming service" #================================================= # START SYSTEMD SERVICE @@ -302,7 +297,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s #================================================= # 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 f19e49ae9861a93b22640f11437b749a006be2cd Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 10 Apr 2021 20:28:06 +0200 Subject: [PATCH 21/29] Apply example_ynh --- scripts/install | 45 ++++++++++++++++++++++----------------------- scripts/restore | 14 +++++++------- scripts/upgrade | 27 +++++++++++++++------------ 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/scripts/install b/scripts/install index 91133d3..cf1ccf3 100644 --- a/scripts/install +++ b/scripts/install @@ -154,9 +154,9 @@ pushd "$final_path/live" popd #================================================= -# MODIFY A CONFIG FILE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Adding a config file..." config="$final_path/live/.env.production" @@ -173,18 +173,32 @@ vapid_public_key="" ynh_add_config --template="../conf/.env.production.sample" --destination="$config" +chmod 400 "$config" +chown $app:$app "$config" + ynh_replace_string --match_string="registrations_mode: 'open'" --replace_string="registrations_mode: 'none'" --target_file="$final_path/live/config/settings.yml" ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="min_invite_role: 'none'" --target_file="$final_path/live/config/settings.yml" ynh_store_file_checksum --file="$final_path/live/config/settings.yml" +chmod 400 "$final_path/live/config/settings.yml" +chown $app:$app "$final_path/live/config/settings.yml" + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." + +# Create a dedicated systemd config +ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT" +ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT" +ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node" + #================================================= # INSTALLING MASTODON #================================================= ynh_script_progression --message="Installing Mastodon..." -chown -R "$app": "$final_path" - pushd "$final_path/live" sudo -u $app $ynh_ruby_load_path bin/bundle config deployment 'true' sudo -u $app $ynh_ruby_load_path bin/bundle config without 'development test' @@ -205,11 +219,14 @@ ynh_app_setting_set --app="$app" --key=vapid_private_key --value="$vapid_private vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt") ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_key" +ynh_secure_remove --file="$final_path/live/key.txt" + ynh_delete_file_checksum --file="$config" ynh_add_config --template="../conf/.env.production.sample" --destination="$config" -ynh_secure_remove --file="$final_path/live/key.txt" +chmod 400 "$config" +chown $app:$app "$config" #================================================= # SETUP THE CRON FILE @@ -218,24 +235,6 @@ ynh_script_progression --message="Setuping the cron file..." ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -# Create a dedicated systemd config -ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT" -ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT" -ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 3e50248..0b389f0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -92,6 +92,13 @@ fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." ynh_add_swap --size=$swap_needed +#================================================= +# RESTORE THE CRON FILE +#================================================= +ynh_script_progression --message="Restoring the cron file..." + +ynh_restore_file --origin_path="/etc/cron.d/$app" + #================================================= # REINSTALL DEPENDENCIES #================================================= @@ -151,13 +158,6 @@ ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" -#================================================= -# RESTORE THE CRON FILE -#================================================= -ynh_script_progression --message="Restoring the cron file..." - -ynh_restore_file --origin_path="/etc/cron.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index b4c16e1..870bd4c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -230,14 +230,27 @@ pushd "$final_path/live" popd #================================================= -# MODIFY A CONFIG FILE +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Updating a config file..." language="$(echo $language | head -c 2)" ynh_add_config --template="../conf/.env.production.sample" --destination="$config" +chmod 400 "$config" +chown $app:$app "$config" + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Upgrading systemd configuration..." + +# Create a dedicated systemd config +ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT" +ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT" +ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node" + #================================================= # UPGRADE MASTODON #================================================= @@ -264,16 +277,6 @@ ynh_script_progression --message="Setuping the cron file..." ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - -# Create a dedicated systemd config -ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT" -ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT" -ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node" - #================================================= # GENERIC FINALIZATION #================================================= From 533654acefffcd052b09a79a8ca53783d73ada6a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 11 Apr 2021 22:31:48 +0200 Subject: [PATCH 22/29] Fix rights --- scripts/install | 2 +- scripts/remove | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index cf1ccf3..cf972be 100644 --- a/scripts/install +++ b/scripts/install @@ -114,7 +114,7 @@ ynh_setup_source --dest_dir="$final_path/live" 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/remove b/scripts/remove index 586bf25..42b0109 100644 --- a/scripts/remove +++ b/scripts/remove @@ -64,7 +64,7 @@ ynh_remove_systemd_config --service="$app-streaming" ynh_script_progression --message="Removing the PostgreSQL database..." # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE DEPENDENCIES diff --git a/scripts/restore b/scripts/restore index 0b389f0..d6d587a 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 870bd4c..7122f77 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -180,7 +180,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 17c2d6b8c4f48f8dff77eb337327ec6421316d52 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 15 Apr 2021 20:28:26 +0200 Subject: [PATCH 23/29] Fix chmod --- 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 cf972be..a5e8ba6 100644 --- a/scripts/install +++ b/scripts/install @@ -112,7 +112,7 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path/live" -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" diff --git a/scripts/restore b/scripts/restore index d6d587a..e4a48fa 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:$app "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade index 7122f77..2300d2e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -178,7 +178,7 @@ then ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb" fi -chmod 750 "$final_path" +chmod -R 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" From 1684f2cf4d04b2a2f138db6b451af95e9f24c842 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 17 Apr 2021 18:31:31 +0200 Subject: [PATCH 24/29] Fix recursive chmod --- 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 a5e8ba6..cf972be 100644 --- a/scripts/install +++ b/scripts/install @@ -112,7 +112,7 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path/live" -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" diff --git a/scripts/restore b/scripts/restore index e4a48fa..d6d587a 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:$app "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade index 2300d2e..7122f77 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -178,7 +178,7 @@ then ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb" fi -chmod -R 750 "$final_path" +chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" From 98be88808aa5faa3251065ec09d844e4d10ee43c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 17 Apr 2021 18:51:14 +0200 Subject: [PATCH 25/29] 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 cf972be..f5da202 100644 --- a/scripts/install +++ b/scripts/install @@ -114,7 +114,7 @@ ynh_setup_source --dest_dir="$final_path/live" 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 diff --git a/scripts/restore b/scripts/restore index d6d587a..7a3808b 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 7122f77..86555dc 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -180,7 +180,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 From 1a2446992535ab2ac2676eee87dfc478b44bdceb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 17 Apr 2021 19:20:13 +0200 Subject: [PATCH 26/29] Fix source --- conf/app.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app.src b/conf/app.src index 6fb011a..37e25d1 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v3.3.0.tar.gz -SOURCE_SUM=ffbaeaf18d9c440ac61c6c5c29fd6581b88c1d2843170f2cb5f0fcf8dcc0ecd6 +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/ca3bc1b09f344f38164aa65d2554cf50d5c10cc0.tar.gz +SOURCE_SUM=bb151900d2e76754b2d1ccb0845ffa834d02c170fc1d87b9458b6c8ced26c4f5 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true From a81ad70b6a73814445c3bc7a624154326486ddb0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 19 Apr 2021 20:41:16 +0200 Subject: [PATCH 27/29] Update app.src --- conf/app.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app.src b/conf/app.src index 37e25d1..6383dac 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/ca3bc1b09f344f38164aa65d2554cf50d5c10cc0.tar.gz -SOURCE_SUM=bb151900d2e76754b2d1ccb0845ffa834d02c170fc1d87b9458b6c8ced26c4f5 +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/1efcbb9cfe36d4428ef6af988bb0d7b25ace3971.tar.gz +SOURCE_SUM=4ecbfd34ea37d739fbcec11cf9b812e8d8f60f6367f8ce255a062d5d64d92557 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true From 799587668ba8d57ab579092b76ce2e39c7373257 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 21 Apr 2021 20:31:39 +0200 Subject: [PATCH 28/29] Update check_process --- check_process | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/check_process b/check_process index b0acafe..1fb0ee9 100644 --- a/check_process +++ b/check_process @@ -17,17 +17,17 @@ # 3.1.2~ynh3 #upgrade=1 from_commit=6b30109fc986d83166b1805ec3ad7e28200e3743 # 3.1.2~ynh4 - upgrade=1 from_commit=d3df899e0a99a63ee1cf7ad845cc513aeaaf30ef + #upgrade=1 from_commit=d3df899e0a99a63ee1cf7ad845cc513aeaaf30ef # 3.2.0~ynh1 - upgrade=1 from_commit=bde14cc4496445fdfed4616ac44fc9527c8369fd + #upgrade=1 from_commit=bde14cc4496445fdfed4616ac44fc9527c8369fd # 3.2.1~ynh1 - upgrade=1 from_commit=248b717f373f3c82bdb19c33cf20980494608697 + #upgrade=1 from_commit=248b717f373f3c82bdb19c33cf20980494608697 # 3.2.1~ynh2 - upgrade=1 from_commit=74908bf3e70c134bc838c7db3ae8b5aa0938cd75 + #upgrade=1 from_commit=74908bf3e70c134bc838c7db3ae8b5aa0938cd75 # 3.2.2~ynh1 - upgrade=1 from_commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c + #upgrade=1 from_commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c # 3.3.0~ynh1 - upgrade=1 from_commit=a7eb98db3fac0697b923072dcd78c1ca04bf0a12 + #upgrade=1 from_commit=a7eb98db3fac0697b923072dcd78c1ca04bf0a12 backup_restore=1 multi_instance=1 port_already_use=0 From e2a23d46f649505a9ece78e1b3e4f0fd73196539 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 23 Apr 2021 13:04:54 +0200 Subject: [PATCH 29/29] Update check_process --- check_process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_process b/check_process index 1fb0ee9..1c35a30 100644 --- a/check_process +++ b/check_process @@ -31,7 +31,7 @@ backup_restore=1 multi_instance=1 port_already_use=0 - change_url=1 + change_url=0 ;;; Options Email=yalh@yahoo.com Notification=all