From f0e342438b6218cd68690cc0500466ee6608bea9 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Mon, 22 Nov 2021 23:15:00 +0100 Subject: [PATCH] 4.3 --- check_process | 6 +- conf/app.src | 6 +- conf/nginx.conf | 5 - issue_template.md | 55 ----- manifest.json | 14 +- pull_request_template.md | 16 -- scripts/_common.sh | 400 +++++++++++++++++++++++++++++++++++- scripts/install | 11 +- scripts/remove | 2 - scripts/restore | 15 +- scripts/upgrade | 10 +- scripts/ynh_add_swap | 93 --------- scripts/ynh_install_ruby__2 | 305 --------------------------- 13 files changed, 424 insertions(+), 514 deletions(-) delete mode 100644 issue_template.md delete mode 100644 pull_request_template.md delete mode 100644 scripts/ynh_add_swap delete mode 100644 scripts/ynh_install_ruby__2 diff --git a/check_process b/check_process index 9c0e57b..8f05788 100644 --- a/check_process +++ b/check_process @@ -1,9 +1,9 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - admin="john" (USER) + domain="domain.tld" + admin="john" language="fr_FR" - is_public=1 (PUBLIC|public=1|private=0) + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/conf/app.src b/conf/app.src index 6320061..d80b5cd 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,7 +1,7 @@ -SOURCE_URL=https://github.com/glitch-soc/mastodon/archive/2024aef0f9b52297d814811f5825678a563f78ff.tar.gz -SOURCE_SUM=d22e21d0175837e6969cdf6b2658784a288cc841cbfda18fb43de5f90d783586 +SOURCE_URL=https://github.com/glitch-soc/mastodon/archive/3ba7c85ec9bd5dcf75b30b00ed634b3b31a029af.tar.gz +SOURCE_SUM=715e847b49b4e752a9a9146cba32c6501e4f4e32f284461adfcad3df0c004cc2 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=2024aef0f9b52297d814811f5825678a563f78ff.tar.gz +SOURCE_FILENAME=mastodon.tar.gz SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index 866fcc7..19c2c01 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -6,11 +6,6 @@ root __FINALPATH__/live/public; location / { - # Force usage of https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - proxy_set_header Accept-Encoding ""; try_files $uri @proxy; diff --git a/issue_template.md b/issue_template.md deleted file mode 100644 index f7c22d8..0000000 --- a/issue_template.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -name: Bug report -about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. - ---- - -**How to post a meaningful bug report** -1. *Read this whole template first.* -2. *Determine if you are on the right place:* - - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* - - *Otherwise, the issue may be due to Glitch-Soc itself. Refer to its documentation or repository for help.* - - *When in doubt, post here and we will figure it out together.* -3. *Delete the italic comments as you write over them below, and remove this guide.* ---- - -### Describe the bug - -*A clear and concise description of what the bug is.* - -### Context - -- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* -- YunoHost version: x.x.x -- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* -- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes* - - If yes, please explain: -- Using, or trying to install package version/branch: -- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* - -### Steps to reproduce - -- *If you performed a command from the CLI, the command itself is enough. For example:* - ```sh - sudo yunohost app install glitchsoc - ``` -- *If you used the webadmin, please perform the equivalent command from the CLI first.* -- *If the error occurs in your browser, explain what you did:* - 1. *Go to '...'* - 2. *Click on '...'* - 3. *Scroll down to '...'* - 4. *See error* - -### Expected behavior - -*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* - -### Logs - -*When an operation fails, YunoHost provides a simple way to share the logs.* -- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* -- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* - -*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* - -*If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index c8336ee..b5201df 100644 --- a/manifest.json +++ b/manifest.json @@ -3,10 +3,10 @@ "id": "glitchsoc", "packaging_format": 1, "description": { - "en": "A libre and federated social network, fork of Mastodon.", - "fr": "Un réseau social libre et fédéré, scission de Mastodon." + "en": "Libre and federated social network, fork of Mastodon", + "fr": "Réseau social libre et fédéré, scission de Mastodon" }, - "version": "2021-05-22~ynh2", + "version": "2021.05.22~ynh2", "url": "https://github.com/glitch-soc/mastodon", "upstream": { "license": "free", @@ -18,7 +18,7 @@ "name": "Tagada" }, "requirements": { - "yunohost": ">= 4.2.0" + "yunohost": ">= 4.3.0" }, "multi_instance": true, "services": [ @@ -28,13 +28,11 @@ "install": [ { "name": "domain", - "type": "domain", - "example": "example.com" + "type": "domain" }, { "name": "admin", - "type": "user", - "example": "johndoe" + "type": "user" }, { "name": "is_public", diff --git a/pull_request_template.md b/pull_request_template.md deleted file mode 100644 index 6c28fc5..0000000 --- a/pull_request_template.md +++ /dev/null @@ -1,16 +0,0 @@ -## Problem -- *Description of why you made this PR* - -## Solution -- *And how do you fix that problem* - -## PR Status -- [ ] Code finished. -- [ ] Tested with Package_check. -- [ ] Fix or enhancement tested. -- [ ] Upgrade from last version tested. -- [ ] Can be reviewed and tested. - -## Package_check results ---- -* An automatic package_check will be launch at https://ci-apps-dev.yunohost.org/, when you add a specific comment to your Pull Request: "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!"* diff --git a/scripts/_common.sh b/scripts/_common.sh index b6f4796..181a153 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,7 +11,7 @@ MEMORY_NEEDED="2560" RUBY_VERSION="2.7.2" -NODEJS_VERSION="12" +NODEJS_VERSION="16" #================================================= # PERSONAL HELPERS @@ -21,6 +21,404 @@ NODEJS_VERSION="12" # EXPERIMENTAL HELPERS #================================================= +# Add swap +# +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local swap_max_size=$(( $size * 1024 )) + + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) + + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] + then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" + return + fi + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] + then + # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case + if ! fallocate -l ${swap_size}K /swap_$app + then + dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} + fi + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi +} + +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap_$app ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_a_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +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 3.2.2 or higher. +ynh_use_ruby () { + ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) + + # Get the absolute path of this version of Ruby + ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" + + # Allow alias to be used into bash script + shopt -s expand_aliases + + # Create an alias for the specific version of Ruby and a variable as fallback + ynh_ruby="$ruby_path/ruby" + alias ynh_ruby="$ynh_ruby" + # And gem + ynh_gem="$ruby_path/gem" + alias ynh_gem="$ynh_gem" + + # Load the path of this version of Ruby in $PATH + if [[ :$PATH: != *":$ruby_path"* ]]; then + PATH="$ruby_path:$PATH" + fi + # Create an alias to easily load the PATH + ynh_ruby_load_path="PATH=$PATH" + + # Sets the local application-specific Ruby version + pushd $final_path + $rbenv_install_dir/bin/rbenv local $ruby_version + popd +} + +# Install a specific version of Ruby +# +# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. +# +# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv +# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) +# +# Don't forget to execute ruby-dependent command in a login environment +# (e.g. sudo --login option) +# When not possible (e.g. in systemd service definition), please use direct path +# to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) +# +# usage: ynh_install_ruby --ruby_version=ruby_version +# | arg: -v, --ruby_version= - Version of ruby to install. +# +# Requires YunoHost version 3.2.2 or higher. +ynh_install_ruby () { + # Declare an array to define the options of this helper. + local legacy_args=v + local -A args_array=( [v]=ruby_version= ) + local ruby_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing Ruby binary, to avoid to block rbenv + test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv + + # Install or update rbenv + rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" + if [ -n "$rbenv" ]; then + ynh_print_info --message="rbenv already seems installed in \`$rbenv'." + pushd "${rbenv%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then + ynh_print_info --message="Trying to update with git..." + git pull -q --tags origin master + ynh_ruby_try_bash_extension + else + ynh_print_info --message="Reinstalling rbenv with git..." + cd .. + ynh_secure_remove --file=$rbenv_install_dir + mkdir -p $rbenv_install_dir + cd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv + fi + popd + else + ynh_print_info --message="Installing rbenv with git..." + mkdir -p $rbenv_install_dir + pushd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv + popd + fi + + ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" + if [ -n "$ruby_build" ]; then + ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." + pushd "${ruby_build%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then + ynh_print_info --message="Trying to update rbenv with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing ruby-build with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" + fi + + rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + if [ -n "$rbenv_alias" ]; then + ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." + pushd "${rbenv_alias%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then + ynh_print_info --message="Trying to update rbenv-aliases with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing rbenv-aliases with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" + fi + + rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + if [ -n "$rbenv_latest" ]; then + ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." + pushd "${rbenv_latest%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then + ynh_print_info --message="Trying to update xxenv-latest with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing xxenv-latest with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" + fi + + # Enable caching + mkdir -p "${rbenv_install_dir}/cache" + + # Create shims directory if needed + mkdir -p "${rbenv_install_dir}/shims" + + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH + + # And replace the old Ruby binary + test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby + + # Install the requested version of Ruby + local final_ruby_version=$(rbenv latest --print $ruby_version) + if ! [ -n "$final_ruby_version" ]; then + final_ruby_version=$ruby_version + fi + ynh_print_info --message="Installing Ruby-$final_ruby_version" + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 + + # Store ruby_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$final_ruby_version + + # Remove app virtualenv + if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` + then + rbenv alias $YNH_APP_INSTANCE_NAME --remove + fi + + # Create app virtualenv + rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby + + # Set environment for Ruby users + echo "#rbenv +export RBENV_ROOT=$rbenv_install_dir +export PATH=\"$rbenv_install_dir/bin:$PATH\" +eval \"\$(rbenv init -)\" +#rbenv" > /etc/profile.d/rbenv.sh + + # Load the environment + eval "$(rbenv init -)" +} + +# Remove the version of Ruby used by the app. +# +# This helper will also cleanup Ruby versions +# +# usage: ynh_remove_ruby +ynh_remove_ruby () { + local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + rbenv alias $YNH_APP_INSTANCE_NAME --remove + + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby +} + +# Remove no more needed versions of Ruby used by the app. +# +# This helper will check what Ruby version are no more required, +# and uninstall them +# If no app uses Ruby, rbenv will be also removed. +# +# usage: ynh_cleanup_ruby +ynh_cleanup_ruby () { + + # List required Ruby versions + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_ruby_versions="" + for installed_app in $installed_apps + do + local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") + if [[ $installed_app_ruby_version ]] + then + required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" + fi + done + + # Remove no more needed Ruby versions + local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') + for installed_ruby_version in $installed_ruby_versions + do + if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` + then + ynh_print_info --message="Removing of Ruby-$installed_ruby_version" + $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version + fi + done + + # If none Ruby version is required + if [[ ! $required_ruby_versions ]] + then + # Remove rbenv environment configuration + ynh_print_info --message="Removing of rbenv-$rbenv_version" + ynh_secure_remove --file="$rbenv_install_dir" + ynh_secure_remove --file="/etc/profile.d/rbenv.sh" + fi +} + + diff --git a/scripts/install b/scripts/install index 412b0f6..d7d2dd3 100644 --- a/scripts/install +++ b/scripts/install @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_install_ruby__2 -source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -30,7 +28,6 @@ path_url="/" admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE - admin_mail=$(ynh_user_get_info $admin 'mail') app=$YNH_APP_INSTANCE_NAME @@ -75,10 +72,10 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream #================================================= ynh_script_progression --message="Installing dependencies..." -ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -ynh_install_ruby --ruby_version=$RUBY_VERSION +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # CREATE DEDICATED USER diff --git a/scripts/remove b/scripts/remove index 42b0109..3b279d4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_install_ruby__2 -source ynh_add_swap source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/restore b/scripts/restore index 7a3808b..c867831 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,8 +8,6 @@ # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_install_ruby__2 -source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -41,10 +39,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= ynh_script_progression --message="Validating restoration parameters..." -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -104,10 +99,10 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= ynh_script_progression --message="Reinstalling dependencies..." -ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -ynh_install_ruby --ruby_version=$RUBY_VERSION +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # INSTALLING RUBY AND BUNDLER diff --git a/scripts/upgrade b/scripts/upgrade index 27d29a7..e7e660c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_install_ruby__2 -source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -202,10 +200,10 @@ ynh_add_nginx_config 'port_web port_stream' #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -ynh_install_ruby --ruby_version=$RUBY_VERSION +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # SPECIFIC UPGRADE diff --git a/scripts/ynh_add_swap b/scripts/ynh_add_swap deleted file mode 100644 index d7ec44b..0000000 --- a/scripts/ynh_add_swap +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -# Add swap -# -# usage: ynh_add_swap --size=SWAP in Mb -# | arg: -s, --size= - Amount of SWAP to add in Mb. -ynh_add_swap () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=size= ) - local size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local swap_max_size=$(( $size * 1024 )) - - local free_space=$(df --output=avail / | sed 1d) - # Because we don't want to fill the disk with a swap file, divide by 2 the available space. - local usable_space=$(( $free_space / 2 )) - - SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} - - # Swap on SD card only if it's is specified - if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] - then - ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" - return - fi - - # Compare the available space with the size of the swap. - # And set a acceptable size from the request - if [ $usable_space -ge $swap_max_size ] - then - local swap_size=$swap_max_size - elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] - then - local swap_size=$(( $swap_max_size / 2 )) - elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] - then - local swap_size=$(( $swap_max_size / 3 )) - elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] - then - local swap_size=$(( $swap_max_size / 4 )) - else - echo "Not enough space left for a swap file" >&2 - local swap_size=0 - fi - - # If there's enough space for a swap, and no existing swap here - if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] - then - # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case - if ! fallocate -l ${swap_size}K /swap_$app - then - dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} - fi - chmod 0600 /swap_$app - # Create the swap - mkswap /swap_$app - # And activate it - swapon /swap_$app - # Then add an entry in fstab to load this swap at each boot. - echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab - fi -} - -ynh_del_swap () { - # If there a swap at this place - if [ -e /swap_$app ] - then - # Clean the fstab - sed -i "/#Swap added by $app/d" /etc/fstab - # Desactive the swap file - swapoff /swap_$app - # And remove it - rm /swap_$app - fi -} - -# Check if the device of the main mountpoint "/" is an SD card -# -# [internal] -# -# return 0 if it's an SD card, else 1 -ynh_is_main_device_a_sd_card () { - local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) - - if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] - then - return 0 - else - return 1 - fi -} diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 deleted file mode 100644 index b12ab74..0000000 --- a/scripts/ynh_install_ruby__2 +++ /dev/null @@ -1,305 +0,0 @@ -#!/bin/bash - -ynh_ruby_try_bash_extension() { - if [ -x src/configure ]; then - src/configure && make -C src || { - ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." - } - fi -} - -rbenv_install_dir="/opt/rbenv" -ruby_version_path="$rbenv_install_dir/versions" -# RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. -export RBENV_ROOT="$rbenv_install_dir" -export rbenv_root="$rbenv_install_dir" - -# Load the version of Ruby for an app, and set variables. -# -# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. -# This helper will provide alias and variables to use in your scripts. -# -# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby` -# Those alias will use the correct version installed for the app -# For example: use `ynh_gem install` instead of `gem install` -# -# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_ruby` -# And propagate $PATH to sudo with $ynh_ruby_load_path -# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install` -# -# $PATH contains the path of the requested version of Ruby. -# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH -# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version -# in $PATH for an usage into a separate script. -# Exemple: $ynh_ruby_load_path $final_path/script_that_use_gem.sh` -# -# -# Finally, to start a Ruby service with the correct version, 2 solutions -# Either the app is dependent of Ruby or gem, but does not called it directly. -# In such situation, you need to load PATH -# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"` -# `ExecStart=__FINALPATH__/my_app` -# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path -# -# Or Ruby start the app directly, then you don't need to load the PATH variable -# `ExecStart=__YNH_RUBY__ my_app run` -# You will replace __YNH_RUBY__ with $ynh_ruby -# -# -# one other variable is also available -# - $ruby_path: The absolute path to Ruby binaries for the chosen version. -# -# usage: ynh_use_ruby -# -# Requires YunoHost version 3.2.2 or higher. -ynh_use_ruby () { - ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) - - # Get the absolute path of this version of Ruby - ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" - - # Allow alias to be used into bash script - shopt -s expand_aliases - - # Create an alias for the specific version of Ruby and a variable as fallback - ynh_ruby="$ruby_path/ruby" - alias ynh_ruby="$ynh_ruby" - # And gem - ynh_gem="$ruby_path/gem" - alias ynh_gem="$ynh_gem" - - # Load the path of this version of Ruby in $PATH - if [[ :$PATH: != *":$ruby_path"* ]]; then - PATH="$ruby_path:$PATH" - fi - # Create an alias to easily load the PATH - ynh_ruby_load_path="PATH=$PATH" - - # Sets the local application-specific Ruby version - pushd $final_path - $rbenv_install_dir/bin/rbenv local $ruby_version - popd -} - -# Install a specific version of Ruby -# -# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. -# -# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv -# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) -# -# Don't forget to execute ruby-dependent command in a login environment -# (e.g. sudo --login option) -# When not possible (e.g. in systemd service definition), please use direct path -# to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) -# -# usage: ynh_install_ruby --ruby_version=ruby_version -# | arg: -v, --ruby_version= - Version of ruby to install. -# -# Requires YunoHost version 3.2.2 or higher. -ynh_install_ruby () { - # Declare an array to define the options of this helper. - local legacy_args=v - local -A args_array=( [v]=ruby_version= ) - local ruby_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - # Load rbenv path in PATH - local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Move an existing Ruby binary, to avoid to block rbenv - test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - - # Install or update rbenv - rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" - if [ -n "$rbenv" ]; then - ynh_print_info --message="rbenv already seems installed in \`$rbenv'." - pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then - ynh_print_info --message="Trying to update with git..." - git pull -q --tags origin master - ynh_ruby_try_bash_extension - else - ynh_print_info --message="Reinstalling rbenv with git..." - cd .. - ynh_secure_remove --file=$rbenv_install_dir - mkdir -p $rbenv_install_dir - cd $rbenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_ruby_try_bash_extension - rbenv=$rbenv_install_dir/bin/rbenv - fi - popd - else - ynh_print_info --message="Installing rbenv with git..." - mkdir -p $rbenv_install_dir - pushd $rbenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_ruby_try_bash_extension - rbenv=$rbenv_install_dir/bin/rbenv - popd - fi - - ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" - if [ -n "$ruby_build" ]; then - ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." - pushd "${ruby_build%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then - ynh_print_info --message="Trying to update rbenv with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing ruby-build with git..." - mkdir -p "${rbenv_install_dir}/plugins" - git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" - fi - - rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" - if [ -n "$rbenv_alias" ]; then - ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." - pushd "${rbenv_alias%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then - ynh_print_info --message="Trying to update rbenv-aliases with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing rbenv-aliases with git..." - mkdir -p "${rbenv_install_dir}/plugins" - git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" - fi - - rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" - if [ -n "$rbenv_latest" ]; then - ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." - pushd "${rbenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then - ynh_print_info --message="Trying to update xxenv-latest with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing xxenv-latest with git..." - mkdir -p "${rbenv_install_dir}/plugins" - git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" - fi - - # Enable caching - mkdir -p "${rbenv_install_dir}/cache" - - # Create shims directory if needed - mkdir -p "${rbenv_install_dir}/shims" - - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH - - # And replace the old Ruby binary - test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby - - # Install the requested version of Ruby - local final_ruby_version=$(rbenv latest --print $ruby_version) - if ! [ -n "$final_ruby_version" ]; then - final_ruby_version=$ruby_version - fi - ynh_print_info --message="Installing Ruby-$final_ruby_version" - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 - - # Store ruby_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$final_ruby_version - - # Remove app virtualenv - if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` - then - rbenv alias $YNH_APP_INSTANCE_NAME --remove - fi - - # Create app virtualenv - rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version - - # Cleanup Ruby versions - ynh_cleanup_ruby - - # Set environment for Ruby users - echo "#rbenv -export RBENV_ROOT=$rbenv_install_dir -export PATH=\"$rbenv_install_dir/bin:$PATH\" -eval \"\$(rbenv init -)\" -#rbenv" > /etc/profile.d/rbenv.sh - - # Load the environment - eval "$(rbenv init -)" -} - -# Remove the version of Ruby used by the app. -# -# This helper will also cleanup Ruby versions -# -# usage: ynh_remove_ruby -ynh_remove_ruby () { - local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) - - # Load rbenv path in PATH - local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - rbenv alias $YNH_APP_INSTANCE_NAME --remove - - # Remove the line for this app - ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version - - # Cleanup Ruby versions - ynh_cleanup_ruby -} - -# Remove no more needed versions of Ruby used by the app. -# -# This helper will check what Ruby version are no more required, -# and uninstall them -# If no app uses Ruby, rbenv will be also removed. -# -# usage: ynh_cleanup_ruby -ynh_cleanup_ruby () { - - # List required Ruby versions - local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') - local required_ruby_versions="" - for installed_app in $installed_apps - do - local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") - if [[ $installed_app_ruby_version ]] - then - required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" - fi - done - - # Remove no more needed Ruby versions - local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') - for installed_ruby_version in $installed_ruby_versions - do - if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` - then - ynh_print_info --message="Removing of Ruby-$installed_ruby_version" - $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version - fi - done - - # If none Ruby version is required - if [[ ! $required_ruby_versions ]] - then - # Remove rbenv environment configuration - ynh_print_info --message="Removing of rbenv-$rbenv_version" - ynh_secure_remove --file="$rbenv_install_dir" - ynh_secure_remove --file="/etc/profile.d/rbenv.sh" - fi -}