seafile_ynh/scripts/change_url

143 lines
5.5 KiB
Text
Raw Normal View History

2017-08-09 22:13:32 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
2017-08-09 22:13:32 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
# Import common cmd
source ./experimental_helper.sh
2017-08-09 22:13:32 +02:00
source ./_common.sh
# Retrive arguments
old_domain=$YNH_APP_OLD_DOMAIN
2018-05-10 01:24:20 +02:00
domain=$YNH_APP_NEW_DOMAIN
old_path=$(ynh_normalize_url_path ${YNH_APP_OLD_PATH:-'/'})
path_url=$(ynh_normalize_url_path ${YNH_APP_NEW_PATH:-'/'})
seahub_port=$(ynh_app_setting_get $app seahub_port)
fileserver_port=$(ynh_app_setting_get $app fileserver_port)
webdav_port=$(ynh_app_setting_get $app webdav_port)
2017-08-09 22:13:32 +02:00
2017-12-01 23:58:31 +01:00
# Get dest folder and system user
2017-08-09 22:13:32 +02:00
get_configuration
# Create special path with / at the end
if [[ $old_path == '/' ]]
then
old_path2=$old_path
else
old_path2=$old_path'/'
2017-08-09 22:13:32 +02:00
fi
if [[ $path_url == '/' ]]
2017-08-09 22:13:32 +02:00
then
path_url2=$path_url
2017-08-09 22:13:32 +02:00
else
path_url2=$path_url'/'
2017-08-09 22:13:32 +02:00
fi
#=================================================
2017-08-09 22:13:32 +02:00
# STANDARD MODIFICATIONS
#=================================================
# Update nginx config
if [ "$old_domain" != "$domain" ]
2017-08-09 22:13:32 +02:00
then
2018-05-19 21:51:46 +02:00
# Delete file checksum for the old conf file location
ynh_delete_file_checksum "/etc/nginx/conf.d/$old_domain.d/$app.conf"
mv "/etc/nginx/conf.d/$old_domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
2017-08-09 22:13:32 +02:00
fi
ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
2017-08-09 22:13:32 +02:00
# Stop service before any change
sudo systemctl stop seafile-server.service
# Update Seafile Config
ynh_replace_string "SERVICE_URL = https://$old_domain$old_path" "SERVICE_URL = https://$domain$path_url" $final_path/conf/ccnet.conf
ynh_replace_string 'FILE_SERVER_ROOT = "https://'"$old_domain"'/seafhttp"' 'FILE_SERVER_ROOT = "https://'"$domain"'/seafhttp"' $final_path/conf/seahub_settings.py
ynh_replace_string 'SITE_ROOT = "'"$old_path2"'"' 'SITE_ROOT = "'"$path_url2"'"' $final_path/conf/seahub_settings.py
ynh_replace_string 'MEDIA_URL = "'"$old_path2"'media/"' 'MEDIA_URL = "'"$path_url2"'media/"' $final_path/conf/seahub_settings.py
ynh_replace_string "LOGIN_URL = '${old_path2}accounts/login/'" "LOGIN_URL = '${path_url2}accounts/login/'" $final_path/conf/seahub_settings.py
ynh_replace_string ' = "seafile@'"$old_domain"'"' ' = "seafile@'"$domain"'"' $final_path/conf/seahub_settings.py
sed --in-place "s@ALLOWED_HOSTS = \['${old_domain}'\]@ALLOWED_HOSTS = \['${domain}'\]@g" $final_path/conf/seahub_settings.py
2017-08-09 22:13:32 +02:00
# Update database
# This fonction relplace all old domain name by the new domain name.
# use : mysql_relpace_db db_name table collum
mysql_relpace_db() {
sql_request='UPDATE `'"$2"'` SET '"$3 = replace($3, '$old_domain', '$domain')"
2017-08-09 22:13:32 +02:00
ynh_mysql_execute_as_root "$sql_request" $1
}
# ccnet DB
mysql_relpace_db ccnetdb EmailUser email
mysql_relpace_db ccnetdb Group creator_name
mysql_relpace_db ccnetdb GroupUser user_name
mysql_relpace_db ccnetdb LDAPUsers email
mysql_relpace_db ccnetdb Organization creator
mysql_relpace_db ccnetdb OrgUser email
mysql_relpace_db ccnetdb UserRole email
# seafile DB
mysql_relpace_db seafiledb OrgUserQuota user
mysql_relpace_db seafiledb RepoGroup user_name
mysql_relpace_db seafiledb RepoOwner owner_id
mysql_relpace_db seafiledb RepoTrash owner_id
mysql_relpace_db seafiledb RepoUserToken email
mysql_relpace_db seafiledb SharedRepo from_email
mysql_relpace_db seafiledb SharedRepo to_email
mysql_relpace_db seafiledb UserQuota user
mysql_relpace_db seafiledb UserShareQuota user
# seahub DB
mysql_relpace_db seahubdb api2_token user
mysql_relpace_db seahubdb api2_tokenv2 user
mysql_relpace_db seahubdb avatar_avatar emailuser
mysql_relpace_db seahubdb base_clientlogintoken username
mysql_relpace_db seahubdb base_devicetoken user
mysql_relpace_db seahubdb base_filecomment author
mysql_relpace_db seahubdb base_innerpubmsg from_email
mysql_relpace_db seahubdb base_innerpubmsgreply from_email
mysql_relpace_db seahubdb base_userenabledmodule username
mysql_relpace_db seahubdb base_userlastlogin username
mysql_relpace_db seahubdb base_userstarredfiles email
mysql_relpace_db seahubdb group_groupmessage from_email
mysql_relpace_db seahubdb group_messagereply from_email
mysql_relpace_db seahubdb institutions_institutionadmin user
mysql_relpace_db seahubdb notifications_usernotification to_user
mysql_relpace_db seahubdb options_useroptions email
mysql_relpace_db seahubdb post_office_attachment_emails email_id
mysql_relpace_db seahubdb post_office_email from_email
mysql_relpace_db seahubdb profile_profile user
mysql_relpace_db seahubdb profile_profile login_id
mysql_relpace_db seahubdb profile_profile contact_email
mysql_relpace_db seahubdb registration_registrationprofile emailuser_id
mysql_relpace_db seahubdb share_anonymousshare repo_owner
mysql_relpace_db seahubdb share_fileshare username
mysql_relpace_db seahubdb share_privatefiledirshare from_user
mysql_relpace_db seahubdb share_privatefiledirshare to_user
mysql_relpace_db seahubdb share_uploadlinkshare username
mysql_relpace_db seahubdb sysadmin_extra_userloginlog username
mysql_relpace_db seahubdb termsandconditions_usertermsandconditions username
mysql_relpace_db seahubdb two_factor_phonedevice user
mysql_relpace_db seahubdb two_factor_staticdevice user
mysql_relpace_db seahubdb two_factor_totpdevice user
mysql_relpace_db seahubdb wiki_personalwiki username
2018-05-21 21:30:31 +02:00
# Avoid the current effect
sleep 1
2017-08-09 22:13:32 +02:00
# Reload services
sudo systemctl reload nginx.service
2018-05-25 22:12:51 +02:00
ynh_system_reload seafile-server start