From b48dc68fd15aefface954072756f23b7afcab9af Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 18 Apr 2020 19:13:20 +0200 Subject: [PATCH 01/11] [enh] systemd help with dynamic variables --- conf/systemd.service | 2 +- scripts/_common.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 7 +---- scripts/upgrade | 7 +---- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index b5a4e27..baf1489 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=ztncui Group=ztncui Environment="PATH=__PATH__" -WorkingDirectory=__FINAL_PATH__/src/ +WorkingDirectory=__FINALPATH__/src/ ExecStart=__NODEJS_PATH__/npm start [Install] diff --git a/scripts/_common.sh b/scripts/_common.sh index f55d066..da093a9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -32,6 +32,67 @@ exec_as() { fi } +# Create a dedicated systemd config +# +# usage: ynh_add_systemd_config [--service=service] [--template=template] [--others_var="list of others variables to replace"] +# | arg: -s, --service - Service name (optional, $app by default) +# | arg: -t, --template - Name of template file (optional, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template) +# | arg: -v, --others_var - List of others variables to replace separated by a space. For example: 'var_1 var_2 ...' +# +# This will use the template ../conf/.service +# to generate a systemd config, by replacing the following keywords +# with global variables that should be defined before calling +# this helper : +# +# __APP__ by $app +# __FINALPATH__ by $final_path +# +# And dynamic variables (from the last example) : +# __VAR_1__ by $var_1 +# __VAR_2__ by $var_2 +# +# Requires YunoHost version 2.7.2 or higher. +ynh_add_systemd_config_vars () { + # Declare an array to define the options of this helper. + local legacy_args=stv + declare -Ar args_array=( [s]=service= [t]=template= [v]=others_var= ) + local service + local template + local others_var + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + service="${service:-$app}" + template="${template:-systemd.service}" + others_var="${others_var:-}" + + finalsystemdconf="/etc/systemd/system/$service.service" + ynh_backup_if_checksum_is_different --file="$finalsystemdconf" + cp ../conf/$template "$finalsystemdconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsystemdconf" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsystemdconf" + fi + + # Replace all other variables given as arguments + for var_to_replace in $others_var + do + # ${var_to_replace^^} make the content of the variable on upper-cases + # ${!var_to_replace} get the content of the variable named $var_to_replace + ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalsystemdconf" + done + + ynh_store_file_checksum --file="$finalsystemdconf" + + chown root: "$finalsystemdconf" + systemctl enable $service + systemctl daemon-reload +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 21f9cbe..19c9851 100644 --- a/scripts/install +++ b/scripts/install @@ -211,13 +211,8 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei ### - As well as the section "RESTORE SYSTEMD" in the restore script ### - And the section "SETUP SYSTEMD" in the upgrade script -# Set the systemd service settings -ynh_replace_string "__PATH__" "$PATH" "../conf/systemd.service" -ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service" -ynh_replace_string "__FINAL_PATH__" "$final_path" "../conf/systemd.service" - # Create a dedicated systemd config -ynh_add_systemd_config +ynh_add_systemd_config_vars --others_var="path nodejs_path" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index f4c271a..e2a18a1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -183,13 +183,8 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 -# Set the systemd service settings -ynh_replace_string "__PATH__" "$PATH" "../conf/systemd.service" -ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service" -ynh_replace_string "__FINAL_PATH__" "$final_path" "../conf/systemd.service" - # Create a dedicated systemd config -ynh_add_systemd_config +ynh_add_systemd_config_vars --others_var="path nodejs_path" #================================================= # GENERIC FINALIZATION From 26fbbfa13d7cf0fa732d652d659a5e6405863396 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 18 Apr 2020 22:50:17 +0200 Subject: [PATCH 02/11] [fix] unbound variable --- conf/systemd.service | 2 +- scripts/install | 4 +++- scripts/upgrade | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index baf1489..4072a8b 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,7 +6,7 @@ After=network.target Type=simple User=ztncui Group=ztncui -Environment="PATH=__PATH__" +Environment="PATH=__ENV_PATH__" WorkingDirectory=__FINALPATH__/src/ ExecStart=__NODEJS_PATH__/npm start diff --git a/scripts/install b/scripts/install index 19c9851..264834f 100644 --- a/scripts/install +++ b/scripts/install @@ -211,8 +211,10 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei ### - As well as the section "RESTORE SYSTEMD" in the restore script ### - And the section "SETUP SYSTEMD" in the upgrade script +# Store current PATH +env_path=$PATH # Create a dedicated systemd config -ynh_add_systemd_config_vars --others_var="path nodejs_path" +ynh_add_systemd_config_vars --others_var="env_path nodejs_path" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index e2a18a1..d683589 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -183,8 +183,10 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +# Store current PATH +env_path=$PATH # Create a dedicated systemd config -ynh_add_systemd_config_vars --others_var="path nodejs_path" +ynh_add_systemd_config_vars --others_var="env_path nodejs_path" #================================================= # GENERIC FINALIZATION From fefa49295a0acaa71f02fd6d405b7640a239c6f0 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 19 Apr 2020 13:53:08 +0200 Subject: [PATCH 03/11] [enh] test nodejs helper --- conf/systemd.service | 6 +- scripts/_common.sh | 261 ++++++++++++++++++++++++++++++++++++++++++- scripts/backup | 2 +- scripts/change_url | 2 +- scripts/install | 14 +-- scripts/remove | 2 +- scripts/restore | 2 +- scripts/upgrade | 14 +-- 8 files changed, 278 insertions(+), 25 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 4072a8b..2fa01a6 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,9 +6,9 @@ After=network.target Type=simple User=ztncui Group=ztncui -Environment="PATH=__ENV_PATH__" -WorkingDirectory=__FINALPATH__/src/ -ExecStart=__NODEJS_PATH__/npm start +Environment="__YNH_NODE_LOAD_PATH__" +WorkingDirectory=__FINAL_PATH__/src/ +ExecStart=__YNH_NODE__/npm start [Install] WantedBy=multi-user.target diff --git a/scripts/_common.sh b/scripts/_common.sh index da093a9..9d1b813 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -21,14 +21,14 @@ pkg_dependencies="g++" # Execute a command as another user # usage: exec_as USER COMMAND [ARG ...] -exec_as() { +ynh_exec_as() { local USER=$1 shift 1 if [[ $USER = $(whoami) ]]; then eval "$@" else - sudo PATH=$PATH -u "$USER" "$@" + sudo -u "$USER" "$@" fi } @@ -96,3 +96,260 @@ ynh_add_systemd_config_vars () { #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +#!/bin/bash + +n_install_dir="/opt/node_n" +node_version_path="$n_install_dir/n/versions/node" +# N_PREFIX is the directory of n, it needs to be loaded as a environment variable. +export N_PREFIX="$n_install_dir" + +# Install Node version management +# +# [internal] +# +# usage: ynh_install_n +# +# Requires YunoHost version 2.7.12 or higher. +ynh_install_n () { + ynh_print_info --message="Installation of N - Node.js version management" + # Build an app.src for n + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/tj/n/archive/v4.1.0.tar.gz +SOURCE_SUM=3983fa3f00d4bf85ba8e21f1a590f6e28938093abe0bb950aeea52b1717471fc" > "../conf/n.src" + # Download and extract n + ynh_setup_source --dest_dir="$n_install_dir/git" --source_id=n + # Install n + (cd "$n_install_dir/git" + PREFIX=$N_PREFIX make install 2>&1) +} + +# Load the version of node for an app, and set variables. +# +# ynh_use_nodejs has to be used in any app scripts before using node for the first time. +# This helper will provide alias and variables to use in your scripts. +# +# To use npm or node, use the alias `ynh_npm` and `ynh_node` +# Those alias will use the correct version installed for the app +# For example: use `ynh_npm install` instead of `npm install` +# +# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_npm` and `$ynh_node` +# Exemple: `ynh_exec_as $app $ynh_npm install` +# +# $PATH contains the path of the requested version of node. +# However, $PATH is duplicated into $node_PATH to outlast any manipulation of $PATH +# You can use the variable `$ynh_node_load_PATH` to quickly load your node version +# in $PATH for an usage into a separate script. +# Exemple: $ynh_node_load_PATH $final_path/script_that_use_npm.sh` +# +# +# Finally, to start a nodejs service with the correct version, 2 solutions +# Either the app is dependent of node or npm, but does not called it directly. +# In such situation, you need to load PATH +# `Environment="__NODE_ENV_PATH__"` +# `ExecStart=__FINALPATH__/my_app` +# You will replace __NODE_ENV_PATH__ with $ynh_node_load_PATH +# +# Or node start the app directly, then you don't need to load the PATH variable +# `ExecStart=__YNH_NODE__ my_app run` +# You will replace __YNH_NODE__ with $ynh_node +# +# +# 2 other variables are also available +# - $nodejs_path: The absolute path to node binaries for the chosen version. +# - $nodejs_version: Just the version number of node for this app. Stored as 'nodejs_version' in settings.yml. +# +# usage: ynh_use_nodejs +# +# Requires YunoHost version 2.7.12 or higher. +ynh_use_nodejs () { + nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) + + # Get the absolute path of this version of node + nodejs_path="$node_version_path/$nodejs_version/bin" + + # Allow alias to be used into bash script + shopt -s expand_aliases + + # Create an alias for the specific version of node and a variable as fallback + ynh_node="$nodejs_path/node" + alias ynh_node="$ynh_node" + # And npm + ynh_npm="$nodejs_path/npm" + alias ynh_npm="$ynh_npm" + + # Load the path of this version of node in $PATH + [[ :$PATH: == *":$nodejs_path"* ]] || PATH="$nodejs_path:$PATH" + node_PATH="$PATH" + # Create an alias to easily load the PATH + ynh_node_load_PATH="PATH=$node_PATH" +} + +# Install a specific version of nodejs +# +# n (Node version management) uses the PATH variable to store the path of the version of node it is going to use. +# That's how it changes the version +# +# ynh_install_nodejs will install the version of node provided as argument by using n. +# +# usage: ynh_install_nodejs --nodejs_version=nodejs_version +# | arg: -n, --nodejs_version - Version of node to install. When possible, your should prefer to use major version number (e.g. 8 instead of 8.10.0). The crontab will then handle the update of minor versions when needed. +# +# Refer to ynh_use_nodejs for more information about available commands and variables +# +# Requires YunoHost version 2.7.12 or higher. +ynh_install_nodejs () { + # Use n, https://github.com/tj/n to manage the nodejs versions + + # Declare an array to define the options of this helper. + local legacy_args=n + declare -Ar args_array=( [n]=nodejs_version= ) + local nodejs_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + # Create $n_install_dir + mkdir -p "$n_install_dir" + + # Load n path in PATH + CLEAR_PATH="$n_install_dir/bin:$PATH" + # Remove /usr/local/bin in PATH in case of node prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing node binary, to avoid to block n. + test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n + test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n + + # If n is not previously setup, install it + if ! test $(n --version > /dev/null 2>&1) + then + ynh_install_n + fi + + # Modify the default N_PREFIX in n script + ynh_replace_string --match_string="^N_PREFIX=\${N_PREFIX-.*}$" --replace_string="N_PREFIX=\${N_PREFIX-$N_PREFIX}" --target_file="$n_install_dir/bin/n" + + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH + + # And replace the old node binary. + test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node + test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm + + # Install the requested version of nodejs + uname=$(uname -m) + if [[ $uname =~ aarch64 || $uname =~ arm64 ]] + then + n $nodejs_version --arch=arm64 + else + n $nodejs_version + fi + + # Find the last "real" version for this major version of node. + real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1) + real_nodejs_version=$(basename $real_nodejs_version) + + # Create a symbolic link for this major version if the file doesn't already exist + if [ ! -e "$node_version_path/$nodejs_version" ] + then + ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version + fi + + # Store the ID of this app and the version of node requested for it + echo "$YNH_APP_INSTANCE_NAME:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version" + + # Store nodejs_version into the config of this app + ynh_app_setting_set --app=$app --key=nodejs_version --value=$nodejs_version + + # Build the update script and set the cronjob + ynh_cron_upgrade_node + + ynh_use_nodejs +} + +# Remove the version of node used by the app. +# +# This helper will check if another app uses the same version of node, +# if not, this version of node will be removed. +# If no other app uses node, n will be also removed. +# +# usage: ynh_remove_nodejs +# +# Requires YunoHost version 2.7.12 or higher. +ynh_remove_nodejs () { + nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) + + # Remove the line for this app + sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$n_install_dir/ynh_app_version" + + # If no other app uses this version of nodejs, remove it. + if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version" + then + $n_install_dir/bin/n rm $nodejs_version + fi + + # If no other app uses n, remove n + if [ ! -s "$n_install_dir/ynh_app_version" ] + then + ynh_secure_remove --file="$n_install_dir" + ynh_secure_remove --file="/usr/local/n" + sed --in-place "/N_PREFIX/d" /root/.bashrc + rm -f /etc/cron.daily/node_update + fi +} + +# Set a cron design to update your node versions +# +# [internal] +# +# This cron will check and update all minor node versions used by your apps. +# +# usage: ynh_cron_upgrade_node +# +# Requires YunoHost version 2.7.12 or higher. +ynh_cron_upgrade_node () { + # Build the update script + cat > "$n_install_dir/node_update.sh" << EOF +#!/bin/bash + +version_path="$node_version_path" +n_install_dir="$n_install_dir" + +# Log the date +date + +# List all real installed version of node +all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")" + +# Keep only the major version number of each line +all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//') + +# Remove double entries +all_real_version=\$(echo "\$all_real_version" | sort --unique) + +# Read each major version +while read version +do + echo "Update of the version \$version" + sudo \$n_install_dir/bin/n \$version + + # Find the last "real" version for this major version of node. + real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1) + real_nodejs_version=\$(basename \$real_nodejs_version) + + # Update the symbolic link for this version + sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version +done <<< "\$(echo "\$all_real_version")" +EOF + + chmod +x "$n_install_dir/node_update.sh" + + # Build the cronjob + cat > "/etc/cron.daily/node_update" << EOF +#!/bin/bash + +$n_install_dir/node_update.sh >> $n_install_dir/node_update.log +EOF + + chmod +x "/etc/cron.daily/node_update" +} diff --git a/scripts/backup b/scripts/backup index 75059f1..4bc5361 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,9 +6,9 @@ # IMPORT GENERIC HELPERS #================================================= +source /usr/share/yunohost/helpers #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/change_url b/scripts/change_url index 3f21bc8..930ac61 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers +source _common.sh #================================================= # RETRIEVE ARGUMENTS diff --git a/scripts/install b/scripts/install index 264834f..49bbdf3 100644 --- a/scripts/install +++ b/scripts/install @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers +source _common.sh #================================================= # MANAGE SCRIPT FAILURE @@ -156,10 +156,10 @@ ynh_script_progression --message="Performing Node app installation..." --time -- chown -R $app: $final_path pushd $final_path/src - exec_as $app $nodejs_path/npm --loglevel=error install node-gyp - exec_as $app $nodejs_path/npm --loglevel=error install - exec_as $app $nodejs_path/npm --loglevel=error install argon2-cli - exec_as $app $nodejs_path/npm --loglevel=error audit fix + ynh_exec_as $app $ynh_npm --loglevel=error install node-gyp + ynh_exec_as $app $ynh_npm --loglevel=error install + ynh_exec_as $app $ynh_npm --loglevel=error install argon2-cli + ynh_exec_as $app $ynh_npm --loglevel=error audit fix popd #================================================= @@ -211,10 +211,8 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei ### - As well as the section "RESTORE SYSTEMD" in the restore script ### - And the section "SETUP SYSTEMD" in the upgrade script -# Store current PATH -env_path=$PATH # Create a dedicated systemd config -ynh_add_systemd_config_vars --others_var="env_path nodejs_path" +ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_node" #================================================= # GENERIC FINALIZATION diff --git a/scripts/remove b/scripts/remove index 9cf7ddf..b9beecd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers +source _common.sh #================================================= # LOAD SETTINGS diff --git a/scripts/restore b/scripts/restore index 5ca36da..538f833 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,9 +6,9 @@ # IMPORT GENERIC HELPERS #================================================= +source /usr/share/yunohost/helpers #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/upgrade b/scripts/upgrade index d683589..fcbfa99 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers +source _common.sh #================================================= # LOAD SETTINGS @@ -136,10 +136,10 @@ ynh_script_progression --message="Performing Node app installation..." --time -- chown -R $app: $final_path pushd $final_path/src - exec_as $app $nodejs_path/npm --loglevel=error install node-gyp - exec_as $app $nodejs_path/npm --loglevel=error install - exec_as $app $nodejs_path/npm --loglevel=error install argon2-cli - exec_as $app $nodejs_path/npm --loglevel=error audit fix + ynh_exec_as $app $ynh_npm --loglevel=error install node-gyp + ynh_exec_as $app $ynh_npm --loglevel=error install + ynh_exec_as $app $ynh_npm --loglevel=error install argon2-cli + ynh_exec_as $app $ynh_npm --loglevel=error audit fix popd #================================================= @@ -183,10 +183,8 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 -# Store current PATH -env_path=$PATH # Create a dedicated systemd config -ynh_add_systemd_config_vars --others_var="env_path nodejs_path" +ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_node" #================================================= # GENERIC FINALIZATION From 92d0de9ac60659bf5d1f75b054719746e09cf2d1 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 19 Apr 2020 14:51:57 +0200 Subject: [PATCH 04/11] [fix] node and npm paths --- conf/systemd.service | 2 +- scripts/install | 10 +++++----- scripts/upgrade | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 2fa01a6..1b56edb 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -8,7 +8,7 @@ User=ztncui Group=ztncui Environment="__YNH_NODE_LOAD_PATH__" WorkingDirectory=__FINAL_PATH__/src/ -ExecStart=__YNH_NODE__/npm start +ExecStart=__YNH_NPM__ start [Install] WantedBy=multi-user.target diff --git a/scripts/install b/scripts/install index 49bbdf3..0ad2a60 100644 --- a/scripts/install +++ b/scripts/install @@ -156,10 +156,10 @@ ynh_script_progression --message="Performing Node app installation..." --time -- chown -R $app: $final_path pushd $final_path/src - ynh_exec_as $app $ynh_npm --loglevel=error install node-gyp - ynh_exec_as $app $ynh_npm --loglevel=error install - ynh_exec_as $app $ynh_npm --loglevel=error install argon2-cli - ynh_exec_as $app $ynh_npm --loglevel=error audit fix + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error install node-gyp + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error install + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error install argon2-cli + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error audit fix popd #================================================= @@ -212,7 +212,7 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei ### - And the section "SETUP SYSTEMD" in the upgrade script # Create a dedicated systemd config -ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_node" +ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_npm" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index fcbfa99..d6c2e01 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -136,10 +136,10 @@ ynh_script_progression --message="Performing Node app installation..." --time -- chown -R $app: $final_path pushd $final_path/src - ynh_exec_as $app $ynh_npm --loglevel=error install node-gyp - ynh_exec_as $app $ynh_npm --loglevel=error install - ynh_exec_as $app $ynh_npm --loglevel=error install argon2-cli - ynh_exec_as $app $ynh_npm --loglevel=error audit fix + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error install node-gyp + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error install + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error install argon2-cli + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --loglevel=error audit fix popd #================================================= @@ -184,7 +184,7 @@ ynh_use_logrotate --non-append ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 # Create a dedicated systemd config -ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_node" +ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_npm" #================================================= # GENERIC FINALIZATION From 02bb04a50cc3edeb9852d742296f8c89f62606da Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 19 Apr 2020 16:11:52 +0200 Subject: [PATCH 05/11] [fix] ... --- conf/systemd.service | 2 +- scripts/_common.sh | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 1b56edb..fc89f0e 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=ztncui Group=ztncui Environment="__YNH_NODE_LOAD_PATH__" -WorkingDirectory=__FINAL_PATH__/src/ +WorkingDirectory=__FINALPATH__/src/ ExecStart=__YNH_NPM__ start [Install] diff --git a/scripts/_common.sh b/scripts/_common.sh index 9d1b813..5070404 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -97,8 +97,6 @@ ynh_add_systemd_config_vars () { # FUTURE OFFICIAL HELPERS #================================================= -#!/bin/bash - n_install_dir="/opt/node_n" node_version_path="$n_install_dir/n/versions/node" # N_PREFIX is the directory of n, it needs to be loaded as a environment variable. From 3dbb2dfc0df53952bae87b591b2ec749eb61691f Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 19 Apr 2020 17:16:04 +0200 Subject: [PATCH 06/11] [fix] upgrade * force replacing certs * standard admin and password if missing --- scripts/upgrade | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index d6c2e01..de21424 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -53,6 +53,17 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# If admin or password do not exist, assign the standard ones and have them replaced upon first login +if [ -z "$admin" ] || [ -z "$hashedpassword" ]; then + admin="admin" + hashedpassword='$argon2i$v=19$m=4096,t=3,p=1$/VYxjWHBzbkuCEO6Hh0AUw$nJaTJtth57vCAyYvg+UbtnscilR0UcE02AfLOhERe3A' + pass_set="false" + ynh_app_setting_set --app=$app --key=admin --value=$admin + ynh_app_setting_set --app=$hashedpassword --key=hashedpassword --value=$hashedpassword +else + pass_set="true" +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -157,7 +168,7 @@ echo "ZT_ADDR=localhost:$(> $env_fil echo "HTTP_PORT=$port" >> $env_file # Setup user credentials file -echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":true,\"hash\":\"$hashedpassword\"}}" >> "$final_path/src/etc/passwd" +echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":$pass_set,\"hash\":\"$hashedpassword\"}}" >> "$final_path/src/etc/passwd" #================================================= # LINK CERTIFICATES @@ -166,8 +177,8 @@ echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":true,\"hash\":\"$hashedpassw # Even though one can stay in HTTP mode, the ztncui requires SSL certificates # let's use the ones of the domain pushd $final_path/src/etc/tls - cp /etc/yunohost/certs/$domain/key.pem privkey.pem - cp /etc/yunohost/certs/$domain/crt.pem fullchain.pem + cp -f /etc/yunohost/certs/$domain/key.pem privkey.pem + cp -f /etc/yunohost/certs/$domain/crt.pem fullchain.pem popd #================================================= @@ -226,3 +237,7 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Upgrade of $app completed" --time --last + +if [ $pass_set = "false" ]; then + ynh_print_warn --message="Default ztncui credentials were reset: admin/password" +fi From 380ce69aef2e27c51adf49023efe24d12b23024c Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 25 Apr 2020 14:35:09 +0200 Subject: [PATCH 07/11] [enh] specify experimental helpers --- check_process | 2 +- scripts/_common.sh | 8 ++++---- scripts/backup | 2 +- scripts/change_url | 2 +- scripts/install | 6 +++--- scripts/remove | 4 ++-- scripts/restore | 4 ++-- scripts/upgrade | 6 +++--- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/check_process b/check_process index 89023cf..409ed35 100644 --- a/check_process +++ b/check_process @@ -14,7 +14,7 @@ port="666" (PORT) ; pre-install sudo yunohost app fetchlist - sudo yunohost app install zerotier + sudo yunohost app install https://github.com/tituspijean/zerotier_ynh ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/scripts/_common.sh b/scripts/_common.sh index 5070404..580f233 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -109,7 +109,7 @@ export N_PREFIX="$n_install_dir" # usage: ynh_install_n # # Requires YunoHost version 2.7.12 or higher. -ynh_install_n () { +EXPERIMENTAL_ynh_install_n () { ynh_print_info --message="Installation of N - Node.js version management" # Build an app.src for n mkdir -p "../conf" @@ -160,7 +160,7 @@ SOURCE_SUM=3983fa3f00d4bf85ba8e21f1a590f6e28938093abe0bb950aeea52b1717471fc" > " # usage: ynh_use_nodejs # # Requires YunoHost version 2.7.12 or higher. -ynh_use_nodejs () { +EXPERIMENTAL_ynh_use_nodejs () { nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) # Get the absolute path of this version of node @@ -196,7 +196,7 @@ ynh_use_nodejs () { # Refer to ynh_use_nodejs for more information about available commands and variables # # Requires YunoHost version 2.7.12 or higher. -ynh_install_nodejs () { +EXPERIMENTAL_ynh_install_nodejs () { # Use n, https://github.com/tj/n to manage the nodejs versions # Declare an array to define the options of this helper. @@ -274,7 +274,7 @@ ynh_install_nodejs () { # usage: ynh_remove_nodejs # # Requires YunoHost version 2.7.12 or higher. -ynh_remove_nodejs () { +EXPERIMENTAL_ynh_remove_nodejs () { nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) # Remove the line for this app diff --git a/scripts/backup b/scripts/backup index 4bc5361..75059f1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,9 +6,9 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/change_url b/scripts/change_url index 930ac61..3f21bc8 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS diff --git a/scripts/install b/scripts/install index 0ad2a60..4d887c1 100644 --- a/scripts/install +++ b/scripts/install @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE @@ -112,8 +112,8 @@ ynh_script_progression --message="Installing dependencies..." --time --weight=1 ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_use_nodejs +EXPERIMENTAL_ynh_install_nodejs --nodejs_version=$nodejs_version +EXPERIMENTAL_ynh_use_nodejs #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE diff --git a/scripts/remove b/scripts/remove index b9beecd..89f6ba4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS @@ -48,7 +48,7 @@ ynh_script_progression --message="Removing dependencies..." --time --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies -ynh_remove_nodejs +EXPERIMENTAL_ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/restore b/scripts/restore index 538f833..3d63998 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,9 +6,9 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE @@ -80,7 +80,7 @@ chown -R $app: $final_path #================================================= ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 -ynh_install_nodejs --nodejs_version=$nodejs_version +EXPERIMENTAL_ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # RESTORE SYSTEMD diff --git a/scripts/upgrade b/scripts/upgrade index de21424..18f241a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS @@ -126,8 +126,8 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_use_nodejs +EXPERIMENTAL_ynh_install_nodejs --nodejs_version=$nodejs_version +EXPERIMENTAL_ynh_use_nodejs #================================================= # CREATE DEDICATED USER From 748fba59e8976843c2bdafc19f831977e8f7c65a Mon Sep 17 00:00:00 2001 From: tituspijean Date: Thu, 14 May 2020 16:16:31 +0200 Subject: [PATCH 08/11] [fix] check_process After zerotier_ynh removal from apps list, one has to --force its installation --- check_process | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/check_process b/check_process index 409ed35..115031c 100644 --- a/check_process +++ b/check_process @@ -13,8 +13,7 @@ password="pass" port="666" (PORT) ; pre-install - sudo yunohost app fetchlist - sudo yunohost app install https://github.com/tituspijean/zerotier_ynh + sudo yunohost app install https://github.com/tituspijean/zerotier_ynh --force ; Checks pkg_linter=1 setup_sub_dir=0 From 1687530f5ac76e3281cea2ab87e7c7c944917fc7 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Thu, 14 May 2020 16:21:43 +0200 Subject: [PATCH 09/11] [rem] unnecessary sudo in nodejs helpers --- scripts/_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 580f233..d076a79 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -329,14 +329,14 @@ all_real_version=\$(echo "\$all_real_version" | sort --unique) while read version do echo "Update of the version \$version" - sudo \$n_install_dir/bin/n \$version + \$n_install_dir/bin/n \$version # Find the last "real" version for this major version of node. real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1) real_nodejs_version=\$(basename \$real_nodejs_version) # Update the symbolic link for this version - sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version + ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version done <<< "\$(echo "\$all_real_version")" EOF From ed13b624ee6af0dfdff5cda91e3284b6c458cecb Mon Sep 17 00:00:00 2001 From: tituspijean Date: Thu, 14 May 2020 16:32:18 +0200 Subject: [PATCH 10/11] [enh] calibrating script progression --- scripts/backup | 16 ++++++++-------- scripts/change_url | 14 +++++++------- scripts/install | 26 +++++++++++++------------- scripts/remove | 18 +++++++++--------- scripts/restore | 18 +++++++++--------- scripts/upgrade | 30 +++++++++++++++--------------- 6 files changed, 61 insertions(+), 61 deletions(-) diff --git a/scripts/backup b/scripts/backup index 75059f1..d93b468 100644 --- a/scripts/backup +++ b/scripts/backup @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -36,21 +36,21 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 +ynh_script_progression --message="Backing up the main app directory..." --weight=2 ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1 ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -59,21 +59,21 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 +ynh_script_progression --message="Backing up systemd configuration..." --weight=1 ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" @@ -81,4 +81,4 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/change_url b/scripts/change_url index 3f21bc8..2075311 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,7 +24,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -37,7 +37,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -72,14 +72,14 @@ fi #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Updating nginx web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -116,14 +116,14 @@ fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -131,4 +131,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --time --last +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 4d887c1..b5cb37b 100644 --- a/scripts/install +++ b/scripts/install @@ -53,7 +53,7 @@ app=$YNH_APP_INSTANCE_NAME ### Use the execution time, given by --time, to estimate the weight of a step. ### A common way to do it is to set a weight equal to the execution time in second +1. ### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. -ynh_script_progression --message="Validating installation parameters..." --time --weight=1 +ynh_script_progression --message="Validating installation parameters..." --weight=1 # Testing if ZeroTier is installed yunohost app list | grep -q "id: zerotier" || ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!" @@ -69,7 +69,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --time --weight=1 +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=final_path --value=$final_path @@ -79,7 +79,7 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." --time --weight=1 +ynh_script_progression --message="Configuring firewall..." --weight=1 ### Use these lines if you have to open a port for the application ### `ynh_find_port` will find the first available port starting from the given port. @@ -100,7 +100,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --time --weight=1 +ynh_script_progression --message="Installing dependencies..." --weight=2 ### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. ### Those deb packages will be installed as dependencies of this package. @@ -118,7 +118,7 @@ EXPERIMENTAL_ynh_use_nodejs #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --time --weight=1 +ynh_script_progression --message="Setting up source files..." --weight=2 ### `ynh_setup_source` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, like a git repository. @@ -131,7 +131,7 @@ ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 +ynh_script_progression --message="Configuring nginx web server..." --weight=1 ### `ynh_add_nginx_config` will use the file conf/nginx.conf @@ -141,7 +141,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --time --weight=1 +ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user ynh_system_user_create $app $final_path @@ -151,7 +151,7 @@ ynh_system_user_create $app $final_path #================================================= # NPM INSTALL #================================================= -ynh_script_progression --message="Performing Node app installation..." --time --weight=1 +ynh_script_progression --message="Performing Node app installation..." --weight=3 chown -R $app: $final_path @@ -198,7 +198,7 @@ popd #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --time --weight=1 +ynh_script_progression --message="Configuring a systemd service..." --weight=1 ### `ynh_systemd_config` is used to configure a systemd script for an app. ### It can be used for apps that use sysvinit (with adaptation) or systemd. @@ -230,7 +230,7 @@ chown -R $app: $final_path #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --time --weight=1 +ynh_script_progression --message="Configuring log rotation..." --weight=1 ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. @@ -268,7 +268,7 @@ yunohost service add $app --description "ZeroTier network controller user interf #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting the systemd service..." --time --weight=1 +ynh_script_progression --message="Starting the systemd service..." --weight=1 ### `ynh_systemd_action` is used to start a systemd service for an app. ### Only needed if you have configure a systemd service @@ -295,7 +295,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -303,4 +303,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --time --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 89f6ba4..f9bb932 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -29,14 +29,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --time --weight=1 + ynh_script_progression --message="Removing $app service..." --weight=1 yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 # Remove the dedicated systemd config ynh_remove_systemd_config @@ -44,7 +44,7 @@ ynh_remove_systemd_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --time --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=2 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -53,7 +53,7 @@ EXPERIMENTAL_ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --time --weight=1 +ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -61,7 +61,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Removing nginx web server configuration..." --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config @@ -69,7 +69,7 @@ ynh_remove_nginx_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 # Remove the app-specific logrotate config ynh_remove_logrotate @@ -89,7 +89,7 @@ fi #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user ynh_system_user_delete --username=$app @@ -98,4 +98,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --time --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 3d63998..2fcda80 100644 --- a/scripts/restore +++ b/scripts/restore @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --time --weight=1 +ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -36,7 +36,7 @@ nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 +ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -54,14 +54,14 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) ynh_system_user_create --username=$app @@ -78,14 +78,14 @@ chown -R $app: $final_path #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 +ynh_script_progression --message="Reinstalling dependencies..." --weight=2 EXPERIMENTAL_ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service @@ -99,7 +99,7 @@ yunohost service add $app --description "A short description of the app" --log " #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" @@ -114,7 +114,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -122,4 +122,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 18f241a..56f7964 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -39,7 +39,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If db_name doesn't exist, create it if [ -z "$db_name" ]; then @@ -67,7 +67,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 # Backup the current version of the app ynh_backup_before_upgrade @@ -95,7 +95,7 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" @@ -105,7 +105,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 + 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" @@ -114,7 +114,7 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 # Create a dedicated nginx config ynh_add_nginx_config @@ -122,7 +122,7 @@ ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 +ynh_script_progression --message="Upgrading dependencies..." --weight=2 ynh_install_app_dependencies $pkg_dependencies @@ -132,7 +132,7 @@ EXPERIMENTAL_ynh_use_nodejs #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) ynh_system_user_create $app $final_path @@ -142,7 +142,7 @@ ynh_system_user_create $app $final_path #================================================= # NPM INSTALL #================================================= -ynh_script_progression --message="Performing Node app installation..." --time --weight=1 +ynh_script_progression --message="Performing Node app installation..." --weight=3 chown -R $app: $final_path @@ -184,7 +184,7 @@ popd #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -192,7 +192,7 @@ ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config_vars --others_var="ynh_node_load_PATH ynh_npm" @@ -209,7 +209,7 @@ chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] @@ -221,14 +221,14 @@ fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -236,7 +236,7 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --last if [ $pass_set = "false" ]; then ynh_print_warn --message="Default ztncui credentials were reset: admin/password" From 94a7235b3f79246f35e948d7417196bfe4b7ac05 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Thu, 14 May 2020 17:27:31 +0200 Subject: [PATCH 11/11] [upg] package version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 1c013be..d552678 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "ZeroTier network controller user interface", "fr": "Interface utilisateur pour le contrôleur de réseau ZeroTier" }, - "version": "0.5.8~ynh1", + "version": "0.5.8~ynh2", "url": "https://key-networks.com/ztncui", "license": "GPL-3.0-only", "maintainer": {