From c7f76147ff831aef4866edc64c080b1b8ca8e0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 8 Feb 2018 11:42:15 +0100 Subject: [PATCH] Add change_url script and some fix --- README.md | 1 + check_process | 13 +++---- scripts/backup | 3 ++ scripts/change_url | 69 ++++++++++++++++++++++++++++++++++ scripts/experimental_helper.sh | 11 +++++- scripts/install | 2 +- scripts/remove | 3 +- scripts/restore | 5 ++- scripts/upgrade | 8 +++- 9 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 scripts/change_url diff --git a/README.md b/README.md index ea83471..185ceea 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ sudo yunohost app upgrade -f /home/admin/gogs_ynh gogs ## Todo - Big comment +- Restore cassé - Test multi instance - check migration - change-url diff --git a/check_process b/check_process index 4cf9936..05268bd 100644 --- a/check_process +++ b/check_process @@ -12,14 +12,13 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=aa075b2051ffad7b0b6fef3a9c767376d5bdbfab - upgrade=1 from_commit=1cbec051e1171de5a8ed1e850eb4fb3506114da5 - upgrade=1 from_commit=5a706ed246392c1ce39c47a648cb93e2996e80d3 + upgrade=1 from_commit=a790f67c69906743eda5c3a7b74ee51d4bb8f6bd + upgrade=1 from_commit=1f3515ca87f79081093d86b65ab4eaefa72e38e4 backup_restore=1 multi_instance=1 incorrect_path=0 port_already_use=1 (6000) - change_url=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto @@ -33,9 +32,7 @@ Level 9=0 Level 10=0 ;;; Upgrade options - ; commit=aa075b2051ffad7b0b6fef3a9c767376d5bdbfab + ; commit=a790f67c69906743eda5c3a7b74ee51d4bb8f6bd name=Before multi_instance and refactoring - ; commit=1cbec051e1171de5a8ed1e850eb4fb3506114da5 - name=From V0.10.18 - ; commit=5a706ed246392c1ce39c47a648cb93e2996e80d3 + ; commit=1f3515ca87f79081093d86b65ab4eaefa72e38e4 name=The oldest package diff --git a/scripts/backup b/scripts/backup index 4c5e533..98949e6 100644 --- a/scripts/backup +++ b/scripts/backup @@ -23,5 +23,8 @@ ynh_backup "$DATADIR" ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" ynh_backup "/etc/systemd/system/${app}.service" +# Backup logs +ynh_backup "/var/log/$app" + # Dump the database ynh_mysql_dump_db "$dbname" > ./db.sql diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..d73089c --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,69 @@ +#!/bin/bash + +# IMPORT GENERIC HELPERS +source /usr/share/yunohost/helpers + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +# Import common cmd +source ./experimental_helper.sh +source ./_common.sh + +cp -r /etc/yunohost/apps/${app}/conf ../ # Quick hack for https://github.com/YunoHost/yunohost/pull/427 + +# 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 + +dbpass=$(ynh_app_setting_get "$app" mysqlpwd) +admin=$(ynh_app_setting_get "$app" adminusername) +key=$(ynh_app_setting_get "$app" secret_key) +port=$(ynh_app_setting_get "$app" web_port) + +# 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) + +domain="$new_domain" +path_url="$new_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 + +# MODIFY URL IN NGINX CONF +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# 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 + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +config_nginx + +# Update gogs config +config_gogs + +# RELOAD services +systemctl reload nginx +systemctl restart "$app".service diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index 8d1c8b6..28b6123 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -1 +1,10 @@ - +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name +} diff --git a/scripts/install b/scripts/install index 3656094..c576b67 100644 --- a/scripts/install +++ b/scripts/install @@ -73,7 +73,7 @@ do done # Add ldap config -ynh_replace_string "__ADMIN__" "$admin" ../conf/login_source.sql$ +ynh_replace_string "__ADMIN__" "$admin" ../conf/login_source.sql ynh_replace_string "__APP__" "$app" ../conf/login_source.sql ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql diff --git a/scripts/remove b/scripts/remove index 27b37f1..8265751 100644 --- a/scripts/remove +++ b/scripts/remove @@ -23,7 +23,8 @@ ynh_mysql_drop_user "$dbuser" 2>/dev/null domain=$(ynh_app_setting_get "$app" domain) # Delete app directory and configurations -ynh_secure_remove "/opt/${app}" +ynh_secure_remove "$final_path" +ynh_secure_remove "$DATADIR" ynh_secure_remove "/var/log/$app" # Remove the app-specific logrotate config diff --git a/scripts/restore b/scripts/restore index 12ed88f..44a0618 100644 --- a/scripts/restore +++ b/scripts/restore @@ -40,6 +40,9 @@ ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql systemctl daemon-reload systemctl enable "$app".service +# Set permissions +set_permission + # Configure logrotate ynh_use_logrotate "/var/log/$app" @@ -48,4 +51,4 @@ yunohost service add "$app" --log /var/log/"$app"/"$app".log # Reload services systemctl reload nginx.service -systemctl restart "$app".service +systemctl start "$app".service diff --git a/scripts/upgrade b/scripts/upgrade index dc60399..11b0c7d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -62,6 +62,9 @@ then fi # end of old package upgrade +# Clean template to fix issue : https://github.com/gogits/gogs/issues/4585 +ynh_secure_remove "/opt/gogs/templates" + # Install Gogs ynh_setup_source $final_path $architecture @@ -91,4 +94,7 @@ then fi # Reload services -systemctl restart "$app".service \ No newline at end of file +systemctl restart "$app".service + + +sleep 10