From 0328159afb3826dd8289a30fb2ad0b6b8c86b7b0 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 25 Mar 2021 17:00:29 +0100 Subject: [PATCH] Fix --- README.md | 78 ++++++- check_process | 9 - conf/app.src | 4 +- conf/config.json | 12 +- conf/systemd.service | 8 +- manifest.json | 20 +- scripts/_common.sh | 522 ++----------------------------------------- scripts/backup | 54 ++--- scripts/install | 111 +++++---- scripts/remove | 63 +++--- 10 files changed, 227 insertions(+), 654 deletions(-) diff --git a/README.md b/README.md index 7151afe..3e50bfe 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,72 @@ -# NodeBB +# NodeBB for YunoHost -TEST UNIQUEMENT (pour l'instant)/TEST ONLY (for the moment) +[![Integration level](https://dash.yunohost.org/integration/nodebb.svg)](https://dash.yunohost.org/appci/app/nodebb) ![](https://ci-apps.yunohost.org/ci/badges/nodebb.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/nodebb.maintain.svg) +[![Install nodebb with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=nodebb) -- Website of the Yuno-package : https://github.com/YunoHost-Apps/nodebb_ynh -- Official website : https://nodebb.org -- Github website : https://github.com/NodeBB/NodeBB/ -- Documentation : [EN]https://docs.nodebb.org/ +*[Lire ce readme en français.](./README_fr.md)* -- A problem/ Un problème : parlez directement(chat) aux développeurs sur https://gitter.im/nodebb/nodebb +> *This package allows you to install nodebb quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* + +## Overview +Quick description of this app. + +**Shipped version:** 1.16.2 + +## Screenshots + +![](https://i.imgur.com/Ud1LrfI.png) + +## Demo + +* [Official demo](Link to a demo site for this app.) + +## Configuration + +How to configure this app: From an admin panel, a plain file with SSH, or any other way. + +## Documentation + + * Official documentation: https://docs.nodebb.org/ + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-user support + +Are LDAP and HTTP auth supported? +Can the app be used by multiple users? + +#### Supported architectures + +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/nodebb%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/nodebb/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/nodebb%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/nodebb/) + +## Limitations + +* Any known limitations. + +## Additional information + +* Other info you would like to add about this app. + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/nodebb_ynh/issues + * App website: https://github.com/NodeBB/NodeBB/ + * Upstream app repository: https://github.com/NodeBB/NodeBB/ + * YunoHost website: https://yunohost.org/ + +--- + +## Developer info + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/nodebb_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/nodebb_ynh/tree/testing --debug +or +sudo yunohost app upgrade nodebb -u https://github.com/YunoHost-Apps/nodebb_ynh/tree/testing --debug +``` -- License: GPLv3 -- Mainteneur actuel du paquet nodebb_ynh : frju365 (abld@tutanota.com) -- Niveau du Paquet : 2 diff --git a/check_process b/check_process index 33bf494..cf4e781 100644 --- a/check_process +++ b/check_process @@ -17,18 +17,9 @@ upgrade=1 backup_restore=0 multi_instance=0 - wrong_user=0 - wrong_path=1 - incorrect_path=1 corrupt_source=0 fail_download_source=0 - port_already_use=1 final_path_already_use=1 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=na # LDAP not integrated Level 5=1 # Test doesn't know what is really an exit diff --git a/conf/app.src b/conf/app.src index a8cee7d..699471e 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/NodeBB/NodeBB/archive/v1.11.1.tar.gz -SOURCE_SUM=ab12c046d23d38a24fe16a0276fff7f61c76b8c1de2538853875ba9234e23fcd +SOURCE_URL=https://github.com/NodeBB/NodeBB/archive/refs/tags/v1.16.2.tar.gz +SOURCE_SUM=2ae8745a9081dc9743f17cb46c81cd0636947f13ae752a314650af328141614a SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/config.json b/conf/config.json index ff29228..63412f9 100644 --- a/conf/config.json +++ b/conf/config.json @@ -1,13 +1,13 @@ { - "url": "https://__URL__", + "url": "https://__DOMAIN__", "secret": "__SECRET__", "database": "mongo", "port": "__PORT__", - "mongo": { + "postgres": { "host": "127.0.0.1", - "port": "27017", - "username": "dbuser", - "password": "dbpass", - "database": "dbname" + "port": "5432", + "username": "db_user", + "password": "db_pass", + "database": "db_name" } } diff --git a/conf/systemd.service b/conf/systemd.service index b6ecac4..90ef4d6 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,12 +1,14 @@ [Unit] -Description=NodeBB forum for Node.js. -After=network.target +Description=NodeBB +Documentation=https://docs.nodebb.org +After=system.slice multi-user.target mongod.service [Service] -Type=simple +Type=forking User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__ +PIDFile=/path/to/nodebb/pidfile Environment=NODE_ENV=production ExecStart=__NODE__/node loader.js --no-daemon --no-silent Restart=always diff --git a/manifest.json b/manifest.json index f70d2ff..e68e329 100644 --- a/manifest.json +++ b/manifest.json @@ -7,6 +7,7 @@ "en": "Nodejs Forum", "fr": "Forum écrit en nodejs" }, + "version": "1.16.2~ynh1", "url": "https://nodebb.org/", "license": "GPL-3.0", "maintainer": { @@ -15,7 +16,7 @@ "url": "https://github.com/Yunohost-Apps/nodebb_ynh" }, "requirements": { - "yunohost": ">> 3.0.0" + "yunohost": ">> 4.1.7" }, "multi_instance": false, "services": [ @@ -25,30 +26,19 @@ "install" : [ { "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain name for NodeBB", - "fr": "Choisissez un nom de domaine pour NodeBB" - }, + "type": "domain", "example": "example.com" }, { "name": "path", - "type": "path", - "ask": { - "en": "Choose a path for NodeBB, only / is allowed.", - "fr": "Choisissez un chemin pour NodeBB, seul / est autorisé." - }, + "type": "path", + "example": "/", "default": "/" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public site? ", - "fr": "Est-ce un site publique ? " - }, "default": true } ] diff --git a/scripts/_common.sh b/scripts/_common.sh index 065a01e..2047787 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,18 +1,27 @@ #!/bin/bash #================================================= +# COMMON VARIABLES +#================================================= + +nodejs_version=14 + +# dependencies used by the app +pkg_dependencies="postgresql postgresql-contrib" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= -# EXEC_LOGIN_AS Helper - -# Execute a command as another user with login -# (hence in user home dir, with prior loading of .profile, etc.) -# usage: exec_login_as USER COMMAND [ARG ...] -exec_login_as() { - local user=$1 - shift 1 - exec_as $user --login "$@" -} # Execute a command as another user # usage: exec_as USER COMMAND [ARG ...] exec_as() { @@ -26,485 +35,6 @@ exec_as() { fi } -#================================================= -# PACKAGE CHECK BYPASSING... -#================================================= - -IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé) - return $(uname -n | grep -c 'pchecker_lxc') -} - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -# INFOS -# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser. -# C'est ainsi qu'il change de version -# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n -# ynh_use_nodejs active une version de nodejs dans le script courant -# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app -# - nodejs_path: Le chemin absolu de cette version de node -# Utilisé pour des appels directs à node. -# - nodejs_version: Simplement le numéro de version de nodejs pour cette application -# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant. -# Utilisé pour démarrer un service ou un script qui utilise node ou npm -# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire. - -n_install_dir="/opt/node_n" -node_version_path="/opt/node_n/n/versions/node" -# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n. -export N_PREFIX="$n_install_dir" - -ynh_install_n () { - echo "Installation of N - Node.js version management" >&2 - # Build an app.src for n - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz -SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src" - # Download and extract n - ynh_setup_source "$n_install_dir/git" n - # Install n - (cd "$n_install_dir/git" - PREFIX=$N_PREFIX make install 2>&1) -} - -ynh_use_nodejs () { - nodejs_version=$(ynh_app_setting_get $app nodejs_version) - - load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir"" - - nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version" - - # "Load" a version of node - eval $load_n_path; $nodejs_use_version - - # Get the absolute path of this version of node - nodejs_path="$(n bin $nodejs_version)" - - # Make an alias for node use - ynh_node_exec="eval $load_n_path; n use $nodejs_version" -} - -ynh_install_nodejs () { - # Use n, https://github.com/tj/n to manage the nodejs versions - nodejs_version="$1" - local n_install_script="https://git.io/n-install" - - # 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 has already setup. - 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 "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$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 - n $nodejs_version - - # 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_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version" - - # Store nodejs_version into the config of this app - ynh_app_setting_set $app nodejs_version $nodejs_version - - # Build the update script and set the cronjob - ynh_cron_upgrade_node - - ynh_use_nodejs -} - -ynh_remove_nodejs () { - ynh_use_nodejs - - # Remove the line for this app - sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version" - - # If none another app uses this version of nodejs, remove it. - if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version" - then - n rm $nodejs_version - fi - - # If none another app uses n, remove n - if [ ! -s "$n_install_dir/ynh_app_version" ] - then - ynh_secure_remove "$n_install_dir" - ynh_secure_remove "/usr/local/n" - sed --in-place "/N_PREFIX/d" /root/.bashrc - fi -} - -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" -} - -#================================================= - -# Start or restart a service and follow its booting -# -# usage: ynh_check_starting "Line to match" [Log file] [Timeout] -# -# | arg: Line to match - The line to find in the log to attest the service have finished to boot. -# | arg: Log file - The log file to watch -# /var/log/$app/$app.log will be used if no other log is defined. -# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds. -ynh_check_starting () { - local line_to_match="$1" - local app_log="${2:-/var/log/$app/$app.log}" - local timeout=${3:-300} - - ynh_clean_check_starting () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 - } - - echo "Starting of $app" >&2 - systemctl restart $app - local templog="$(mktemp)" - # Following the starting of the app in its log - tail -f -n1 "$app_log" > "$templog" & - # Get the PID of the tail command - local pid_tail=$! - - local i=0 - for i in `seq 1 $timeout` - do - # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout - if grep --quiet "$line_to_match" "$templog" - then - echo "The service $app has correctly started." >&2 - break - fi - echo -n "." >&2 - sleep 1 - done - if [ $i -eq $timeout ] - then - echo "The service $app didn't fully started before the timeout." >&2 - fi - - echo "" - ynh_clean_check_starting -} - -#================================================= - -ynh_print_log () { - echo "${1}" -} - -# Print an info on stdout -# -# usage: ynh_print_info "Text to print" -# | arg: text - The text to print -ynh_print_info () { - ynh_print_log "[INFO] ${1}" -} - -# Print a warning on stderr -# -# usage: ynh_print_warn "Text to print" -# | arg: text - The text to print -ynh_print_warn () { - ynh_print_log "[WARN] ${1}" >&2 -} - -# Print a error on stderr -# -# usage: ynh_print_err "Text to print" -# | arg: text - The text to print -ynh_print_err () { - ynh_print_log "[ERR] ${1}" >&2 -} - -# Execute a command and print the result as an error -# -# usage: ynh_exec_err command to execute -# usage: ynh_exec_err "command to execute | following command" -# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. -# -# | arg: command - command to execute -ynh_exec_err () { - ynh_print_err "$(eval $@)" -} - -# Execute a command and print the result as a warning -# -# usage: ynh_exec_warn command to execute -# usage: ynh_exec_warn "command to execute | following command" -# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. -# -# | arg: command - command to execute -ynh_exec_warn () { - ynh_print_warn "$(eval $@)" -} - -# Execute a command and force the result to be printed on stdout -# -# usage: ynh_exec_warn_less command to execute -# usage: ynh_exec_warn_less "command to execute | following command" -# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. -# -# | arg: command - command to execute -ynh_exec_warn_less () { - eval $@ 2>&1 -} - -# Execute a command and redirect stdout in /dev/null -# -# usage: ynh_exec_quiet command to execute -# usage: ynh_exec_quiet "command to execute | following command" -# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. -# -# | arg: command - command to execute -ynh_exec_quiet () { - eval $@ > /dev/null -} - -# Execute a command and redirect stdout and stderr in /dev/null -# -# usage: ynh_exec_fully_quiet command to execute -# usage: ynh_exec_fully_quiet "command to execute | following command" -# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. -# -# | arg: command - command to execute -ynh_exec_fully_quiet () { - eval $@ > /dev/null 2>&1 -} - -# Remove any logs for all the following commands. -# -# usage: ynh_print_OFF -# WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging. -ynh_print_OFF () { - set +x -} - -# Restore the logging after ynh_print_OFF -# -# usage: ynh_print_ON -ynh_print_ON () { - set -x - # Print an echo only for the log, to be able to know that ynh_print_ON has been called. - echo ynh_print_ON > /dev/null -} - -#================================================= - -# Install or update the main directory yunohost.multimedia -# -# usage: ynh_multimedia_build_main_dir -ynh_multimedia_build_main_dir () { - wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip 2>&1 - unzip -q master.zip - ./yunohost.multimedia-master/script/ynh_media_build.sh -} - -# Add a directory in yunohost.multimedia -# This "directory" will be a symbolic link to a existing directory. -# -# usage: ynh_multimedia_addfolder "Source directory" "Destination directory" -# -# | arg: Source directory - The real directory which contains your medias. -# | arg: Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia" -ynh_multimedia_addfolder () { - local source_dir="$1" - local dest_dir="$2" - ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir" -} - -# Move a directory in yunohost.multimedia, and replace by a symbolic link -# -# usage: ynh_multimedia_movefolder "Source directory" "Destination directory" -# -# | arg: Source directory - The real directory which contains your medias. -# It will be moved to "Destination directory" -# A symbolic link will replace it. -# | arg: Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia" -ynh_multimedia_movefolder () { - local source_dir="$1" - local dest_dir="$2" - ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir" -} - -# Allow an user to have an write authorisation in multimedia directories -# -# usage: ynh_multimedia_addaccess user_name -# -# | arg: user_name - The name of the user which gain this access. -ynh_multimedia_addaccess () { - local user_name=$1 - groupadd -f multimedia - usermod -a -G multimedia $user_name -} - -#================================================= - -# Create a dedicated fail2ban config (jail and filter conf files) -# -# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]] -# | arg: log_file - Log file to be checked by fail2ban -# | arg: failregex - Failregex to be looked for by fail2ban -# | arg: max_retry - Maximum number of retries allowed before banning IP address - default: 3 -# | arg: ports - Ports blocked for a banned IP address - default: http,https -ynh_add_fail2ban_config () { - # Process parameters - logpath=$1 - failregex=$2 - max_retry=${3:-3} - ports=${4:-http,https} - - test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." - test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." - - finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf" - finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1 - ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1 - - sudo tee $finalfail2banjailconf <&2 - unset YNH_FORCE_UPGRADE - elif [ "$package_check" != "0" ] - then - echo "Upgrade forced for package check." >&2 - else - ynh_die "Up-to-date, nothing to do" 0 - fi - fi -} - -#================================================= # Send an email to inform the administrator # @@ -567,17 +97,3 @@ $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" } -#================================================= -#============= FUTURE YUNOHOST HELPER ============ -#================================================= - -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} diff --git a/scripts/backup b/scripts/backup index e18948b..ca47243 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,57 +6,48 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +# 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 #================================================= +ynh_clean_setup () { + ### Remove this function if there's nothing to clean before calling the remove script. + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -dbname=$(ynh_app_setting_get $app dbname) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= -# BACKUP THE MYSQL DATABASE -#================================================= - -pushd $final_path -mkdir mongo_backup -datebackup=$(date -u +%H%M%m%G) -ynh_app_setting_set $app datebackup $datebackup -pushd mongo_backup$datebackup -mongodump --db $dbname -popd -popd +ynh_print_info --message="Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP @@ -64,10 +55,23 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP LOGROTATE #================================================= -ynh_backup "/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup "/etc/systemd/system/$app.service" +ynh_backup --src_path="/etc/systemd/system/$app.service" + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= +ynh_print_info --message="Backing up the MySQL database..." + +ynh_mysql_dump_db --database="$db_name" > db.sql + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 040913b..ec79ddc 100644 --- a/scripts/install +++ b/scripts/install @@ -29,34 +29,32 @@ secret=$(ynh_string_random) #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_script_progression --message="Validating installation parameters..." --time --weight=1 final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) - -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +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_app_setting_set $app domain $domain -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set "$app" secret "$secret" +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=$secret--value="$secret" #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Finding an available port..." --time --weight=1 -port=$(ynh_find_port 4567) # Cherche un port libre. -ynh_app_setting_set $app port $port +# Find an available port +port=$(ynh_find_port --port=4567) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES @@ -66,30 +64,35 @@ ynh_install_app_dependencies mongodb systemctl start mongodb #================================================= -# CREATE A SQL BDD +# CREATE A MYSQL DATABASE #================================================= +ynh_script_progression --message="Creating a MySQL database..." --time --weight=1 + +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + +mongo --shell "$dbname" --eval 'db.createUser( { user: "'$db_user'", pwd: "'$db_pwd'", roles: [ "readWrite" ] } );' <<< exit +mongo --shell "$dbname" --eval 'db.grantRolesToUser("'$db_user'",[{ role: "clusterMonitor", db: "admin" }]);' <<< exit -dbname=$app -dbuser=$app -dbpass=$(ynh_string_random) -ynh_app_setting_set $app dbuser $dbuser -ynh_app_setting_set $app dbpass $dbpass -ynh_app_setting_set $app dbname $dbname -mongo --shell "$dbname" --eval 'db.createUser( { user: "'${dbuser}'", pwd: "'${dbpass}'", roles: [ "readWrite" ] } );' <<< exit -mongo --shell "$dbname" --eval 'db.grantRolesToUser("'${dbuser}'",[{ role: "clusterMonitor", db: "admin" }]);' <<< exit #================================================= -# INSTALL NODEJS +# INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." --weight=6 -ynh_install_nodejs 8.14.0 +#ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + +ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Configuring system user..." --time --weight=1 # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # SPECIFIC SETUP @@ -111,49 +114,48 @@ ynh_use_logrotate #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --time --weight=1 -final_path=/var/www/$app -ynh_app_setting_set $app final_path $final_path -ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$final_path" #================================================= -# Modify Nginx configuration file and copy it to Nginx conf directory +# NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configuring NGINX web server..." --time --weight=1 +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= # Add Systemd service #================================================= +ynh_script_progression --message="Configuring a systemd service..." --time --weight=1 -ynh_add_systemd_config ynh_replace_string "__NODEJS__" "$nodejs_use_version" "/etc/systemd/system/$app.service" ynh_replace_string "__ENV_PATH__" "$PATH" "/etc/systemd/system/$app.service" ynh_replace_string "__NODE__" "$nodejs_path" "/etc/systemd/system/$app.service" cat /etc/systemd/system/$app.service +ynh_add_systemd_config + #================================================= # CONFIGURE SERVER.JS #================================================= -mv ../conf/config.json $final_path/config.json -ynh_replace_string "__URL__" "$domain" "$final_path/config.json" -ynh_replace_string "__PORT__" "$port" "$final_path/config.json" -ynh_replace_string "__SECRET__" "$secret" "$final_path/config.json" -ynh_replace_string "dbuser" "$dbuser" "$final_path/config.json" -ynh_replace_string "dbname" "$dbname" "$final_path/config.json" -ynh_replace_string "dbpass" "$dbpass" "$final_path/config.json" -cat $final_path/config.json +ynh_add_config --template="../conf/config.json" --destination="$final_path/config.json" #================================================= # CONFIGURE NODEBB #================================================= chown -R $app:$app $final_path + pushd $final_path -exec_as "$app" ./nodebb setup -l > $install_log -exec_as "$app" npm install nodebb-plugin-dbsearch --save-prod -exec_as "$app" ./nodebb build -l + exec_as $app ./nodebb setup -l > $install_log + exec_as $app npm install nodebb-plugin-dbsearch --save-prod + exec_as $app ./nodebb build -l popd @@ -162,36 +164,33 @@ popd #================================================= cat /etc/systemd/system/$app.service -sudo systemctl daemon-reload -sudo systemctl enable "$app".service +systemctl daemon-reload +systemctl enable $app.service + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log" #================================================= # START ETHERPAD IN BACKGROUND #================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -systemctl start $app # Démarre Nodebb. Le démarrage est fait le plus tôt possible, car il est très long... - -#================================================= -# ENABLE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --log "/var/log/$app/nodebb.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring permissions..." --weight=1 -if [ $is_public -eq 0 ] -then # Remove the public access - ynh_app_setting_delete $app skipped_uris -fi # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_permission_update --permission="main" --add="visitors" fi -ynh_check_starting "NodeBB is now listening on: 0.0.0.0:4567" "/var/log/syslog" "90" #================================================= # RELOAD NGINX diff --git a/scripts/remove b/scripts/remove index 24ff799..2adad7c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,34 +12,45 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -dbname=$(ynh_app_setting_get $app dbname) -dbpass=$(ynh_app_setting_get $app dbpass) -dbuser=$dbname -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= + +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service integration..." --time --weight=1 + yunohost service remove $app +fi + #================================================= # STOP AND REMOVE SERVICE #================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." --time --weight=1 # Remove the dedicated systemd config ynh_remove_systemd_config #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Removing the MySQL database..." --time --weight=1 + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi #================================================= # REMOVE THE MONGO DATABASE @@ -51,6 +62,7 @@ mongo --shell "$dbname" --eval 'db.runCommand({dropDatabase: 1})' <<< exit #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." --time --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -58,39 +70,40 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." --time --weight=1 # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing NGINX web server configuration..." --time --weight=1 -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - echo "Close port $port" - yunohost firewall disallow TCP $port 2>&1 -fi - #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1 # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --time --last +