From 4d349f0090afd11c79a36935c75b9cac21771b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Wed, 27 Sep 2023 23:04:06 +0200 Subject: [PATCH] Fix issues --- actions.json | 11 +--------- conf/ccnet.conf | 1 + scripts/_common.sh | 1 - scripts/actions | 53 +++++++++++++--------------------------------- scripts/change_url | 8 +++++++ scripts/restore | 2 +- scripts/upgrade | 25 +++++++++++++++++++--- 7 files changed, 48 insertions(+), 53 deletions(-) diff --git a/actions.json b/actions.json index 803b1eb..61b96cc 100644 --- a/actions.json +++ b/actions.json @@ -1,13 +1,4 @@ -[{ - "id": "migrate_user_email_to_mail_email", - "name": "Migrate all user email with seafile domain to main user email", - "command": "bash scripts/actions", - "user": "root", - "accepted_return_codes": [0], - "description": { - "en": "Hight level function : Change automatically the email for the user authentication to a the main user email. This function should be run when you migrate from seafile 6 to seafile 7.\nBy example 'toto@seafile-domain.tld' will be renamed to the new email 'toto-main-email@main-yunohost-domain.tld'. Note that when do you this change the email need to be also changed in all client !!" - } -}, +[ { "id": "change_user_email", "name": "Change user email of user", diff --git a/conf/ccnet.conf b/conf/ccnet.conf index 1858d12..a26426a 100644 --- a/conf/ccnet.conf +++ b/conf/ccnet.conf @@ -1,4 +1,5 @@ [General] +SERVICE_URL = https://__DOMAIN____PATH__ [Database] ENGINE = mysql diff --git a/scripts/_common.sh b/scripts/_common.sh index 671f331..9a3d4cd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -2,7 +2,6 @@ # SET ALL CONSTANTS #================================================= -db_user=seafile time_zone=$(cat /etc/timezone) #================================================= diff --git a/scripts/actions b/scripts/actions index 69b5a4e..d52863d 100644 --- a/scripts/actions +++ b/scripts/actions @@ -93,21 +93,21 @@ migrate_email_in_database() { # 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 + mysql_relpace_db $db_name FolderUserPerm user || true + mysql_relpace_db $db_name OrgGroupRepo owner || true + mysql_relpace_db $db_name OrgRepo user || true + mysql_relpace_db $db_name OrgSharedRepo from_email || true + mysql_relpace_db $db_name OrgSharedRepo to_email || true + mysql_relpace_db $db_name OrgUserQuota user + mysql_relpace_db $db_name RepoGroup user_name + mysql_relpace_db $db_name RepoInfo last_modifier + mysql_relpace_db $db_name RepoOwner owner_id + mysql_relpace_db $db_name RepoTrash owner_id + mysql_relpace_db $db_name RepoUserToken email + mysql_relpace_db $db_name SharedRepo from_email + mysql_relpace_db $db_name SharedRepo to_email + mysql_relpace_db $db_name UserQuota user + mysql_relpace_db $db_name UserShareQuota user # seahub DB mysql_relpace_db seahubdb api2_token user @@ -168,33 +168,10 @@ migrate_user() { 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 diff --git a/scripts/change_url b/scripts/change_url index c29231e..cef7cfd 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -18,6 +18,14 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_change_url_nginx_config +# Create special path with / at the end +if [[ $path == '/' ]] +then + path2=$path +else + path2=$path"/" +fi + #================================================= # SPECIFIC MODIFICATIONS #================================================= diff --git a/scripts/restore b/scripts/restore index f5b4385..10e4142 100644 --- a/scripts/restore +++ b/scripts/restore @@ -32,8 +32,8 @@ ynh_script_progression --message="Restoring database..." --weight=3 db_helper=ynh_"mysql"_setup_db $db_helper --db_user $db_user --db_name ccnetdb --db_pwd "$db_pwd" $db_helper --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd" +su -c "mysql -u ${app} -p$db_pwd $db_name < ${YNH_CWD}/seafiledb.dmp" su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${YNH_CWD}/ccnetdb.dmp" -su -c "mysql -u ${app} -p$db_pwd seafiledb < ${YNH_CWD}/seafiledb.dmp" su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 39a2f6b..6a70726 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,14 @@ source /usr/share/yunohost/helpers installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/} seafile_version=$(ynh_app_upstream_version) +# Create special path with / at the end +if [[ $path == '/' ]] +then + path2=$path +else + path2=$path"/" +fi + if [ "$YNH_APP_CURRENT_VERSION" == '-' ]; then ynh_die "Upgrade from this version not supported" fi @@ -39,10 +47,21 @@ pkill -f seaf-server || true pkill -f ccnet-server || true pkill -f seahub || true -# Migrate DB if needed +# Migrate DB name if needed if mysqlshow | grep -q seafiledb; then - ynh_mysql_execute_as_root --sql 'DROP DATABASE `'$db_name'`' - ynh_mysql_execute_as_root --sql 'RENAME DATABASE `seafiledb TO "'$db_name'"' + mysqlconn="mysql -u root" + sql_mv_params=$($mysqlconn -N -e "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES \ + WHERE table_schema='seafiledb'") + for name in $sql_mv_params; do + $mysqlconn -e "RENAME TABLE seafiledb.$name to $db_name.$name"; + done; + $mysqlconn -e "DROP DATABASE seafiledb" +fi + +# Set missing settings +if [ -z ${seahub_secret_key:-} ]; then + seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2) + ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key fi ynh_script_progression --message="Upgrading source files..." --weight=6