From a98b6c7de6145d1696ec043684b88330168831b2 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 5 Nov 2017 18:40:37 +0100 Subject: [PATCH] Allow subpath installation --- check_process | 27 ++++++++++++++++-- conf/nginx.conf | 6 ++-- manifest.json | 30 ++++++++++++++++++-- scripts/install | 73 ++++++++++++++++++++++++++++++------------------- scripts/upgrade | 24 ++++++++++++++-- 5 files changed, 123 insertions(+), 37 deletions(-) diff --git a/check_process b/check_process index 3397437..0b62824 100644 --- a/check_process +++ b/check_process @@ -1,15 +1,17 @@ -;; Test complet avec libreoffice +;; Test complet avec libreoffice sans mypads auto_remove=1 ; Manifest domain="domain.tld" (DOMAIN) + path="/path" (PATH) admin="john" (USER) password="password" language="en" is_public=1 (PUBLIC|public=1|private=0) export="libreoffice" + mypads=0 ; Checks pkg_linter=1 - setup_sub_dir=0 + setup_sub_dir=1 setup_root=1 setup_nourl=0 setup_private=1 @@ -17,29 +19,48 @@ upgrade=1 backup_restore=1 multi_instance=0 - incorrect_path=0 + incorrect_path=1 port_already_use=1 (9001) change_url=0 +;; Test avec mypads + auto_remove=1 + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + admin="john" (USER) + password="password" + language="en" + is_public=1 (PUBLIC|public=1|private=0) + export="libreoffice" + mypads=1 + ; Checks + setup_root=1 + upgrade=1 + backup_restore=1 ;; Test abiword auto_remove=1 ; Manifest domain="domain.tld" (DOMAIN) + path="/path" (PATH) admin="john" (USER) password="password" language="en" is_public=1 (PUBLIC|public=1|private=0) export="abiword" + mypads=1 ; Checks setup_root=1 ;; Test sans export auto_remove=1 ; Manifest domain="domain.tld" (DOMAIN) + path="/path" (PATH) admin="john" (USER) password="password" language="en" is_public=1 (PUBLIC|public=1|private=0) export="none" + mypads=1 ; Checks setup_root=1 ;;; Levels diff --git a/conf/nginx.conf b/conf/nginx.conf index 1a59193..7a9d944 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,7 +1,9 @@ -location / { +location __PATH__/ { if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +#sub_path_only rewrite ^__PATH__/admin$ __PATH__/admin/ permanent; proxy_pass http://127.0.0.1:__PORT__/; proxy_set_header Host $host; proxy_buffering off; @@ -10,6 +12,6 @@ location / { include conf.d/yunohost_panel.conf.inc; } -location ~* /p/[^/]*(_|%|\*)[^/]*/export/etherpad { +location ~* __PATH__/p/[^/]*(_|%|\*)[^/]*/export/etherpad { return 404; } diff --git a/manifest.json b/manifest.json index 88c3971..0778ea8 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "email": "maniackc_dev@crudelis.fr" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 2.7.2" }, "multi_instance": true, "services": [ @@ -32,6 +32,20 @@ }, "example": "sub.domain.org" }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for Etherpad", + "fr": "Choisissez un chemin pour Etherpad" + }, + "help": { + "en": "If you choose to install mypads plugin, etherpad has to be on /", + "fr": "Si vous choisissez d'installer le plugin mypads, etherpad doit être sur /" + }, + "example": "/", + "default": "/" + }, { "name": "admin", "type": "user", @@ -68,7 +82,7 @@ }, "default": true }, - { + { "name": "export", "ask": { "en": "Use abiword (~260Mo) or libreoffice (~400Mo) (more stable) to expand export possibilities (pdf, doc) ?", @@ -76,6 +90,18 @@ }, "choices" : ["none", "abiword", "libreoffice"], "default" : "none" + }, + { + "name": "mypads", + "type": "boolean", + "ask": { + "en": "Do you want to install mypads plugin ?", + "fr": "Voulez-vous installer le plugin mypads ?" + }, + "help": { + "en": "mypads plugin" + }, + "default": true } ] } diff --git a/scripts/install b/scripts/install index 35576ee..4642ebe 100644 --- a/scripts/install +++ b/scripts/install @@ -31,11 +31,13 @@ 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 language=$YNH_APP_ARG_LANGUAGE is_public=$YNH_APP_ARG_IS_PUBLIC export=$YNH_APP_ARG_EXPORT +mypads=$YNH_APP_ARG_MYPADS app=$YNH_APP_INSTANCE_NAME @@ -48,34 +50,31 @@ then ynh_die "The password must be between 8 and 30 characters." fi -if yunohost domain list | grep -q $domain # Vérifie la liste des domaines -then # Si le domaine existe dans Yunohost - if yunohost app map | grep -q $domain # Vérifie la liste des apps par domaine - then # Si une app est installée sur ce domaine. - WARNING echo "An app is already installed on the domain $domain. Mypads needs a whole domain or subdomain to himself." - fi +if [ "$path_url" != "/" ] && [ $mypads -eq 1 ] +then + ynh_die "Mypads needs to be installed on the root of a domain or a subdomain." fi final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" -path_url="/" # Check web path availability ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url -path_url="" # Assure la compatibilité avec les fonctions utilisant $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= 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_app_setting_set $app language $language ynh_app_setting_set $app export $export +ynh_app_setting_set $app mypads $mypads #================================================= # STANDARD MODIFICATIONS @@ -121,6 +120,11 @@ ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie d # NGINX CONFIGURATION #================================================= +if [ "$path_url" != "/" ] +then + ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" +fi +ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" ynh_add_nginx_config #================================================= @@ -217,7 +221,9 @@ npm install ep_delete_empty_pads >> $install_log 2>&1 # Framapad - Delete pads w npm install ep_font_color >> $install_log 2>&1 # Framapad - Apply colors to fonts npm install ep_headings2 >> $install_log 2>&1 # Framapad - Adds heading support to Etherpad Lite. npm install ep_markdown >> $install_log 2>&1 # Framapad - Edit and Export as Markdown in Etherpad -npm install ep_mypads >> $install_log 2>&1 # Framapad - Groups and private pads for etherpad +if [ $mypads -eq 1 ]; then + npm install ep_mypads >> $install_log 2>&1 # Framapad - Groups and private pads for etherpad +fi npm install ep_page_view >> $install_log 2>&1 # Framapad - Add support to do 'page view', with a toggle on/off option in Settings, also Page Breaks with Control Enter npm install ep_spellcheck >> $install_log 2>&1 # Framapad - Add support to do 'Spell checking' npm install ep_subscript_and_superscript >> $install_log 2>&1 # Framapad - Add support for Subscript and Superscript @@ -229,15 +235,18 @@ chown -R $app: $final_path/node_modules # SOME HACKS #================================================= -# Ajoute un lien vers etherpad pour créer des pads anonymes depuis Mypads. -ynh_replace_string "^ *\"DESCRIPTION\": .*" "&Pads anonymes" $final_path/node_modules/ep_mypads/static/l10n/fr.json -ynh_replace_string "^ *\"DESCRIPTION\": .*" "&Anonymous pads" $final_path/node_modules/ep_mypads/static/l10n/en.json -# Et un lien vers l'admin etherpad depuis Mypads. -ynh_replace_string "^ *\"FOOTER\": .*2.0" "& | Etherpad admin" $final_path/node_modules/ep_mypads/static/l10n/en.json -ynh_replace_string "^ *\"FOOTER\": .*2.0" "& | Etherpad admin" $final_path/node_modules/ep_mypads/static/l10n/fr.json +if [ $mypads -eq 1 ] +then + # Ajoute un lien vers etherpad pour créer des pads anonymes depuis Mypads. + ynh_replace_string "^ *\"DESCRIPTION\": .*" "&Pads anonymes" $final_path/node_modules/ep_mypads/static/l10n/fr.json + ynh_replace_string "^ *\"DESCRIPTION\": .*" "&Anonymous pads" $final_path/node_modules/ep_mypads/static/l10n/en.json + # Et un lien vers l'admin etherpad depuis Mypads. + ynh_replace_string "^ *\"FOOTER\": .*2.0" "& | Etherpad admin" $final_path/node_modules/ep_mypads/static/l10n/en.json + ynh_replace_string "^ *\"FOOTER\": .*2.0" "& | Etherpad admin" $final_path/node_modules/ep_mypads/static/l10n/fr.json -mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "" | cut -d '-' -f 1) # Recherche le /div situé sous le champs d'ouverture de pad. -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. + mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "" | cut -d '-' -f 1) # Recherche le /div situé sous le champs d'ouverture de pad. + 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 @@ -269,19 +278,27 @@ systemctl reload nginx # CHECK ETHERPAD STARTING #================================================= -lang_OK=0 +if [ $mypads -eq 1 ] +then + lang_OK=0 +else + lang_OK=1 +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 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; + 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." diff --git a/scripts/upgrade b/scripts/upgrade index e053c7b..2b745dd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,6 +18,7 @@ source _variables app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) admin=$(ynh_app_setting_get $app admin) language=$(ynh_app_setting_get $app language) is_public=$(ynh_app_setting_get $app is_public) @@ -25,6 +26,7 @@ final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) export=$(ynh_app_setting_get $app export) db_name=$(ynh_app_setting_get $app db_name) +mypads=$(ynh_app_setting_get $app mypads) #================================================= # FIX OLD THINGS @@ -61,6 +63,16 @@ if [ -z $export ]; then # Si export n'est pas renseigné dans app setting ynh_app_setting_set $app export $export fi +if [ -z $mypads ]; then # Si mypads n'est pas renseigné dans app setting + mypads=1 + ynh_app_setting_set $app mypads $mypads +fi + +if [ -z $path_url ]; then # Si path_url n'est pas renseigné dans app setting + path_url="/" + ynh_app_setting_set $app path $path_url +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -92,6 +104,11 @@ ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie d # NGINX CONFIGURATION #================================================= +if [ "$path_url" != "/" ] +then + ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" +fi +ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf" ynh_add_nginx_config #================================================= @@ -185,8 +202,11 @@ ynh_add_systemd_config # SOME HACKS #================================================= -mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "" | cut -d '-' -f 1) # Recherche le /div situé sous le champs d'ouverture de pad. -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. +if [ $mypads -eq 1 ] +then + mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "" | cut -d '-' -f 1) # Recherche le /div situé sous le champs d'ouverture de pad. + 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