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"