From 6414a7d25cbce4ea5b18eadb372e22a556bc403b Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Tue, 3 Apr 2018 19:18:35 +0200 Subject: [PATCH] upgrade/restore/backup --- conf/nginx.conf | 2 - scripts/backup | 12 ++-- scripts/change_url | 125 --------------------------------------- scripts/install | 4 -- scripts/restore | 72 ++--------------------- scripts/upgrade | 144 ++++----------------------------------------- 6 files changed, 24 insertions(+), 335 deletions(-) delete mode 100644 scripts/change_url diff --git a/conf/nginx.conf b/conf/nginx.conf index c2b90bc..ab2eb0b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,8 +2,6 @@ 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; diff --git a/scripts/backup b/scripts/backup index 311dfb4..47cdb97 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,7 +29,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) +#db_name=$(ynh_app_setting_get $app db_name) #================================================= # STANDARD BACKUP STEPS @@ -50,8 +50,8 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP OF THE SQL BDD #================================================= -ynh_mysql_dump_db "$db_name" > db.sql -CHECK_SIZE "db.sql" +#ynh_mysql_dump_db "$db_name" > db.sql +#CHECK_SIZE "db.sql" #================================================= # SPECIFIC BACKUP @@ -59,7 +59,7 @@ CHECK_SIZE "db.sql" # BACKUP LOGROTATE #================================================= -ynh_backup "/etc/logrotate.d/$app" +#ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD @@ -71,5 +71,5 @@ ynh_backup "/etc/systemd/system/$app.service" # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_backup "/etc/fail2ban/jail.d/$app.conf" -ynh_backup "/etc/fail2ban/filter.d/$app.conf" +#ynh_backup "/etc/fail2ban/jail.d/$app.conf" +#ynh_backup "/etc/fail2ban/filter.d/$app.conf" diff --git a/scripts/change_url b/scripts/change_url deleted file mode 100644 index 06a5b58..0000000 --- a/scripts/change_url +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source _common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -app=$YNH_APP_INSTANCE_NAME - -mypads=$(ynh_app_setting_get $app mypads) - -#================================================= -# CHECK THE SYNTAX OF THE PATHS -#================================================= - -test -n "$old_path" || old_path="/" -test -n "$new_path" || new_path="/" -new_path=$(ynh_normalize_url_path $new_path) -old_path=$(ynh_normalize_url_path $old_path) - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - -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 - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# MODIFY URL IN NGINX CONF -#================================================= - -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the path in the nginx config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different "$nginx_conf_path" - - # Move from sub path to root - if [ "$new_path" == "/" ] - then - ynh_replace_string "^location $old_path/" "location $new_path" "$nginx_conf_path" - ynh_replace_string "^.*rewrite.*\^/" "#sub_path_only&" "$nginx_conf_path" - ynh_replace_string "^location ~\* $old_path/" "location ~* $new_path" "$nginx_conf_path" - - # Change the path in the two rewrite instructions - ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path" "$nginx_conf_path" - ynh_replace_string "\(rewrite *\^\)$old_path/*admin\$ $old_path/*" "\1${new_path}admin\$ $new_path" "$nginx_conf_path" - - # Move to a sub path - else - ynh_replace_string "^location $old_path.*" "location $new_path/ {" "$nginx_conf_path" - ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path" - ynh_replace_string "^location ~\* $old_path/*" "location ~* $new_path/" "$nginx_conf_path" - - # Change the path in the two rewrite instructions - ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path/" "$nginx_conf_path" - ynh_replace_string "\(rewrite *\^\)$old_path/*admin\$ $old_path/*" "\1$new_path/admin\$ $new_path/" "$nginx_conf_path" - fi - - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" -fi - -# Change the domain for nginx -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum "$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - - nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" -fi - -#================================================= -# RELOAD NGINX -#================================================= - -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" diff --git a/scripts/install b/scripts/install index 388f5fc..ac888e4 100644 --- a/scripts/install +++ b/scripts/install @@ -78,10 +78,6 @@ ynh_setup_source "$final_path" # Download, check integrity and uncompress the so # 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 diff --git a/scripts/restore b/scripts/restore index 2a9ae04..6f4cadd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -36,11 +36,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) 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) -ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -65,14 +60,6 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "$final_path" -#================================================= -# RESTORE THE SQL DB -#================================================= - -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -86,7 +73,7 @@ ynh_system_user_create $app $final_path # Recreate the dedicated user, if it doe #================================================= mkdir -p /var/log/$app -touch /var/log/$app/etherpad.log +touch /var/log/$app/timeoff.log install_log=/var/log/$app/installation.log touch $install_log chown $app -R /var/log/$app @@ -95,16 +82,6 @@ chown admin -R $install_log # Restore logrotate configuration ynh_restore_file "/etc/logrotate.d/$app" -#================================================= -# INSTALL DEPENDENCIES -#================================================= - -if [ "$export" = "abiword" ]; then - ynh_install_app_dependencies $abiword_app_depencencies -elif [ "$export" = "libreoffice" ]; then - ynh_install_app_dependencies $libreoffice_app_dependencies -fi - #================================================= # INSTALL NODEJS #================================================= @@ -117,13 +94,12 @@ ynh_install_nodejs $nodejs_version ynh_use_nodejs npm cache clean -npm install forever -g >> $install_log 2>&1 #================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= -yunohost service add $app --log "/var/log/$app/etherpad.log" +yunohost service add $app --log "/var/log/$app/timeoff.log" #================================================= # RESTORE SYSTEMD @@ -137,50 +113,12 @@ systemctl enable $app.service # RESTORE FAIL2BAN CONFIGURATION #================================================= -ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -systemctl restart fail2ban +# ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" +# ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" +# systemctl restart fail2ban #================================================= # RELOAD NGINX #================================================= systemctl reload nginx - -#================================================= -# CHECK ETHERPAD STARTING -#================================================= - -# Wait for etherpad to be 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 2 different admin panels, for etherpad by accessing https://$domain${path_url%/}/admin and for mypads by accessing 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 - -ynh_print_OFF -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 are 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 5fcb350..d062acb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,74 +20,18 @@ 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) 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) -useldap=$(ynh_app_setting_get $app useldap) #================================================= # CHECK VERSION #================================================= # Wait for etherpad to be fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" +# ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120" ynh_abort_if_up_to_date -#================================================= -# FIX OLD THINGS -#================================================= - -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 # Convert is_public to boolean - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 - is_public=0 -fi - -if [ -z $db_name ]; then # If db_name setting doesn't exist - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name -fi - -if [ -z $abiword ]; then # If abiword setting doesn't exist - abiword=0 - ynh_app_setting_set $app abiword $abiword -fi - -if [ -n $abiword ]; then # If abiword setting exists - if [ $abiword -eq 1 ]; then - export=abiword - fi - ynh_app_setting_set $app export $export - ynh_app_setting_delete $app abiword -fi - -if [ -z $export ]; then # If export setting doesn't exist - export=none - ynh_app_setting_set $app export $export -fi - -if [ -z $mypads ]; then # If mypads setting doesn't exist - mypads=1 - ynh_app_setting_set $app mypads $mypads -fi - -if [ -z $useldap ]; then # If useldap setting doesn't exist - useldap=0 - ynh_app_setting_set $app useldap $useldap -fi - -if [ -z $path_url ]; then # If path_url setting doesn't exist - path_url="/" - ynh_app_setting_set $app path $path_url -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -122,10 +66,6 @@ ynh_setup_source "$final_path" # Download, check integrity and uncompress the so # 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 @@ -133,13 +73,6 @@ ynh_add_nginx_config # UPGRADE NODEJS #================================================= -# Remove the old nvm helper. -if [ -d /opt/nvm ] -then - ynh_secure_remove "/opt/nvm" - sed --in-place "/NVM_DIR/d" /root/.bashrc -fi - ynh_install_nodejs $nodejs_version #================================================= @@ -154,41 +87,16 @@ npm update #================================================= # CONFIGURE ETHERPAD #================================================= +ynh_backup_if_checksum_is_different "$final_path/config/app.json" +ynh_backup_if_checksum_is_different "$final_path/config/db.json" -ynh_backup_if_checksum_is_different "$final_path/settings.json" # Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$final_path/credentials.json" # Verify the checksum and backup the file if it's different -cp ../conf/settings.json "$final_path/settings.json" -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) -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_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON -if [ "$export" = "abiword" ] -then - abiword_path=`which abiword` # Get abiword binary path - ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad -elif [ "$export" = "libreoffice" ] -then - soffice_path=`which soffice` # Get soffice binary path - ynh_replace_string "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" # Renseigne l'emplacement de abiword dans la config de etherpad -fi -if test -z $language; then - language=en # If upgrading from a version which doesn't support translations, set language to English by default - ynh_app_setting_set $app language $language -fi -ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" +cp ../conf/app.json "$final_path/config/app.json" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config/app.json" -# Use ldap for mypads -if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] -then - ynh_replace_string "//noldap" "" "$final_path/settings.json" -fi +cp ../conf/db.json "$final_path/config/db.json" -ynh_store_file_checksum "$final_path/settings.json" # Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/credentials.json" # Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/config/app.json" +ynh_store_file_checksum "$final_path/config/db.json" #================================================= # CREATE DEDICATED USER @@ -202,14 +110,14 @@ ynh_system_user_create $app $final_path # Create the dedicated user, if it doesn # Set files ownership to etherpad chown -R $app: $final_path -chmod 600 "$final_path/credentials.json" # Restrict access to credentials.json -chown $app -R /var/log/$app/etherpad.log +chmod 600 "$final_path/config/db.json" # Restrict access to credentials.json +chown $app -R /var/log/$app/timeoff.log #================================================= # UPGRADE FAIL2BAN #================================================= -ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" " .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5 +# ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" " .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5 #================================================= # SETUP LOGROTATE @@ -223,38 +131,12 @@ ynh_use_logrotate --non-append ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" +ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" +ynh_replace_string "__FINAL_PATH__" "$final_path" "../conf/systemd.service" ynh_add_systemd_config -#================================================= -# SOME HACKS -#================================================= - -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 - -#================================================= -# SETUP SSOWAT -#================================================= - -# Make app public if necessary -if [ $is_public -eq 1 ]; then - ynh_app_setting_set $app skipped_uris "/" -else - ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO... -fi - #================================================= # RELOAD NGINX #================================================= systemctl reload nginx - -#================================================= -# CHECK ETHERPAD STARTING -#================================================= - -# Wait for etherpad to be fully started -ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120"