From e8112505b3aa3b8b6622aab3d4039af60e2b3a92 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 26 Nov 2017 17:55:03 +0100 Subject: [PATCH 1/5] Readme fr --- README.md | 6 ++-- README_fr.md | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 README_fr.md diff --git a/README.md b/README.md index faa416b..7d8665e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ [![Integration level](https://dash.yunohost.org/integration/etherpad_mypads.svg)](https://ci-apps.yunohost.org/jenkins/job/etherpad_mypads%20%28Community%29/lastBuild/consoleFull) [![Install Etherpad with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=etherpad_mypads) +*[Lire ce readme en français.](./README_fr.md)* + > *This package allow you to install etherpad quickly and simply on a YunoHost server. If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* @@ -18,8 +20,8 @@ This package will install the same plugins than [Framapad](https://framapad.org/ ## Configuration -You can access to 2 different admin panels, for etherpad by accessing `domain.tld/admin` and for mypads by `domain.tld/mypads/?/admin` -Or, you can find a config file for etherpad at this path `/var/www/etherpad_mypads/settings.json` +You can access to 2 different admin panels, for etherpad by accessing `domain.tld/admin` and for mypads by `domain.tld/mypads/?/admin`. +Or, you can find a config file for etherpad at this path `/var/www/etherpad_mypads/settings.json`. ## Documentation diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..f03f690 --- /dev/null +++ b/README_fr.md @@ -0,0 +1,88 @@ +# Etherpad avec plugin mypads pour YunoHost + +[![Niveau d'intégration](https://dash.yunohost.org/integration/etherpad_mypads.svg)](https://ci-apps.yunohost.org/jenkins/job/etherpad_mypads%20%28Community%29/lastBuild/consoleFull) +[![Installer Etherpad avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=etherpad_mypads) + +*[Read this readme in english.](./README.md)* + +> *Ce package vous permet d'installer etherpad rapidement et simplement sur un serveur YunoHost. +Si vous n'avez pas YunoHost, merci de regarder [ici](https://yunohost.org/#/install_fr) pour savoir comment l'installer et en profiter.* + +## Résumé +Etherpad est un éditeur en ligne Open Source hautement personnalisable qui permet l'édition collaborative en temps réel. +Ce paquet installera les mêmes plugins que [Framapad](https://framapad.org/). + +**Version embarquée:** 1.6.2 + +## Captures d'écran + +![](http://etherpad.org/img/screenshot.png) + +## Configuration + +Vous pouvez accéder à 2 panneaux d'administration différents, pour etherpad en accédant à `domain.tld/admin` et pour mypads par `domain.tld/mypads/?/admin`. +Ou, vous pouvez trouver un fichier de configuration pour etherpad à `/var/www/etherpad_mypads/settings.json`. + +## Documentation + + * Documentation officielle: http://etherpad.org/doc/v1.6.2 + * Documentation YunoHost: Il n'y a pas d'autre documentation, n'hésitez pas à contribuer. + +## Fonctionnalités spécifiques à YunoHost + +#### Support multi-utilisateurs + +Supportée, **sans LDAP ni SSO**. + +#### Architectures supportées. + +* Testé sur x86_64 + +## Limitations + +* Si vous demandez d'installer le plugin mypads, vous devez installer à la racine d'un domaine ou d'un sous-domaine dédié. Sinon, mypads sera inaccessible. + +## Informations additionnelles + +* Ce paquet installera les plugins suivants: + + * ep_align - *Ajoute Gauche/Centre/Droite/Justifier à des lignes de texte dans un pad* + * ep_author_hover - *Ajoute des noms d'auteurs* + * ep_automatic_logut - *Déconnecte automatiquement l'utilisateur après une certaine période de temps (Prévient la surcharge du serveur)* + * ep_comments_page - *Ajoute des commentaires sur la sidebar et le lie au texte.* + * ep_countable - *Affiche les paragraphes, phrases, mots et nombres de caractères.* + * ep_delete_empty_pads - *Supprimer les pads qui n'ont jamais été édités* + * ep_font_color - *Appliquer les couleurs aux polices de caractères* + * ep_headings2 - *Ajoute le support de titre à Etherpad Lite.* + * ep_markdown - *Modifier et exporter en tant que Markdown dans Etherpad* + * ep_mypads - *Groupes et pads privés pour etherpad* + * ep_page_view - *Ajouter la prise en charge de 'page view', avec une option d'activation/désactivation dans Paramètres, ainsi que 'Page Breaks' avec Control + Entrée* + * ep_spellcheck - *Ajouter le support pour faire de la vérification orthographique* + * ep_subscript_and_superscript - *Ajouter la prise en charge de Subscript et Superscript*. + * ep_table_of_contents - *Voir une table des matières pour votre pad* + * ep_user_font_size - *Permet de définir taille de la police dans les paramètres, cela n'affecte pas les vues des autres personnes*. + +* Parce qu'il n'y a pas de support ldap avec le plugin mypads, aucun utilisateur n'est créé lors de l'installation. +Vous devez vous connecter au panneau d'administration pour créer les premiers utilisateurs. +Login et mot de passe sont ceux que vous avez choisis lors de l'installation. + +## Liens + + * Reporter un bug: https://github.com/YunoHost-Apps/etherpad_mypads_ynh/issues + * Site de etherpad: http://etherpad.org/ + * Site du plugin mypads: https://git.framasoft.org/framasoft/ep_mypads + * Site de YunoHost: https://yunohost.org/ + +--- + +Informations à l'intention des développeurs +---------------- + +Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/etherpad_mypads_ynh/tree/testing). + +Pour tester la branche testing, merci de procéder ainsi. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/etherpad_mypads_ynh/tree/testing --verbose +ou +sudo yunohost app upgrade etherpad_mypads -u https://github.com/YunoHost-Apps/etherpad_mypads_ynh/tree/testing --verbose +``` From 31a120ef1c8efef5a63fb7c40751fc6c037bc638 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 5 Dec 2017 19:27:22 +0100 Subject: [PATCH 2/5] Update package --- scripts/change_url | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 2f0442f..dd39267 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -58,27 +58,19 @@ then fi #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# MANAGE FAILURE OF THE SCRIPT #================================================= -if [ $change_domain -eq 0 ] -then - # Backup the current version of the app - ynh_backup_before_upgrade - ynh_clean_setup () { - # Nettoyage des résidus d'installation non pris en charge par le script remove. - if test -n "$PID_TAIL" - then - SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. - ynh_secure_remove "$tempfile" - fi - - # restore it if the upgrade fails - ynh_restore_upgradebackup - } - # Exit if an error occurs during the execution of the script - ynh_abort_if_errors -fi +ynh_clean_setup () { +# Nettoyage des résidus d'installation non pris en charge par le script remove. + if test -n "$PID_TAIL" + then + SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. + ynh_secure_remove "$tempfile" + fi +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # STANDARD MODIFICATIONS From 205f427cb8d373316773271829e652da59b4f33d Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Dec 2017 23:13:41 +0100 Subject: [PATCH 3/5] Add new helpers --- scripts/_common.sh | 370 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 341 insertions(+), 29 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index cac8bd1..883fe5e 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,31 +1,5 @@ #!/bin/bash -#================================================= -# DISPLAYING -#================================================= - -NO_PRINT () { # Supprime l'affichage dans stdout pour la commande en argument. - set +x - $@ - set -x -} - -WARNING () { # Écrit sur le canal d'erreur pour passer en warning. - $@ >&2 -} - -SUPPRESS_WARNING () { # Force l'écriture sur la sortie standard - $@ 2>&1 -} - -QUIET () { # Redirige la sortie standard dans /dev/null - $@ > /dev/null -} - -ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null - $@ > /dev/null 2>&1 -} - #================================================= # BACKUP #================================================= @@ -42,8 +16,8 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant if [ $free_space -le $backup_size ] then - WARNING echo "Espace insuffisant pour sauvegarder $file_to_analyse." - WARNING echo "Espace disponible: $(HUMAN_SIZE $free_space)" + ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse." + ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)" ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)" fi } @@ -57,7 +31,7 @@ IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé) } #================================================= -# NODEJS +# EXPERIMENTAL HELPERS #================================================= # INFOS @@ -234,6 +208,344 @@ 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 +} + +#================================================= + +# 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 +# +# usage: ynh_send_readme_to_admin app_message [recipients] +# | arg: app_message - The message to send to the administrator. +# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root +# example: "root admin@domain" +# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you +# example: "root admin@domain user1 user2" +ynh_send_readme_to_admin() { + local app_message="${1:-...No specific informations...}" + local recipients="${2:-root}" + + # Retrieve the email of users + find_mails () { + local list_mails="$1" + local mail + local recipients=" " + # Read each mail in argument + for mail in $list_mails + do + # Keep root or a real email address as it is + if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" + then + recipients="$recipients $mail" + else + # But replace an user name without a domain after by its email + if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) + then + recipients="$recipients $mail" + fi + fi + done + echo "$recipients" + } + recipients=$(find_mails "$recipients") + + local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!" + + local mail_message="This is an automated message from your beloved YunoHost server. + +Specific informations for the application $app. + +$app_message + +--- +Automatic diagnosis data from YunoHost + +$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" + + # Send the email to the recipients + echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" +} #================================================= #============= FUTURE YUNOHOST HELPER ============ From f17b3f33cd2094d584fdb9cf2350b480a47e5af2 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Dec 2017 23:15:26 +0100 Subject: [PATCH 4/5] Use new helpers --- manifest.json | 6 ++-- scripts/_sed | 51 ++++++++++++++++++++++++++++ scripts/change_url | 32 +++-------------- scripts/install | 85 ++++++++++++++++++++++------------------------ scripts/remove | 2 +- scripts/restore | 65 +++++++++++++++++++++-------------- scripts/upgrade | 46 +++++++------------------ 7 files changed, 151 insertions(+), 136 deletions(-) create mode 100644 scripts/_sed diff --git a/manifest.json b/manifest.json index 8493e34..46f696e 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Framapad clone, a online editor providing collaborative editing in real-time.", "fr": "Clone de Framapad, un éditeur en ligne fournissant l'édition collaborative en temps réel." }, - "version": "1.6.2", + "version": "1.6.2~ynh1", "url": "https://framapad.org", "license": "Apache-2.0", "maintainer": { @@ -27,8 +27,8 @@ "name": "domain", "type": "domain", "ask": { - "en": "Choose a dedicated domain for Etherpad Mypads.", - "fr": "Choisissez un domaine dédié pour Etherpad Mypads." + "en": "Choose a domain for Etherpad Mypads.", + "fr": "Choisissez un domaine pour Etherpad Mypads." }, "example": "sub.domain.org" }, diff --git a/scripts/_sed b/scripts/_sed new file mode 100644 index 0000000..cc76ab9 --- /dev/null +++ b/scripts/_sed @@ -0,0 +1,51 @@ +#!/bin/bash + +# https://github.com/YunoHost/yunohost/pull/394 + +# Substitute/replace a string (or expression) by another in a file +# +# usage: ynh_replace_string match_string replace_string target_file +# | arg: match_string - String to be searched and replaced in the file +# | arg: replace_string - String that will replace matches +# | arg: target_file - File in which the string will be replaced. +# +# As this helper is based on sed command, regular expressions and +# references to sub-expressions can be used +# (see sed manual page for more information) +ynh_replace_string () { + local delimit=@ + local match_string=$1 + local replace_string=$2 + local workfile=$3 + + # Escape the delimiter if it's in the string. + match_string=${match_string//${delimit}/"\\${delimit}"} + replace_string=${replace_string//${delimit}/"\\${delimit}"} + + sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile" +} + +# Substitute/replace a password by another in a file +# +# usage: ynh_replace_password_string match_string replace_string target_file +# | arg: match_string - String to be searched and replaced in the file +# | arg: replace_string - String that will replace matches +# | arg: target_file - File in which the string will be replaced. +# +# This helper will use ynh_replace_string, but as you can use special +# characters, you can't use some regular expressions and sub-expressions. +ynh_replace_password_string () { + local match_string=$1 + local replace_string=$2 + local workfile=$3 + + # Escape any backslash to preserve them as simple backslash. + match_string=${match_string//\\/"\\\\"} + replace_string=${replace_string//\\/"\\\\"} + + # Escape the & character, who has a special function in sed. + match_string=${match_string//&/"\&"} + replace_string=${replace_string//&/"\&"} + + ynh_replace_string "$match_string" "$replace_string" "$workfile" +} diff --git a/scripts/change_url b/scripts/change_url index dd39267..1925519 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -8,6 +8,7 @@ source _common.sh source /usr/share/yunohost/helpers +source _sed #================================================= # RETRIEVE ARGUMENTS @@ -63,11 +64,7 @@ fi ynh_clean_setup () { # Nettoyage des résidus d'installation non pris en charge par le script remove. - if test -n "$PID_TAIL" - then - SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. - ynh_secure_remove "$tempfile" - fi + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -130,30 +127,9 @@ fi systemctl reload nginx -#================================================= -# START ETHERPAD IN BACKGROUND -#================================================= - -# Démarre etherpad -WARNING echo "Redémarrage d'etherpad" -tempfile="$(mktemp)" -tail -f -n1 /var/log/$app/etherpad.log > "$tempfile" & # Suit le démarrage dans le log -PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan. -systemctl start $app # Redémarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long... - #================================================= # CHECK ETHERPAD STARTING #================================================= -for i in `seq 1 120` -do # La boucle attend le démarrage d'etherpad. Ou 2 minutes. Cette boucle évite simplement un 502 au début, car le démarrage est long... - if grep -q "You can access your Etherpad instance at" "$tempfile"; then - WARNING echo "Le service $app a démarré correctement." - break # Si le log annonce le démarrage d'etherpad, sort de la boucle. - fi - WARNING echo -n "." - sleep 1 -done -echo "" -QUIET kill -s 15 $PID_TAIL # Arrête l'exécution de tail. -ynh_secure_remove "$tempfile" +# Wait for etherpad fully started +ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" diff --git a/scripts/install b/scripts/install index ab5430f..91cfbc4 100644 --- a/scripts/install +++ b/scripts/install @@ -10,6 +10,7 @@ source _common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source _variables +source _sed #================================================= # MANAGE FAILURE OF THE SCRIPT @@ -17,12 +18,7 @@ source _variables ynh_clean_setup () { # Nettoyage des résidus d'installation non pris en charge par le script remove. - if test -n "$PID_TAIL" - then - SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. - ynh_secure_remove "$tempfile" - fi - echo "" + ynh_clean_check_starting } ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. @@ -171,7 +167,7 @@ ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" ynh_replace_string "__DB_USER__" "$db_name" "$final_path/credentials.json" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" -ynh_replace_string "__PASSWD__" "$password" "$final_path/credentials.json" +ynh_replace_password_string "__PASSWD__" "$password" "$final_path/credentials.json" if [ "$export" = "abiword" ] then abiword_path=`which abiword` # Récupère l'emplacement de l'exécutable de abiword @@ -251,16 +247,6 @@ then sed -i "$mod_line s@div>@&\n\t

Mypads
@" $final_path/src/templates/index.html # Pour ajouter un lien vers le plugin mypads depuis la page d'Etherpad. fi -#================================================= -# START ETHERPAD IN BACKGROUND -#================================================= - -WARNING echo "Démarrage d'etherpad" -tempfile="$(mktemp)" -tail -f -n1 /var/log/$app/etherpad.log > "$tempfile" & # Suit le démarrage dans le log -PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan. -systemctl start $app # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long... - #================================================= # SETUP SSOWAT #================================================= @@ -281,34 +267,43 @@ systemctl reload nginx # CHECK ETHERPAD STARTING #================================================= +# Wait for etherpad fully started +ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" + if [ $mypads -eq 1 ] then - lang_OK=0 -else - lang_OK=1 + ynh_replace_string "__LANGUAGE__" "$language" "$script_dir/../conf/lang_mypads.sql" + mysql -u $db_name -p$db_pwd $db_name < "$script_dir/../conf/lang_mypads.sql" + + # Wait for etherpad fully started + ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" fi -for i in `seq 1 120` -do # La boucle attend le démarrage d'etherpad. Ou 2 minutes. Cette boucle évite simplement un 502 au début, car le démarrage est long... - if [ $mypads -eq 1 ] - then - if grep -q "You can access your Etherpad instance at" "$tempfile" && [ "$lang_OK" -eq 0 ] ; then - # Si le log annonce une première fois le démarrage d'etherpad, applique la langue de mypads et redémarre le service. - WARNING echo "Le service $app a démarré correctement." - ynh_replace_string "__LANGUAGE__" "$language" "$script_dir/../conf/lang_mypads.sql" - mysql -u $db_name -p$db_pwd $db_name < "$script_dir/../conf/lang_mypads.sql" - echo "" - systemctl restart $app - cat /dev/null > "$tempfile" # Purge le log de suivi du démarrage. - lang_OK=1 - i=1; - fi - fi - if grep -q "You can access your Etherpad instance at" "$tempfile" && [ "$lang_OK" -eq 1 ]; then - WARNING echo "Le service $app a démarré correctement." - break # Si le log annonce une deuxième fois le démarrage d'etherpad, sort de la boucle. - fi - WARNING echo -n "." - sleep 1 -done -SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. -ynh_secure_remove "$tempfile" + +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +if [ $mypads -eq 1 ] +then + Informations1="You can access to 2 different admin panels, for etherpad by accessing https://$domain${path_url%/}/admin and for mypads by https://$domain${path_url%/}/mypads/?/admin." + + Informations2=" +Because there's no ldap support with mypads plugin, no user is created at the installation. +You have to connect to the admin panel to create the first users. +" +else + Informations1="You can access to the admin panel, by accessing https://$domain${path_url%/}/admin." + + Informations2="" +fi + +message="$Informations1 +Or, you can find a config file for etherpad at this path /var/www/etherpad_mypads/settings.json. + +Your credentials for the admin panel are: +- login : $admin +- password : $password +$Informations2 +If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh" + +ynh_send_readme_to_admin "$message" "$admin" diff --git a/scripts/remove b/scripts/remove index 65e6c6e..ec55e4f 100755 --- a/scripts/remove +++ b/scripts/remove @@ -34,7 +34,7 @@ ynh_remove_systemd_config if yunohost service status | grep -q $app # Test l'existence du service dans Yunohost then - echo "Remove $app service" + ynh_print_info "Remove $app service" >&2 yunohost service remove $app fi diff --git a/scripts/restore b/scripts/restore index 704edf3..f4ae657 100644 --- a/scripts/restore +++ b/scripts/restore @@ -20,6 +20,10 @@ source ../settings/scripts/_variables # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { +# Nettoyage des résidus d'installation non pris en charge par le script remove. + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -30,16 +34,19 @@ ynh_abort_if_errors app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path_url) +path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get $app db_name) export=$(ynh_app_setting_get $app export) +mypads=$(ynh_app_setting_get $app mypads) +admin=$(ynh_app_setting_get $app admin) +password=$(ynh_app_setting_get $app password) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -yunohost app checkurl "${domain}${path_url}" -a "$app" \ +ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " @@ -126,16 +133,6 @@ ynh_restore_file "/etc/systemd/system/$app.service" ## Démarrage auto du service systemctl enable $app.service -#================================================= -# START ETHERPAD IN BACKGROUND -#================================================= - -echo "Démarrage d'etherpad" >&2 -tempfile="$(mktemp)" -tail -f -n1 /var/log/$app/etherpad.log > "$tempfile" & # Suit le démarrage dans le log -PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan. -systemctl start $app # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long... - #================================================= # RELOAD NGINX #================================================= @@ -146,16 +143,34 @@ systemctl reload nginx # CHECK ETHERPAD STARTING #================================================= -# Surveille le démarrage du service. -for i in `seq 1 60` -do # La boucle attend le démarrage d'etherpad. Ou 1 minute. Cette boucle évite simplement un 502 au début, car le démarrage est long... - if grep -q "You can access your Etherpad instance at" "$tempfile"; then - echo "Le service $app a démarré correctement." >&2 - break # Si le log annonce le démarrage d'etherpad, sort de la boucle. - fi - echo -n "." >&2 - sleep 1 -done -echo "" -kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail. -ynh_secure_remove "$tempfile" +# Wait for etherpad fully started +ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" + +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +if [ $mypads -eq 1 ] +then + Informations1="You can access to 2 different admin panels, for etherpad by accessing https://$domain${path_url%/}/admin and for mypads by https://$domain${path_url%/}/mypads/?/admin." + + Informations2=" +Because there's no ldap support with mypads plugin, no user is created at the installation. +You have to connect to the admin panel to create the first users. +" +else + Informations1="You can access to the admin panel, by accessing https://$domain${path_url%/}/admin." + + Informations2="" +fi + +message="$Informations1 +Or, you can find a config file for etherpad at this path /var/www/etherpad_mypads/settings.json. + +Your credentials for the admin panel are: +- login : $admin +- password : $password +$Informations2 +If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh" + +ynh_send_readme_to_admin "$message" "$admin" diff --git a/scripts/upgrade b/scripts/upgrade index 88c6106..347ab6e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,6 +10,7 @@ source _common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source _variables +source _sed #================================================= # LOAD SETTINGS @@ -28,6 +29,12 @@ export=$(ynh_app_setting_get $app export) db_name=$(ynh_app_setting_get $app db_name) mypads=$(ynh_app_setting_get $app mypads) +#================================================= +# CHECK VERSION +#================================================= + +ynh_abort_if_up_to_date + #================================================= # FIX OLD THINGS #================================================= @@ -81,11 +88,7 @@ fi ynh_backup_before_upgrade ynh_clean_setup () { # Nettoyage des résidus d'installation non pris en charge par le script remove. - if test -n "$PID_TAIL" - then - SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. - ynh_secure_remove "$tempfile" - fi + ynh_clean_check_starting # restore it if the upgrade fails ynh_restore_upgradebackup @@ -155,7 +158,7 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) password=$(ynh_app_setting_get $app password) ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" -ynh_replace_string "__PASSWD__" "$password" "$final_path/credentials.json" +ynh_replace_password_string "__PASSWD__" "$password" "$final_path/credentials.json" if [ "$export" = "abiword" ] then abiword_path=`which abiword` # Récupère l'emplacement de l'exécutable de abiword @@ -192,10 +195,7 @@ chown $app -R /var/log/$app/etherpad.log # SETUP LOGROTATE #================================================= -# Remove logrotate config -ynh_remove_logrotate -# And replace it -ynh_use_logrotate +ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD @@ -215,17 +215,6 @@ then sed -i "$mod_line s@div>@&\n\t

Mypads
@" $final_path/src/templates/index.html # Pour ajouter un lien vers le plugin mypads depuis la page d'Etherpad. fi -#================================================= -# START ETHERPAD IN BACKGROUND -#================================================= - -# Démarre etherpad -WARNING echo "Redémarrage d'etherpad" -tempfile="$(mktemp)" -tail -f -n1 /var/log/$app/etherpad.log > "$tempfile" & # Suit le démarrage dans le log -PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan. -systemctl start $app # Redémarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long... - #================================================= # SETUP SSOWAT #================================================= @@ -247,16 +236,5 @@ systemctl reload nginx # CHECK ETHERPAD STARTING #================================================= - -for i in `seq 1 120` -do # La boucle attend le démarrage d'etherpad. Ou 2 minutes. Cette boucle évite simplement un 502 au début, car le démarrage est long... - if grep -q "You can access your Etherpad instance at" "$tempfile"; then - WARNING echo "Le service $app a démarré correctement." - break # Si le log annonce le démarrage d'etherpad, sort de la boucle. - fi - WARNING echo -n "." - sleep 1 -done -echo "" -QUIET kill -s 15 $PID_TAIL # Arrête l'exécution de tail. -ynh_secure_remove "$tempfile" +# Wait for etherpad fully started +ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" From 011503a5b3a6e345da00b39b34dbd9c261de0362 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 21 Dec 2017 20:44:05 +0100 Subject: [PATCH 5/5] Remove password from log --- scripts/_common.sh | 17 +++++++++++++++++ scripts/install | 10 +++++++--- scripts/restore | 4 +++- scripts/upgrade | 4 ++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 883fe5e..522fde5 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -343,6 +343,23 @@ 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 diff --git a/scripts/install b/scripts/install index 91cfbc4..e8b05d5 100644 --- a/scripts/install +++ b/scripts/install @@ -29,7 +29,7 @@ ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est dét domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN -password=$YNH_APP_ARG_PASSWORD +ynh_print_OFF; password=$YNH_APP_ARG_PASSWORD; ynh_print_ON language=$YNH_APP_ARG_LANGUAGE is_public=$YNH_APP_ARG_IS_PUBLIC export=$YNH_APP_ARG_EXPORT @@ -41,10 +41,12 @@ app=$YNH_APP_INSTANCE_NAME # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= +ynh_print_OFF if [ "${#password}" -lt 8 ] || [ "${#password}" -gt 30 ] then ynh_die "The password must be between 8 and 30 characters." fi +ynh_print_ON if [ "$path_url" != "/" ] && [ $mypads -eq 1 ] then @@ -70,7 +72,7 @@ ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url ynh_app_setting_set $app admin $admin ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app password $password +ynh_print_OFF; ynh_app_setting_set $app password $password; ynh_print_ON ynh_app_setting_set $app language $language ynh_app_setting_set $app export $export ynh_app_setting_set $app mypads $mypads @@ -167,7 +169,7 @@ ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" ynh_replace_string "__DB_USER__" "$db_name" "$final_path/credentials.json" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" -ynh_replace_password_string "__PASSWD__" "$password" "$final_path/credentials.json" +ynh_print_OFF; ynh_replace_password_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON if [ "$export" = "abiword" ] then abiword_path=`which abiword` # Récupère l'emplacement de l'exécutable de abiword @@ -297,6 +299,7 @@ else Informations2="" fi +ynh_print_OFF message="$Informations1 Or, you can find a config file for etherpad at this path /var/www/etherpad_mypads/settings.json. @@ -307,3 +310,4 @@ $Informations2 If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh" ynh_send_readme_to_admin "$message" "$admin" +ynh_print_ON diff --git a/scripts/restore b/scripts/restore index f4ae657..0144967 100644 --- a/scripts/restore +++ b/scripts/restore @@ -40,7 +40,7 @@ db_name=$(ynh_app_setting_get $app db_name) export=$(ynh_app_setting_get $app export) mypads=$(ynh_app_setting_get $app mypads) admin=$(ynh_app_setting_get $app admin) -password=$(ynh_app_setting_get $app password) +ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -164,6 +164,7 @@ else Informations2="" fi +ynh_print_OFF message="$Informations1 Or, you can find a config file for etherpad at this path /var/www/etherpad_mypads/settings.json. @@ -174,3 +175,4 @@ $Informations2 If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh" ynh_send_readme_to_admin "$message" "$admin" +ynh_print_ON diff --git a/scripts/upgrade b/scripts/upgrade index 347ab6e..bc1b244 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -155,10 +155,10 @@ cp ../conf/credentials.json "$final_path/credentials.json" ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" ynh_replace_string "__DB_USER__" "$app" "$final_path/credentials.json" db_pwd=$(ynh_app_setting_get $app mysqlpwd) -password=$(ynh_app_setting_get $app password) +ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" -ynh_replace_password_string "__PASSWD__" "$password" "$final_path/credentials.json" +ynh_print_OFF; ynh_replace_password_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON if [ "$export" = "abiword" ] then abiword_path=`which abiword` # Récupère l'emplacement de l'exécutable de abiword