1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gogs_ynh.git synced 2024-09-03 20:36:23 +02:00

Add change_url script and some fix

This commit is contained in:
Josué Tille 2018-02-08 11:42:15 +01:00
parent 943f689f9d
commit c7f76147ff
9 changed files with 102 additions and 13 deletions

View file

@ -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

View file

@ -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

View file

@ -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

69
scripts/change_url Normal file
View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
systemctl restart "$app".service
sleep 10