From 3843310bdf10db932fa6b10a5dfcb0e0cf22e143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 4 Oct 2023 12:18:39 +0200 Subject: [PATCH 01/11] start manifestv2 --- check_process | 24 --- conf/acropolis-sidekiq.service | 2 +- conf/acropolis-web.service | 4 +- conf/app.src | 7 - conf/nginx.conf | 2 +- manifest.json | 58 ------ manifest.toml | 94 +++++++++ scripts/_common.sh | 347 +-------------------------------- scripts/backup | 16 +- scripts/install | 131 ++----------- scripts/remove | 47 +---- scripts/restore | 54 ++--- scripts/upgrade | 70 +++---- scripts/ynh_ruby | 303 ++++++++++++++++++++++++++++ tests.toml | 13 ++ 15 files changed, 514 insertions(+), 658 deletions(-) delete mode 100644 check_process delete mode 100644 conf/app.src delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 scripts/ynh_ruby create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index 5a913f7..0000000 --- a/check_process +++ /dev/null @@ -1,24 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - is_public=1 - admin="john" - password="1Strong-Password" - email="admin@domain.tld" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - # 2022.01.29~ynh1 - upgrade=1 from_commit=dc712d6bf6dd2f67b9863b03b8a6a3705713a81c - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=0 -;;; Options -Email= -Notification=none diff --git a/conf/acropolis-sidekiq.service b/conf/acropolis-sidekiq.service index c4e9867..a287dff 100644 --- a/conf/acropolis-sidekiq.service +++ b/conf/acropolis-sidekiq.service @@ -5,7 +5,7 @@ After=network.target [Service] Type=simple User=__APP__ -WorkingDirectory=__FINALPATH__ +WorkingDirectory=__INSTALL_DIR__ Environment="RAILS_ENV=production" Environment="DB_POOL=25" Environment="MALLOC_ARENA_MAX=2" diff --git a/conf/acropolis-web.service b/conf/acropolis-web.service index 8beb608..a46b769 100644 --- a/conf/acropolis-web.service +++ b/conf/acropolis-web.service @@ -5,10 +5,10 @@ After=network.target [Service] Type=simple User=__APP__ -WorkingDirectory=__FINALPATH__ +WorkingDirectory=__INSTALL_DIR__ Environment="RAILS_ENV=production" Environment="PORT=__PORT_WEB__" -Environment=UNICORN_LISTENER=__FINALPATH__/tmp/sockets/unicorn.sock +Environment=UNICORN_LISTENER=__INSTALL_DIR__/tmp/sockets/unicorn.sock ExecStart=__RBENV_ROOT__/versions/__APP__/bin/bundle exec unicorn --config config/unicorn.rb -E production ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=60 diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 03a1013..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/magicstone-dev/acropolis/archive/f586f64b4cee0b2a50f45b5cf6de4e1fd749def8.tar.gz -SOURCE_SUM=716d9c5e1e8e7d2694dbe6d2c1b5e48e5a5537a29ec8a8d0a722e6750fffae56 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index f1c4a3a..ce59f6e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,7 +2,7 @@ client_max_body_size 100M; # add to v1.4 assets -root __FINALPATH__/public; +root __INSTALL_DIR__/public; location / { diff --git a/manifest.json b/manifest.json deleted file mode 100644 index c015beb..0000000 --- a/manifest.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "name": "Acropolis", - "id": "acropolis", - "packaging_format": 1, - "description": { - "en": "Dynamic fork of diaspora*'s federated social network", - "fr": "Fourche dynamique du réseau social fédéré de diaspora*" - }, - "version": "2022.01.29~ynh1", - "url": "https://github.com/magicstone-dev/acropolis", - "upstream": { - "license": "AGPL-3.0-or-later", - "website": "https://magicstone.dev", - "code": "https://github.com/magicstone-dev/acropolis" - }, - "license": "AGPL-3.0-or-later", - "maintainer": { - "name": "weex" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": false, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "default": true, - "help": { - "en": "For federation to work, this needs to be true. False is ok if you want to run a private instance." - } - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - }, - { - "name": "email", - "type": "string", - "ask": { - "en": "Enter email address for administative notifications." - } - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..a8a137c --- /dev/null +++ b/manifest.toml @@ -0,0 +1,94 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "acropolis" +name = "Acropolis" +description.en = "Dynamic fork of diaspora*'s federated social network" +description.fr = "Fourche dynamique du réseau social fédéré de diaspora*" + +version = "2022.01.29~ynh1" + +maintainers = ["weex"] + +[upstream] +license = "AGPL-3.0-or-later" +website = "https://magicstone.dev" +code = "https://github.com/magicstone-dev/acropolis" + +[integration] +yunohost = ">= 4.3.0" +architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +multi_instance = false +ldap = false +sso = false +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + + +[install] + [install.domain] + type = "domain" + + [install.admin] + type = "user" + + [install.init_main_permission] + help.en = "For federation to work, this needs to be true. False is ok if you want to run a private instance." + type = "group" + default = "visitors" + + [install.email] + ask.en = "Enter email address for administative notifications." + type = "string" + + [install.password] + type = "password" + +[resources] + [resources.sources.main] + url = "https://github.com/magicstone-dev/acropolis/archive/f586f64b4cee0b2a50f45b5cf6de4e1fd749def8.tar.gz" + sha256 = "716d9c5e1e8e7d2694dbe6d2c1b5e48e5a5537a29ec8a8d0a722e6750fffae56" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + web.default = 3000 + + [resources.apt] + packages = [ + "g++", + "libjemalloc1|libjemalloc2", + "libjemalloc-dev", + "zlib1g-dev", + "libreadline-dev", + "libpq-dev", + "libssl-dev", + "libyaml-dev", + "libcurl4-dev", + "libapr1-dev", + "libxslt1-dev", + "libidn11-dev", + "libxml2-dev", + "vim", + "imagemagick", + "postgresql", + "postgresql-server-dev-all", + "postgresql-contrib", + "optipng", + "jhead", + "jpegoptim", + "gifsicle", + "brotli", + "cmake", + "pkg-config" + ] + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 838ccf5..199ab3f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,25 +4,16 @@ # COMMON VARIABLES #================================================= -pkg_dependencies="g++ libjemalloc1|libjemalloc2 libjemalloc-dev zlib1g-dev libreadline-dev libpq-dev libssl-dev libyaml-dev libcurl4-dev libapr1-dev libxslt1-dev libidn11-dev libxml2-dev vim imagemagick postgresql postgresql-server-dev-all postgresql-contrib optipng jhead jpegoptim gifsicle brotli nodejs cmake pkg-config" - RUBY_VERSION="2.7.1" MEMORY_NEEDED="2560" +source ynh_ruby + #================================================= # PERSONAL HELPERS #================================================= -# Execute a command as another user with login -# (hence in user home dir, with prior loading of .profile, etc.) -# usage: exec_login_as USER COMMAND [ARG ...] -exec_login_as() { - local user=$1 - shift 1 - ynh_exec_as $user --login "$@" -} - # Returns true if a swap partition is enabled, false otherwise # usage: is_swap_present is_swap_present() { @@ -65,14 +56,6 @@ check_memory_requirements_upgrade() { } ynh_maintenance_mode_ON () { - # Load value of $path_url and $domain from the config if their not set - if [ -z $path_url ]; then - path_url=$(ynh_app_setting_get $app path) - fi - if [ -z $domain ]; then - domain=$(ynh_app_setting_get $app domain) - fi - # Create an html to serve as maintenance notice echo " @@ -94,10 +77,10 @@ ynh_maintenance_mode_ON () { " > "/var/www/html/maintenance.$app.html" # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. - echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice -rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect; + echo "# All request to the app will be redirected to ${path}_maintenance and fall on the maintenance notice +rewrite ^${path}/(.*)$ ${path}_maintenance/? redirect; # Use another location, to not be in conflict with the original config file -location ${path_url}_maintenance/ { +location ${path}_maintenance/ { alias /var/www/html/ ; try_files maintenance.$app.html =503; # Include SSOWAT user panel. @@ -106,7 +89,7 @@ include conf.d/yunohost_panel.conf.inc; # The current config file will redirect all requests to the root of the app. # To keep the full path, we can use the following rewrite rule: - # rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect; + # rewrite ^${path}/(.*)$ ${path}_maintenance/\$1? redirect; # The difference will be in the $1 at the end, which keep the following queries. # But, if it works perfectly for a html request, there's an issue with any php files. # This files are treated as simple files, and will be downloaded by the browser. @@ -116,16 +99,9 @@ include conf.d/yunohost_panel.conf.inc; } ynh_maintenance_mode_OFF () { - # Load value of $path_url and $domain from the config if their not set - if [ -z $path_url ]; then - path_url=$(ynh_app_setting_get $app path) - fi - if [ -z $domain ]; then - domain=$(ynh_app_setting_get $app domain) - fi - # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. - echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" + # Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app. + echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" systemctl reload nginx # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. @@ -145,310 +121,3 @@ ynh_maintenance_mode_OFF () { #================================================= # FUTURE OFFICIAL HELPERS #================================================= - -#================================================= -# RUBY HELPER -#================================================= - -ynh_ruby_try_bash_extension() { - if [ -x src/configure ]; then - src/configure && make -C src || { - ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." - } - fi -} - -rbenv_install_dir="/opt/rbenv" -ruby_version_path="$rbenv_install_dir/versions" -# RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. -export RBENV_ROOT="$rbenv_install_dir" -export rbenv_root="$rbenv_install_dir" -# Load the version of Ruby for an app, and set variables. -# -# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. -# This helper will provide alias and variables to use in your scripts. -# -# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby` -# Those alias will use the correct version installed for the app -# For example: use `ynh_gem install` instead of `gem install` -# -# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_ruby` -# And propagate $PATH to sudo with $ynh_ruby_load_path -# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install` -# -# $PATH contains the path of the requested version of Ruby. -# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH -# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version -# in $PATH for an usage into a separate script. -# Exemple: $ynh_ruby_load_path $final_path/script_that_use_gem.sh` -# -# -# Finally, to start a Ruby service with the correct version, 2 solutions -# Either the app is dependent of Ruby or gem, but does not called it directly. -# In such situation, you need to load PATH -# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"` -# `ExecStart=__FINALPATH__/my_app` -# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path -# -# Or Ruby start the app directly, then you don't need to load the PATH variable -# `ExecStart=__YNH_RUBY__ my_app run` -# You will replace __YNH_RUBY__ with $ynh_ruby -# -# -# one other variable is also available -# - $ruby_path: The absolute path to Ruby binaries for the chosen version. -# -# usage: ynh_use_ruby -# -# Requires YunoHost version 2.7.12 or higher. -ynh_use_ruby () { - ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) - - # Get the absolute path of this version of Ruby - ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" - - # Allow alias to be used into bash script - shopt -s expand_aliases - - # Create an alias for the specific version of Ruby and a variable as fallback - ynh_ruby="$ruby_path/ruby" - alias ynh_ruby="$ynh_ruby" - # And gem - ynh_gem="$ruby_path/gem" - alias ynh_gem="$ynh_gem" - - # Load the path of this version of Ruby in $PATH - if [[ :$PATH: != *":$ruby_path"* ]]; then - PATH="$ruby_path:$PATH" - fi - # Create an alias to easily load the PATH - ynh_ruby_load_path="PATH=$PATH" - - # Sets the local application-specific Ruby version - pushd $final_path - $rbenv_install_dir/bin/rbenv local $ruby_version - popd -} - -# Install a specific version of Ruby -# -# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. -# -# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv -# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) -# -# Don't forget to execute ruby-dependent command in a login environment -# (e.g. sudo --login option) -# When not possible (e.g. in systemd service definition), please use direct path -# to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) -# -# usage: ynh_install_ruby --ruby_version=ruby_version -# | arg: -v, --ruby_version= - Version of ruby to install. -# -# Requires YunoHost version 2.7.12 or higher. -ynh_install_ruby () { - # Declare an array to define the options of this helper. - local legacy_args=v - local -A args_array=( [v]=ruby_version= ) - local ruby_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - # Load rbenv path in PATH - local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Move an existing Ruby binary, to avoid to block rbenv - test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - - # Install or update rbenv - rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" - if [ -n "$rbenv" ]; then - ynh_print_info --message="rbenv already seems installed in \`$rbenv'." - pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then - ynh_print_info --message="Trying to update with git..." - git pull -q --tags origin master - ynh_ruby_try_bash_extension - else - ynh_print_info --message="Reinstalling rbenv with git..." - cd .. - ynh_secure_remove --file=$rbenv_install_dir - mkdir -p $rbenv_install_dir - cd $rbenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_ruby_try_bash_extension - rbenv=$rbenv_install_dir/bin/rbenv - fi - popd - else - ynh_print_info --message="Installing rbenv with git..." - mkdir -p $rbenv_install_dir - pushd $rbenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_ruby_try_bash_extension - rbenv=$rbenv_install_dir/bin/rbenv - popd - fi - - ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" - if [ -n "$ruby_build" ]; then - ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." - pushd "${ruby_build%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then - ynh_print_info --message="Trying to update rbenv with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing ruby-build with git..." - mkdir -p "${rbenv_install_dir}/plugins" - git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" - fi - - rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" - if [ -n "$rbenv_alias" ]; then - ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." - pushd "${rbenv_alias%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then - ynh_print_info --message="Trying to update rbenv-aliases with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing rbenv-aliases with git..." - mkdir -p "${rbenv_install_dir}/plugins" - git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" - fi - - rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" - if [ -n "$rbenv_latest" ]; then - ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." - pushd "${rbenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then - ynh_print_info --message="Trying to update xxenv-latest with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing xxenv-latest with git..." - mkdir -p "${rbenv_install_dir}/plugins" - git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" - fi - - # Enable caching - mkdir -p "${rbenv_install_dir}/cache" - - # Create shims directory if needed - mkdir -p "${rbenv_install_dir}/shims" - - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH - - # And replace the old Ruby binary - test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby - - # Install the requested version of Ruby - local final_ruby_version=$(rbenv latest --print $ruby_version) - if ! [ -n "$final_ruby_version" ]; then - final_ruby_version=$ruby_version - fi - ynh_print_info --message="Installing Ruby-$final_ruby_version" - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 - - # Store ruby_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$final_ruby_version - - # Remove app virtualenv - if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` - then - rbenv alias $YNH_APP_INSTANCE_NAME --remove - fi - - # Create app virtualenv - rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version - - # Cleanup Ruby versions - ynh_cleanup_ruby - - # Set environment for Ruby users - echo "#rbenv -export RBENV_ROOT=$rbenv_install_dir -export PATH=\"$rbenv_install_dir/bin:$PATH\" -eval \"\$(rbenv init -)\" -#rbenv" > /etc/profile.d/rbenv.sh - - # Load the environment - eval "$(rbenv init -)" -} - -# Remove the version of Ruby used by the app. -# -# This helper will also cleanup Ruby versions -# -# usage: ynh_remove_ruby -ynh_remove_ruby () { - local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) - - # Load rbenv path in PATH - local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - rbenv alias $YNH_APP_INSTANCE_NAME --remove - - # Remove the line for this app - ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version - - # Cleanup Ruby versions - ynh_cleanup_ruby -} - -# Remove no more needed versions of Ruby used by the app. -# -# This helper will check what Ruby version are no more required, -# and uninstall them -# If no app uses Ruby, rbenv will be also removed. -# -# usage: ynh_cleanup_ruby -ynh_cleanup_ruby () { - - # List required Ruby versions - local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') - local required_ruby_versions="" - for installed_app in $installed_apps - do - local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") - if [[ $installed_app_ruby_version ]] - then - required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" - fi - done - - # Remove no more needed Ruby versions - local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') - for installed_ruby_version in $installed_ruby_versions - do - if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` - then - ynh_print_info --message="Removing of Ruby-$installed_ruby_version" - $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version - fi - done - - # If none Ruby version is required - if [[ ! $required_ruby_versions ]] - then - # Remove rbenv environment configuration - ynh_print_info --message="Removing of rbenv-$rbenv_version" - ynh_secure_remove --file="$rbenv_install_dir" - ynh_secure_remove --file="/etc/profile.d/rbenv.sh" - fi -} diff --git a/scripts/backup b/scripts/backup index c6fe988..4c3d61d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,22 +15,22 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { true } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +#REMOVEME? ynh_print_info --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -41,7 +41,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 887fb53..fab7ed9 100644 --- a/scripts/install +++ b/scripts/install @@ -10,111 +10,38 @@ source _common.sh source ynh_add_swap source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -is_public=$YNH_APP_ARG_IS_PUBLIC -admin=$YNH_APP_ARG_ADMIN -password=$YNH_APP_ARG_PASSWORD -email=$YNH_APP_ARG_EMAIL - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=admin --value=$admin - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -port_web=$(ynh_find_port --port=3000) -ynh_app_setting_set --app=$app --key=port_web --value=$port_web - #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=1 -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." +ynh_script_progression --message="Setting a PostgreSQL database..." -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_app_setting_set --app=$app --key=db_user --value=$db_user -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -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" +ynh_setup_source --dest_dir="$install_dir" -mkdir -p "$final_path/tmp/pids" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +mkdir -p "$install_dir/tmp/pids" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -# Create a dedicated NGINX config ynh_add_nginx_config #================================================= @@ -127,9 +54,9 @@ ynh_script_progression --message="Adding swap if needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 -if [ $total_memory -lt $MEMORY_NEEDED ]; then +if (( MEMORY_NEEDED > total_memory )); then # Need a minimum of 2.5Go of memory - swap_needed=$(($MEMORY_NEEDED - $total_memory)) + swap_needed=$((MEMORY_NEEDED - total_memory)) fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." @@ -140,11 +67,11 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Installing Ruby..." -pushd "$final_path" +pushd "$install_dir" ynh_use_ruby ynh_gem install bundler:1.17.3 --no-document - ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" - ynh_exec_as $app chmod +x script/server + ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" + ynh_exec_as "$app" chmod +x script/server popd #================================================= @@ -152,8 +79,8 @@ popd #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -database_yml="$final_path/config/database.yml" -diaspora_toml="$final_path/config/diaspora.toml" +database_yml="$install_dir/config/database.yml" +diaspora_toml="$install_dir/config/diaspora.toml" ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml" ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml" @@ -177,7 +104,7 @@ ynh_add_systemd_config --service="$app-sidekiq" --template="$app-sidekiq.service #================================================= ynh_script_progression --message="Installing acropolis..." -pushd "$final_path" +pushd "$install_dir" ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path script/configure_bundler ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set path 'vendor/bundle' ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install --full-index @@ -185,7 +112,7 @@ popd ynh_script_progression --message="Preparing the database and create initial admin user..." -pushd "$final_path" +pushd "$install_dir" ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake "admin:create[$admin, $email, $password]" @@ -217,26 +144,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 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="Booted Rails" -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" -fi - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 3f50932..7958ac7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -10,20 +10,6 @@ source _common.sh source ynh_add_swap source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$(ynh_app_setting_get --app=$app --key=db_user) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - #================================================= # STANDARD REMOVE #================================================= @@ -51,38 +37,21 @@ ynh_script_progression --message="Stopping and removing the systemd service..." ynh_remove_systemd_config --service="$app-web" ynh_remove_systemd_config --service="$app-sidekiq" -#================================================= -# REMOVE THE POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Removing the PostgreSQL database.." - -ynh_psql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - - #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 -# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 +#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=1 # Remove metapackage and its dependencies ynh_remove_ruby -ynh_remove_app_dependencies +#REMOVEME? ynh_remove_app_dependencies #================================================= # SPECIFIC REMOVE @@ -100,16 +69,6 @@ ynh_secure_remove --file="/var/log/$app" # Remove swap ynh_del_swap -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index e319c0e..d8abd06 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,64 +15,64 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$(ynh_app_setting_get --app=$app --key=db_user) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$(ynh_app_setting_get --app=$app --key=db_user) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 +#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " +#REMOVEME? test ! -d $install_dir \ + || ynh_die --message="There is already a directory: $install_dir " #================================================= # STANDARD RESTORATION STEPS #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 +#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -mkdir -p "$final_path/tmp/pids" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +mkdir -p "$install_dir/tmp/pids" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= @@ -101,11 +101,11 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." +#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#REMOVEME? ynh_psql_test_if_first_run +#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;" ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" @@ -115,10 +115,10 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= ynh_script_progression --message="Installing Ruby..." -pushd "$final_path" +pushd "$install_dir" ynh_use_ruby ynh_gem install bundler:1.17.3 --no-document - ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" + ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" popd #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index bb9f545..bbee044 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,18 +12,18 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$(ynh_app_setting_get --app=$app --key=db_user) -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -port_web=$(ynh_app_setting_get --app=$app --key=port_web) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$(ynh_app_setting_get --app=$app --key=db_user) +#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#REMOVEME? port_web=$(ynh_app_setting_get --app=$app --key=port_web) #================================================= # CHECK VERSION @@ -35,17 +35,17 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 +#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { ynh_clean_check_starting # Restore it if the upgrade fails - ynh_restore_upgradebackup +#REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS @@ -63,8 +63,8 @@ ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=syst ynh_script_progression --message="Ensuring downward compatibility..." # Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all +#REMOVEME? if ynh_legacy_permissions_exists; then +#REMOVEME? ynh_legacy_permissions_delete_all ynh_app_setting_delete --app=$app --key=is_public fi @@ -72,14 +72,14 @@ fi # If port_web doesn't exist, create it, needed for old install if [[ -z "$port_web" ]]; then port_web=3000 - ynh_app_setting_set --app=$app --key=port_web --value=$port_web +#REMOVEME? ynh_app_setting_set --app=$app --key=port_web --value=$port_web fi # If db_pwd doesn't exist, create it, needed for old install if [[ -z "$db_pwd" ]]; then db_pwd=$(ynh_string_random) - ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd - ynh_psql_test_if_first_run +#REMOVEME? ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd +#REMOVEME? ynh_psql_test_if_first_run sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="$config" fi @@ -91,10 +91,10 @@ ynh_app_setting_delete --app=$app --key=secret_key_base #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -105,19 +105,19 @@ then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$install_dir" fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 +#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= @@ -135,10 +135,10 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Installing Ruby..." -pushd "$final_path" +pushd "$install_dir" ynh_use_ruby ynh_gem install bundler:1.17.3 --no-document - ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" + ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" popd #================================================= @@ -146,8 +146,8 @@ popd #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 -database_yml="$final_path/config/database.yml" -diaspora_toml="$final_path/config/diaspora.toml" +database_yml="$install_dir/config/database.yml" +diaspora_toml="$install_dir/config/diaspora.toml" ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml" ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml" @@ -172,7 +172,7 @@ ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.se #================================================= ynh_script_progression --message="Upgrading acropolis..." -pushd "$final_path" +pushd "$install_dir" ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config deployment 'true' ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config without 'development test' ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) @@ -210,9 +210,9 @@ ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=sys #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/ynh_ruby b/scripts/ynh_ruby new file mode 100644 index 0000000..f780763 --- /dev/null +++ b/scripts/ynh_ruby @@ -0,0 +1,303 @@ + +ynh_ruby_try_bash_extension() { + if [ -x src/configure ]; then + src/configure && make -C src || { + ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." + } + fi +} + +rbenv_install_dir="/opt/rbenv" +ruby_version_path="$rbenv_install_dir/versions" +# RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. +export RBENV_ROOT="$rbenv_install_dir" +export rbenv_root="$rbenv_install_dir" +# Load the version of Ruby for an app, and set variables. +# +# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. +# This helper will provide alias and variables to use in your scripts. +# +# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby` +# Those alias will use the correct version installed for the app +# For example: use `ynh_gem install` instead of `gem install` +# +# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_ruby` +# And propagate $PATH to sudo with $ynh_ruby_load_path +# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install` +# +# $PATH contains the path of the requested version of Ruby. +# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH +# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version +# in $PATH for an usage into a separate script. +# Exemple: $ynh_ruby_load_path $install_dir/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=__INSTALL_DIR__/my_app` +# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path +# +# Or Ruby start the app directly, then you don't need to load the PATH variable +# `ExecStart=__YNH_RUBY__ my_app run` +# You will replace __YNH_RUBY__ with $ynh_ruby +# +# +# one other variable is also available +# - $ruby_path: The absolute path to Ruby binaries for the chosen version. +# +# usage: ynh_use_ruby +# +# Requires YunoHost version 2.7.12 or higher. +ynh_use_ruby () { + ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) + + # Get the absolute path of this version of Ruby + ruby_path="$ruby_version_path/$app/bin" + + # Allow alias to be used into bash script + shopt -s expand_aliases + + # Create an alias for the specific version of Ruby and a variable as fallback + ynh_ruby="$ruby_path/ruby" + alias ynh_ruby="$ynh_ruby" + # And gem + ynh_gem="$ruby_path/gem" + alias ynh_gem="$ynh_gem" + + # Load the path of this version of Ruby in $PATH + if [[ :$PATH: != *":$ruby_path"* ]]; then + PATH="$ruby_path:$PATH" + fi + # Create an alias to easily load the PATH + ynh_ruby_load_path="PATH=$PATH" + + # Sets the local application-specific Ruby version + pushd $install_dir + $rbenv_install_dir/bin/rbenv local $ruby_version + popd +} + +# Install a specific version of Ruby +# +# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. +# +# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv +# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) +# +# Don't forget to execute ruby-dependent command in a login environment +# (e.g. sudo --login option) +# When not possible (e.g. in systemd service definition), please use direct path +# to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) +# +# usage: ynh_install_ruby --ruby_version=ruby_version +# | arg: -v, --ruby_version= - Version of ruby to install. +# +# Requires YunoHost version 2.7.12 or higher. +ynh_install_ruby () { + # Declare an array to define the options of this helper. + local legacy_args=v + local -A args_array=( [v]=ruby_version= ) + local ruby_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing Ruby binary, to avoid to block rbenv + test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv + + # Install or update rbenv + rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" + if [ -n "$rbenv" ]; then + ynh_print_info --message="rbenv already seems installed in \`$rbenv'." + pushd "${rbenv%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then + ynh_print_info --message="Trying to update with git..." + git pull -q --tags origin master + ynh_ruby_try_bash_extension + else + ynh_print_info --message="Reinstalling rbenv with git..." + cd .. + ynh_secure_remove --file=$rbenv_install_dir + mkdir -p $rbenv_install_dir + cd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv + fi + popd + else + ynh_print_info --message="Installing rbenv with git..." + mkdir -p $rbenv_install_dir + pushd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv + popd + fi + + ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" + if [ -n "$ruby_build" ]; then + ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." + pushd "${ruby_build%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then + ynh_print_info --message="Trying to update rbenv with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing ruby-build with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" + fi + + rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + if [ -n "$rbenv_alias" ]; then + ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." + pushd "${rbenv_alias%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then + ynh_print_info --message="Trying to update rbenv-aliases with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing rbenv-aliases with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" + fi + + rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + if [ -n "$rbenv_latest" ]; then + ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." + pushd "${rbenv_latest%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then + ynh_print_info --message="Trying to update xxenv-latest with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing xxenv-latest with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" + fi + + # Enable caching + mkdir -p "${rbenv_install_dir}/cache" + + # Create shims directory if needed + mkdir -p "${rbenv_install_dir}/shims" + + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH + + # And replace the old Ruby binary + test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby + + # Install the requested version of Ruby + local final_ruby_version=$(rbenv latest --print $ruby_version) + if ! [ -n "$final_ruby_version" ]; then + final_ruby_version=$ruby_version + fi + ynh_print_info --message="Installing Ruby-$final_ruby_version" + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 + + # Store ruby_version into the config of this app + ynh_app_setting_set --app=$app --key=ruby_version --value=$final_ruby_version + + # Remove app virtualenv + if `rbenv alias --list | grep --quiet "$app " 1>/dev/null 2>&1` + then + rbenv alias $app --remove + fi + + # Create app virtualenv + rbenv alias $app $final_ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby + + # Set environment for Ruby users + echo "#rbenv +export RBENV_ROOT=$rbenv_install_dir +export PATH=\"$rbenv_install_dir/bin:$PATH\" +eval \"\$(rbenv init -)\" +#rbenv" > /etc/profile.d/rbenv.sh + + # Load the environment + eval "$(rbenv init -)" +} + +# Remove the version of Ruby used by the app. +# +# This helper will also cleanup Ruby versions +# +# usage: ynh_remove_ruby +ynh_remove_ruby () { + local ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + +#REMOVEME? rbenv alias $app --remove + + # Remove the line for this app +#REMOVEME? ynh_app_setting_delete --app=$app --key=ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby +} + +# Remove no more needed versions of Ruby used by the app. +# +# This helper will check what Ruby version are no more required, +# and uninstall them +# If no app uses Ruby, rbenv will be also removed. +# +# usage: ynh_cleanup_ruby +ynh_cleanup_ruby () { + + # List required Ruby versions + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_ruby_versions="" + for installed_app in $installed_apps + do + local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") + if [[ $installed_app_ruby_version ]] + then + required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" + fi + done + + # Remove no more needed Ruby versions + local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') + for installed_ruby_version in $installed_ruby_versions + do + if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` + then + ynh_print_info --message="Removing of Ruby-$installed_ruby_version" + $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version + fi + done + + # If none Ruby version is required + if [[ ! $required_ruby_versions ]] + then + # Remove rbenv environment configuration + ynh_print_info --message="Removing of rbenv-$rbenv_version" + ynh_secure_remove --file="$rbenv_install_dir" + ynh_secure_remove --file="/etc/profile.d/rbenv.sh" + fi +} diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..48ce378 --- /dev/null +++ b/tests.toml @@ -0,0 +1,13 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + exclude = [ + "install.subdir" + ] + + test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c.name = "previous version" + test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c.args.email = "admin@domain.tld" + test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c.args.password = "1Strong-Password" From ee9cec8efe1f8fe8799c2a8f9b7ee395d5032829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 11:34:46 +0100 Subject: [PATCH 02/11] Continue manifestv2 --- manifest.toml | 8 +-- scripts/install | 136 +++++++++++++++++++----------------------------- scripts/remove | 61 ++++++---------------- 3 files changed, 73 insertions(+), 132 deletions(-) diff --git a/manifest.toml b/manifest.toml index a8a137c..98881f0 100644 --- a/manifest.toml +++ b/manifest.toml @@ -7,7 +7,7 @@ name = "Acropolis" description.en = "Dynamic fork of diaspora*'s federated social network" description.fr = "Fourche dynamique du réseau social fédéré de diaspora*" -version = "2022.01.29~ynh1" +version = "2022.01.29~ynh2" maintainers = ["weex"] @@ -17,8 +17,8 @@ website = "https://magicstone.dev" code = "https://github.com/magicstone-dev/acropolis" [integration] -yunohost = ">= 4.3.0" -architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +yunohost = ">=11.2" +architectures = "all" multi_instance = false ldap = false sso = false @@ -64,7 +64,7 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen [resources.apt] packages = [ "g++", - "libjemalloc1|libjemalloc2", + # "libjemalloc1|libjemalloc2", "libjemalloc-dev", "zlib1g-dev", "libreadline-dev", diff --git a/scripts/install b/scripts/install index fab7ed9..f52d03e 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -13,14 +11,30 @@ source /usr/share/yunohost/helpers #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 +ynh_script_progression --message="Installing Ruby..." --weight=1 ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION" +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_script_progression --message="Adding swap if needed..." + +total_memory=$(ynh_get_ram --total) +swap_needed=0 + +if (( MEMORY_NEEDED > total_memory )); then + # Need a minimum of 2.5Go of memory + swap_needed=$((MEMORY_NEEDED - total_memory)) +fi + +ynh_script_progression --message="Adding $swap_needed Mo to swap..." +ynh_add_swap --size=$swap_needed + #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Setting a PostgreSQL database..." +ynh_script_progression --message="Setting the PostgreSQL database..." ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database="$db_name" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name" @@ -33,116 +47,72 @@ ynh_script_progression --message="Setting up source files..." --weight=1 ynh_setup_source --dest_dir="$install_dir" mkdir -p "$install_dir/tmp/pids" -chmod 750 "$install_dir" + chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 - -ynh_add_nginx_config - -#================================================= -# SPECIFIC SETUP -#================================================= -# ADD SWAP IF NEEDED -#================================================= -ynh_script_progression --message="Adding swap if needed..." - -total_memory=$(ynh_get_ram --total) -swap_needed=0 - -if (( MEMORY_NEEDED > total_memory )); then - # Need a minimum of 2.5Go of memory - swap_needed=$((MEMORY_NEEDED - total_memory)) -fi - -ynh_script_progression --message="Adding $swap_needed Mo to swap..." -ynh_add_swap --size=$swap_needed - -#================================================= -# INSTALLING RUBY AND BUNDLER -#================================================= -ynh_script_progression --message="Installing Ruby..." - -pushd "$install_dir" - ynh_use_ruby - ynh_gem install bundler:1.17.3 --no-document - ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" - ynh_exec_as "$app" chmod +x script/server -popd +chown -R "$app:www-data" "$install_dir" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -database_yml="$install_dir/config/database.yml" -diaspora_toml="$install_dir/config/diaspora.toml" +ynh_add_config --template="database.yml.example" --destination="$install_dir/config/database.yml" +ynh_add_config --template="diaspora.toml.example" --destination="$install_dir/config/diaspora.toml" -ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml" -ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml" - -chmod 400 "$database_yml" -chown $app:$app "$database_yml" - -chmod 400 "$diaspora_toml" -chown $app:$app "$diaspora_toml" +chmod 400 "$install_dir/config/database.yml" +chmod 400 "$install_dir/config/diaspora.toml" +chown "$app:$app" "$install_dir/config/database.yml" +chown "$app:$app" "$install_dir/config/diaspora.toml" #================================================= -# SETUP SYSTEMD +# INSTALLING RUBY AND BUNDLER #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 - -ynh_add_systemd_config --service="$app-web" --template="$app-web.service" -ynh_add_systemd_config --service="$app-sidekiq" --template="$app-sidekiq.service" - -#================================================= -# INSTALLING ACROPOLIS -#================================================= -ynh_script_progression --message="Installing acropolis..." +ynh_script_progression --message="Building $app..." pushd "$install_dir" - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path script/configure_bundler - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set path 'vendor/bundle' - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install --full-index + ynh_use_ruby + ynh_gem install bundler:1.17.3 --no-document + ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" + ynh_exec_as "$app" chmod +x script/server +popd + +pushd "$install_dir" + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" script/configure_bundler + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config set path 'vendor/bundle' + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle install --full-index popd ynh_script_progression --message="Preparing the database and create initial admin user..." pushd "$install_dir" - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake "admin:create[$admin, $email, $password]" + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake db:migrate + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:precompile + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake "admin:create[$admin, $email, $password]" popd #================================================= -# GENERIC FINALIZATION +# SYSTEM CONFIGURATION #================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +ynh_add_nginx_config + +ynh_add_systemd_config --service="$app-web" --template="$app-web.service" +yunohost service add "$app-web" --description="$app web service" + +ynh_add_systemd_config --service="$app-sidekiq" --template="$app-sidekiq.service" +yunohost service add "$app-sidekiq" --description="$app sidekiq service" # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add "$app-web" --description="$app web service" -yunohost service add "$app-sidekiq" --description="$app sidekiq service" - #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -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="Booted Rails" +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="Booted Rails" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 7958ac7..e31f498 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -11,64 +9,37 @@ source ynh_add_swap source /usr/share/yunohost/helpers #================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST -#================================================= - -# 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..." --weight=1 - yunohost service remove "$app-web" -fi - -if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null -then - ynh_script_progression --message="Removing $app-sidekiq service integration..." --weight=1 - yunohost service remove "$app-sidekiq" -fi - -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - -ynh_remove_systemd_config --service="$app-web" -ynh_remove_systemd_config --service="$app-sidekiq" - -#================================================= -# REMOVE NGINX CONFIGURATION +# REMOVE SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +# 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 + yunohost service remove "$app-web" +fi +ynh_remove_systemd_config --service="$app-web" + +if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null; then + yunohost service remove "$app-sidekiq" +fi +ynh_remove_systemd_config --service="$app-sidekiq" + ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_ruby -#REMOVEME? ynh_remove_app_dependencies - -#================================================= -# SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." --weight=1 -# Remove a directory securely ynh_secure_remove --file="/etc/$app" -# Remove the log files ynh_secure_remove --file="/var/log/$app" -# Remove swap +ynh_script_progression --message="Removing Swap..." --weight=1 ynh_del_swap +ynh_script_progression --message="Uninstalling Ruby..." --weight=1 +ynh_remove_ruby + #================================================= # END OF SCRIPT #================================================= From cc889885f06997e0b7daa47747fbf1222c3915d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 11:35:21 +0100 Subject: [PATCH 03/11] Fix missing install arg --- tests.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests.toml b/tests.toml index 48ce378..e520486 100644 --- a/tests.toml +++ b/tests.toml @@ -4,6 +4,8 @@ test_format = 1.0 [default] + args.email = "admin@domain.tld" + exclude = [ "install.subdir" ] From 9ebf108e4e4c12a5d3547720567da081e8bd3036 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Fri, 29 Mar 2024 10:35:44 +0000 Subject: [PATCH 04/11] Auto-update READMEs --- README.md | 2 +- README_fr.md | 2 +- README_gl.md | 2 +- README_it.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 72b53e5..8afa006 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ It shall NOT be edited by hand. Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that. -**Shipped version:** 2022.01.29~ynh1 +**Shipped version:** 2022.01.29~ynh2 ## Disclaimers / important information Acropolis is beta software, and under active development. Use at your own risk! diff --git a/README_fr.md b/README_fr.md index 39def79..f709655 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,7 +19,7 @@ Il NE doit PAS être modifié à la main. Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that. -**Version incluse :** 2022.01.29~ynh1 +**Version incluse :** 2022.01.29~ynh2 ## Avertissements / informations importantes Acropolis is beta software, and under active development. Use at your own risk! diff --git a/README_gl.md b/README_gl.md index 233a3b4..f01f85d 100644 --- a/README_gl.md +++ b/README_gl.md @@ -19,7 +19,7 @@ NON debe editarse manualmente. Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that. -**Versión proporcionada:** 2022.01.29~ynh1 +**Versión proporcionada:** 2022.01.29~ynh2 ## Avisos / información importante Acropolis is beta software, and under active development. Use at your own risk! diff --git a/README_it.md b/README_it.md index e3051d0..004f326 100644 --- a/README_it.md +++ b/README_it.md @@ -19,7 +19,7 @@ NON DEVE essere modificato manualmente. Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that. -**Versione pubblicata:** 2022.01.29~ynh1 +**Versione pubblicata:** 2022.01.29~ynh2 ## Attenzione/informazioni importanti Acropolis is beta software, and under active development. Use at your own risk! From c753e6cd2819dfa047aad83007447872a1690412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 11:46:21 +0100 Subject: [PATCH 05/11] Continue manifestv2 --- scripts/backup | 39 +-------- scripts/install | 2 - scripts/restore | 139 ++++++++----------------------- scripts/upgrade | 211 +++++++++++------------------------------------- 4 files changed, 85 insertions(+), 306 deletions(-) diff --git a/scripts/backup b/scripts/backup index 4c3d61d..7a474c5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -11,27 +9,6 @@ source ../settings/scripts/_common.sh source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_print_info --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -44,26 +21,16 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# BACKUP THE SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup --src_path="/etc/logrotate.d/$app" - -#================================================= -# BACKUP SYSTEMD -#================================================= - ynh_backup --src_path="/etc/systemd/system/$app-web.service" ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service" +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP THE MYSQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index f52d03e..00bd016 100644 --- a/scripts/install +++ b/scripts/install @@ -74,9 +74,7 @@ pushd "$install_dir" ynh_gem install bundler:1.17.3 --no-document ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" ynh_exec_as "$app" chmod +x script/server -popd -pushd "$install_dir" ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" script/configure_bundler ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config set path 'vendor/bundle' ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle install --full-index diff --git a/scripts/restore b/scripts/restore index d8abd06..0aab10f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -12,68 +10,11 @@ source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling Ruby..." --weight=4 -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$(ynh_app_setting_get --app=$app --key=db_user) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -#REMOVEME? test ! -d $install_dir \ - || ynh_die --message="There is already a directory: $install_dir " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 - -ynh_restore_file --origin_path="$install_dir" - -mkdir -p "$install_dir/tmp/pids" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=1 - -# Define and install dependencies -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION +ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION" #================================================= # ADD SWAP IF NEEDED @@ -83,82 +24,68 @@ ynh_script_progression --message="Adding swap if needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 -if [ $total_memory -lt $MEMORY_NEEDED ]; then - # Need a minimum of 8Go of memory - swap_needed=$(($MEMORY_NEEDED - $total_memory)) +if (( MEMORY_NEEDED > total_memory )); then + # Need a minimum of 2.5Go of memory + swap_needed=$((MEMORY_NEEDED - total_memory)) fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." ynh_add_swap --size=$swap_needed #================================================= -# RESTORE THE NGINX CONFIGURATION +# RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="$install_dir" + +mkdir -p "$install_dir/tmp/pids" + +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." - -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -#REMOVEME? ynh_psql_test_if_first_run -#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;" -ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 +ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql #================================================= # INSTALLING RUBY AND BUNDLER #================================================= -ynh_script_progression --message="Installing Ruby..." +ynh_script_progression --message="Rebuilding $app..." pushd "$install_dir" - ynh_use_ruby - ynh_gem install bundler:1.17.3 --no-document - ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" + ynh_use_ruby + ynh_gem install bundler:1.17.3 --no-document + ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" popd #================================================= -# RESTORE SYSTEMD +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service" -ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service" -systemctl enable "$app-web" "$app-sidekiq" --quiet +systemctl enable "$app-web" --quiet +yunohost service add "$app-web" --description="$app web service" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 +ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service" +systemctl enable "$app-sidekiq" --quiet +yunohost service add "$app-sidekiq" --description="$app sidekiq service" ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -yunohost service add "$app-web" --description="$app web service" -yunohost service add "$app-sidekiq" --description="$app sidekiq service" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 - -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="Booted Rails" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." +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="Booted Rails" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index bbee044..4172c4a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,218 +1,105 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh -source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$(ynh_app_setting_get --app=$app --key=db_user) -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -#REMOVEME? port_web=$(ynh_app_setting_get --app=$app --key=port_web) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped" -ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped" +ynh_systemd_action --service_name="${app}-web" --action="stop" --log_path=systemd +ynh_systemd_action --service_name="${app}-sidekiq" --action="stop" --log_path=systemd #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Cleaning legacy permissions -#REMOVEME? if ynh_legacy_permissions_exists; then -#REMOVEME? ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - -# If port_web doesn't exist, create it, needed for old install -if [[ -z "$port_web" ]]; then - port_web=3000 -#REMOVEME? ynh_app_setting_set --app=$app --key=port_web --value=$port_web -fi - -# If db_pwd doesn't exist, create it, needed for old install -if [[ -z "$db_pwd" ]]; then - db_pwd=$(ynh_string_random) -#REMOVEME? ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd -#REMOVEME? ynh_psql_test_if_first_run - sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres - ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="$config" -fi - ynh_remove_extra_repo -ynh_app_setting_delete --app=$app --key=redis_namespace -ynh_app_setting_delete --app=$app --key=secret_key_base +ynh_app_setting_delete --app="$app" --key=redis_namespace +ynh_app_setting_delete --app="$app" --key=secret_key_base #================================================= -# CREATE DEDICATED USER +# INSTALL DEPENDENCIES #================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_script_progression --message="Updating Ruby..." --weight=1 + +ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION" + -# Create a dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" -fi - -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# INSTALLING RUBY AND BUNDLER -#================================================= -ynh_script_progression --message="Installing Ruby..." - -pushd "$install_dir" - ynh_use_ruby - ynh_gem install bundler:1.17.3 --no-document - ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" -popd +chown -R "$app:www-data" "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression --message="Updating $app's configuration files..." --weight=1 -database_yml="$install_dir/config/database.yml" -diaspora_toml="$install_dir/config/diaspora.toml" +ynh_add_config --template="database.yml.example" --destination="$install_dir/config/database.yml" +ynh_add_config --template="diaspora.toml.example" --destination="$install_dir/config/diaspora.toml" -ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml" -ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml" - -chmod 400 "$database_yml" -chown $app:$app "$database_yml" - -chmod 400 "$diaspora_toml" -chown $app:$app "$diaspora_toml" +chmod 400 "$install_dir/config/database.yml" +chmod 400 "$install_dir/config/diaspora.toml" +chown "$app:$app" "$install_dir/config/database.yml" +chown "$app:$app" "$install_dir/config/diaspora.toml" #================================================= -# SETUP SYSTEMD +# INSTALLING RUBY AND BUNDLER #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 - -# Create a dedicated systemd config -ynh_add_systemd_config --service="$app-web" --template="acropolis-web.service" -ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.service" - -#================================================= -# UPGRADE ACROPOLIS -#================================================= -ynh_script_progression --message="Upgrading acropolis..." +ynh_script_progression --message="Building $app..." pushd "$install_dir" - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config deployment 'true' - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config without 'development test' - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:clean - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile - ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate + ynh_use_ruby + ynh_gem install bundler:1.17.3 --no-document + ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc" + + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config deployment 'true' + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config without 'development test' + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle install -j$(getconf _NPROCESSORS_ONLN) + + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:clean + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:precompile + ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake db:migrate popd #================================================= -# GENERIC FINALIZATION +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config --service="$app-web" --template="acropolis-web.service" +yunohost service add "$app-web" --description="$app web service" + +ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.service" +yunohost service add "$app-sidekiq" --description="$app sidekiq service" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add "$app-web" --description="$app web service" -yunohost service add "$app-sidekiq" --description="$app sidekiq service" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 -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="Booted Rails" - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload +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="Booted Rails" #================================================= # END OF SCRIPT From 885b9a9490c3af992b7d6d9299d1969595844f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 11:57:06 +0100 Subject: [PATCH 06/11] add nodejs dep --- manifest.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.toml b/manifest.toml index 98881f0..63ca830 100644 --- a/manifest.toml +++ b/manifest.toml @@ -86,6 +86,7 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen "jpegoptim", "gifsicle", "brotli", + "nodejs", "cmake", "pkg-config" ] From 6507031ef92ce8acfd96c82fdfceba55584df213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 11:59:51 +0100 Subject: [PATCH 07/11] mv disclaimer pre_install --- doc/{DISCLAIMER.md => PRE_INSTALL.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/{DISCLAIMER.md => PRE_INSTALL.md} (100%) diff --git a/doc/DISCLAIMER.md b/doc/PRE_INSTALL.md similarity index 100% rename from doc/DISCLAIMER.md rename to doc/PRE_INSTALL.md From f12070a083eccc9274782c5e131ee9451f6befe4 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Fri, 29 Mar 2024 10:59:56 +0000 Subject: [PATCH 08/11] Auto-update READMEs --- README.md | 11 ----------- README_fr.md | 11 ----------- README_gl.md | 11 ----------- README_it.md | 11 ----------- 4 files changed, 44 deletions(-) diff --git a/README.md b/README.md index 8afa006..124c4f6 100644 --- a/README.md +++ b/README.md @@ -20,17 +20,6 @@ Acropolis was forked from diaspora* in August 2021. The idea for the fork is to **Shipped version:** 2022.01.29~ynh2 -## Disclaimers / important information - -Acropolis is beta software, and under active development. Use at your own risk! - -* This app require a dedicated domain or subdomain. -* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin. -* Configuration of the instance requires editing one or more config files which must also be done manually. -* Single sign-on doesn't work. - -You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface. - ## Documentation and resources - Official app website: diff --git a/README_fr.md b/README_fr.md index f709655..d7dc9d1 100644 --- a/README_fr.md +++ b/README_fr.md @@ -20,17 +20,6 @@ Acropolis was forked from diaspora* in August 2021. The idea for the fork is to **Version incluse :** 2022.01.29~ynh2 -## Avertissements / informations importantes - -Acropolis is beta software, and under active development. Use at your own risk! - -* This app require a dedicated domain or subdomain. -* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin. -* Configuration of the instance requires editing one or more config files which must also be done manually. -* Single sign-on doesn't work. - -You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface. - ## Documentations et ressources - Site officiel de l’app : diff --git a/README_gl.md b/README_gl.md index f01f85d..8d70c24 100644 --- a/README_gl.md +++ b/README_gl.md @@ -20,17 +20,6 @@ Acropolis was forked from diaspora* in August 2021. The idea for the fork is to **Versión proporcionada:** 2022.01.29~ynh2 -## Avisos / información importante - -Acropolis is beta software, and under active development. Use at your own risk! - -* This app require a dedicated domain or subdomain. -* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin. -* Configuration of the instance requires editing one or more config files which must also be done manually. -* Single sign-on doesn't work. - -You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface. - ## Documentación e recursos - Web oficial da app: diff --git a/README_it.md b/README_it.md index 004f326..df0d39c 100644 --- a/README_it.md +++ b/README_it.md @@ -20,17 +20,6 @@ Acropolis was forked from diaspora* in August 2021. The idea for the fork is to **Versione pubblicata:** 2022.01.29~ynh2 -## Attenzione/informazioni importanti - -Acropolis is beta software, and under active development. Use at your own risk! - -* This app require a dedicated domain or subdomain. -* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin. -* Configuration of the instance requires editing one or more config files which must also be done manually. -* Single sign-on doesn't work. - -You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface. - ## Documentazione e risorse - Sito web ufficiale dell’app: From 07a260c3bca316f42e24570820819546ec57a314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 12:02:21 +0100 Subject: [PATCH 09/11] Add autoupdate strategy --- manifest.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manifest.toml b/manifest.toml index 63ca830..080183f 100644 --- a/manifest.toml +++ b/manifest.toml @@ -51,6 +51,8 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen url = "https://github.com/magicstone-dev/acropolis/archive/f586f64b4cee0b2a50f45b5cf6de4e1fd749def8.tar.gz" sha256 = "716d9c5e1e8e7d2694dbe6d2c1b5e48e5a5537a29ec8a8d0a722e6750fffae56" + autoupdate.strategy = "latest_github_commit" + [resources.system_user] [resources.install_dir] From 2456519cbe2e719633e1c021d67c9f37bae387e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 13:04:55 +0100 Subject: [PATCH 10/11] Fix sourcing of helpers --- scripts/_common.sh | 2 -- scripts/backup | 1 + scripts/install | 1 + scripts/remove | 1 + scripts/restore | 1 + scripts/upgrade | 3 +++ 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 199ab3f..5f5307a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,8 +8,6 @@ RUBY_VERSION="2.7.1" MEMORY_NEEDED="2560" -source ynh_ruby - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 7a474c5..22f3a4c 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_ruby source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers diff --git a/scripts/install b/scripts/install index 00bd016..22ab8e3 100644 --- a/scripts/install +++ b/scripts/install @@ -5,6 +5,7 @@ #================================================= source _common.sh +source ynh_ruby source ynh_add_swap source /usr/share/yunohost/helpers diff --git a/scripts/remove b/scripts/remove index e31f498..4094ddc 100644 --- a/scripts/remove +++ b/scripts/remove @@ -5,6 +5,7 @@ #================================================= source _common.sh +source ynh_ruby source ynh_add_swap source /usr/share/yunohost/helpers diff --git a/scripts/restore b/scripts/restore index 0aab10f..2711d38 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_ruby source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers diff --git a/scripts/upgrade b/scripts/upgrade index 4172c4a..2e70928 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -5,6 +5,9 @@ #================================================= source _common.sh +source ynh_ruby +source ynh_add_swap +source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE From 573f6dc737c38e7943e25d6967f3c2fbc3586067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 13:10:13 +0100 Subject: [PATCH 11/11] Fix test_ugprade_from --- tests.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests.toml b/tests.toml index e520486..958120f 100644 --- a/tests.toml +++ b/tests.toml @@ -10,6 +10,10 @@ test_format = 1.0 "install.subdir" ] - test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c.name = "previous version" - test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c.args.email = "admin@domain.tld" - test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c.args.password = "1Strong-Password" + [default.test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c] + name = "previous version" + + args.admin = "package_checker" + args.email = "admin@domain.tld" + args.password = "1Strong-Password" + args.domain = "domain.tld"