mirror of
https://github.com/YunoHost-Apps/seafile_ynh.git
synced 2024-09-03 20:26:01 +02:00
200 lines
7.5 KiB
Bash
200 lines
7.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
|
|
# Source YunoHost helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# Stop script if errors
|
|
ynh_abort_if_errors
|
|
|
|
# Import common cmd
|
|
source scripts/experimental_helper.sh
|
|
source scripts/_common.sh
|
|
|
|
ynh_print_info --message="Loading installation settings..."
|
|
|
|
# Retrive arguments
|
|
domain=$(ynh_app_setting_get --app $app --key domain)
|
|
|
|
#=================================================
|
|
# FUNCTION DECLARATION
|
|
#=================================================
|
|
|
|
stop_seafile() {
|
|
ynh_print_info --message="Stoping seafile..."
|
|
|
|
# Stop service before any change
|
|
ynh_systemd_action --service_name seafile --action stop
|
|
ynh_systemd_action --service_name seahub --action stop
|
|
sleep 2
|
|
pkill -f seafile-controller || true
|
|
pkill -f seaf-server || true
|
|
pkill -f ccnet-server || true
|
|
pkill -f seahub || true
|
|
}
|
|
|
|
start_seafile(){
|
|
ynh_print_info --message="Starting seafile..."
|
|
# Avoid the current effect
|
|
sleep 2
|
|
|
|
# Reload services
|
|
ynh_print_info --message="Starting services..."
|
|
ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
|
|
ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd"
|
|
sleep 2
|
|
}
|
|
|
|
get_email_list_in_seafile() {
|
|
sql_request='SELECT email FROM `EmailUser`; SELECT email FROM `LDAPUsers`'
|
|
all_user_list=$(ynh_mysql_execute_as_root --sql "$sql_request" --database ccnetdb | grep -v "^email$")
|
|
user_list=$(echo "$all_user_list" | grep "@$domain$" || true)
|
|
}
|
|
|
|
migrate_email_in_database() {
|
|
|
|
ynh_print_info --message="Migrating email $1 to $2"
|
|
local old_email=$1
|
|
local new_email=$2
|
|
sleep 1
|
|
|
|
if [[ "$all_user_list" =~ "$new_email" ]]; then
|
|
ynh_print_err --message "The user '$new_email' already exist in seafile, can rename '$old_email' to '$new_email'"
|
|
return
|
|
fi
|
|
|
|
if ! [[ "$all_user_list" =~ "$old_email" ]]; then
|
|
ynh_print_err --message "The user '$old_email' don't exist in seafile, can rename '$old_email' to '$new_email'"
|
|
return
|
|
fi
|
|
|
|
# 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_email', '$new_email')"
|
|
ynh_mysql_execute_as_root --sql "$sql_request" --database $1
|
|
}
|
|
|
|
# TODO check DB update
|
|
# ccnet DB
|
|
mysql_relpace_db ccnetdb Binding email
|
|
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
|
|
# Note that when we do a migration from seafile v6 some time don't exist. So yes it's probably a bug on seafile side. But anyway just ignore this problem...
|
|
mysql_relpace_db seafiledb FolderUserPerm user || true
|
|
mysql_relpace_db seafiledb OrgGroupRepo owner || true
|
|
mysql_relpace_db seafiledb OrgRepo user || true
|
|
mysql_relpace_db seafiledb OrgSharedRepo from_email || true
|
|
mysql_relpace_db seafiledb OrgSharedRepo to_email || true
|
|
mysql_relpace_db seafiledb OrgUserQuota user
|
|
mysql_relpace_db seafiledb RepoGroup user_name
|
|
mysql_relpace_db seafiledb RepoInfo last_modifier
|
|
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 auth_user email
|
|
mysql_relpace_db seahubdb auth_user username
|
|
mysql_relpace_db seahubdb auth_user_groups user_id
|
|
mysql_relpace_db seahubdb auth_user_user_permissions user_id
|
|
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 django_cas_ng_proxygrantingticket user || true
|
|
mysql_relpace_db seahubdb drafts_draft username
|
|
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 role_permissions_adminrole email
|
|
mysql_relpace_db seahubdb share_anonymousshare repo_owner
|
|
mysql_relpace_db seahubdb share_extrasharepermission share_to
|
|
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 social_auth_code email || true
|
|
mysql_relpace_db seahubdb social_auth_usersocialauth username
|
|
mysql_relpace_db seahubdb sysadmin_extra_userloginlog username
|
|
mysql_relpace_db seahubdb tags_filetag 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
|
|
mysql_relpace_db seahubdb wiki_wiki username
|
|
|
|
ynh_print_info --message="Migration of email $1 to $2 done"
|
|
}
|
|
|
|
migrate_user() {
|
|
stop_seafile
|
|
get_email_list_in_seafile
|
|
|
|
migrate_email_in_database $YNH_ACTION_OLD_EMAIL $YNH_ACTION_NEW_EMAIL
|
|
|
|
start_seafile
|
|
}
|
|
|
|
migrate_all_user() {
|
|
stop_seafile
|
|
get_email_list_in_seafile
|
|
|
|
for user in $user_list; do
|
|
# Try to get the main email of the user in yunohost which has is the old email
|
|
user_main_email=$(yunohost tools shell -c "
|
|
from yunohost.user import user_info
|
|
info = user_info('$user'.split('@')[0])
|
|
print(info['mail'])
|
|
exit()
|
|
")
|
|
if [ "$user" == "$user_main_email" ]; then
|
|
ynh_print_info --message "Nothing to do for user $user."
|
|
fi
|
|
|
|
migrate_email_in_database $user $user_main_email
|
|
done
|
|
|
|
start_seafile
|
|
}
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
|
|
case $YNH_ACTION in
|
|
migrate_user_email_to_mail_email) migrate_all_user;;
|
|
change_user_email) migrate_user;;
|
|
esac
|