From fd287c9ea4bda7cb51c312fc763fce2152c0121c Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 02:59:12 +0200 Subject: [PATCH 01/10] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 1 + manifest.toml | 4 ++- scripts/_common.sh | 9 +++--- scripts/backup | 31 +++++++++--------- scripts/change_url | 30 ++++++++--------- scripts/install | 78 +++++++++++++++++++++----------------------- scripts/remove | 35 ++++++++++---------- scripts/restore | 33 +++++++++---------- scripts/upgrade | 81 ++++++++++++++++++++++------------------------ 9 files changed, 148 insertions(+), 154 deletions(-) diff --git a/.gitignore b/.gitignore index 3ed2386..09e69f3 100644 --- a/.gitignore +++ b/.gitignore @@ -221,3 +221,4 @@ pip-log.txt *-swp auto_update_config.sh +*.sw[op] diff --git a/manifest.toml b/manifest.toml index 482853d..0dc33d2 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,8 @@ code = "https://github.com/haiwen/seafile-server" cpe = "cpe:2.3:a:seafile:seafile" [integration] -yunohost = ">= 11.2.13" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = ["amd64", "arm64"] multi_instance = false ldap = true @@ -65,6 +66,7 @@ ram.runtime = "500M" home = "/opt/yunohost/__APP__" [resources.install_dir] + group = "www-data:r-x" dir = "/opt/yunohost/__APP__" owner = "__APP__:rwx" group = "www-data:rx" diff --git a/scripts/_common.sh b/scripts/_common.sh index f65469b..0474e61 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -31,7 +31,7 @@ fi #================================================= run_seafile_cmd() { - ynh_exec_warn_less systemd-run --wait --uid="$app" --gid="$app" \ + ynh_hide_warnings systemd-run --wait --uid="$app" --gid="$app" \ --property=RootDirectory="$install_dir"/seafile_image \ --property="BindPaths=$systemd_seafile_bind_mount" \ $@ @@ -76,14 +76,15 @@ set_permission() { clean_url_in_db_config() { sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "SERVICE_URL"' - ynh_mysql_execute_as_root --sql="$sql_request" --database=seahubdb + ynh_mysql_db_shell <<< "$sql_request" --database=seahubdb sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"' - ynh_mysql_execute_as_root --sql="$sql_request" --database=seahubdb + ynh_mysql_db_shell <<< "$sql_request" --database=seahubdb } ensure_vars_set() { +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=jwt_private_key_notification_server --value=$(ynh_string_random -l 32) if [ -z "${jwt_private_key_notification_server:-}" ]; then jwt_private_key_notification_server=$(ynh_string_random -l 32) - ynh_app_setting_set --app="$app" --key=jwt_private_key_notification_server --value="$jwt_private_key_notification_server" + ynh_app_setting_set --key=jwt_private_key_notification_server --value="$jwt_private_key_notification_server" fi } diff --git a/scripts/backup b/scripts/backup index c5d9791..dee25a2 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,7 @@ seafile_version=$(ynh_app_upstream_version) seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" if systemctl is-active seafile --quiet || systemctl is-active seahub --quiet; then - ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'" + ynh_print_warn "It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'" fi #================================================= @@ -23,24 +23,25 @@ fi #================================================= # # Backup app files -ynh_print_info --message="Backing up code..." -ynh_backup --src_path="$install_dir" -ynh_print_info --message="Backing up user data..." -ynh_backup --src_path="$data_dir" --dest_path="data" --is_big=1 -ynh_print_info --message="Backing up configuration..." -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/${app}.conf" -ynh_backup --src_path=/etc/systemd/system/seafile.service -ynh_backup --src_path=/etc/systemd/system/seahub.service -ynh_backup --src_path=/etc/fail2ban/jail.d/"$app".conf -ynh_backup --src_path=/etc/fail2ban/filter.d/"$app".conf +ynh_print_info "Backing up code..." +ynh_backup "$install_dir" +ynh_print_info "Backing up user data..." +ynh_backup "$data_dir" --dest_path="data" + +ynh_print_info "Backing up configuration..." +ynh_backup "/etc/nginx/conf.d/$domain.d/${app}.conf" +ynh_backup /etc/systemd/system/seafile.service +ynh_backup /etc/systemd/system/seahub.service +ynh_backup /etc/fail2ban/jail.d/"$app".conf +ynh_backup /etc/fail2ban/filter.d/"$app".conf # Backup logs -ynh_backup --src_path="/var/log/$app" +ynh_backup "/var/log/$app" # Backup mysql -ynh_print_info --message="Backing up database" -ynh_mysql_dump_db --database="$db_name" > "${YNH_CWD}"/seafiledb.dmp +ynh_print_info "Backing up database" +ynh_mysql_dump_db > "${YNH_CWD}"/seafiledb.dmp ynh_mysql_dump_db --database=ccnetdb > "${YNH_CWD}"/ccnetdb.dmp ynh_mysql_dump_db --database=seahubdb > "${YNH_CWD}"/seahubdb.dmp -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index cdbb140..3d1bb1b 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -14,35 +14,33 @@ source /usr/share/yunohost/helpers seafile_version="$(ynh_app_upstream_version)" seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" -#================================================= -# STANDARD MODIFICATIONS #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -ynh_change_url_nginx_config +ynh_script_progression "Updating NGINX web server configuration..." +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS #================================================= -ynh_script_progression --message="Stoping services..." +ynh_script_progression "Stoping services..." # Stop service before any change -ynh_systemd_action --service_name=seafile --action=stop -ynh_systemd_action --service_name=seahub --action=stop +ynh_systemctl --service=seafile --action=stop +ynh_systemctl --service=seahub --action=stop sleep 2 pkill -f seafile-controller || true pkill -f seaf-server || true pkill -f ccnet-server || true pkill -f seahub || true -ynh_script_progression --message="Updating seafile configuration..." +ynh_script_progression "Updating seafile configuration..." # Update Seafile Config -ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py -ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf -ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py -ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf +ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py +ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf +ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py +ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf # Update permissions ynh_permission_url --permission=file_server --url="$domain"/seafhttp @@ -55,9 +53,9 @@ clean_url_in_db_config sleep 2 # Reload services -ynh_script_progression --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" +ynh_script_progression "Starting services..." +ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" sleep 2 -ynh_script_progression --message="Change of URL completed for $app" --time=--last +ynh_script_progression "Change of URL completed for $app" --time= diff --git a/scripts/install b/scripts/install index b883257..57a7176 100644 --- a/scripts/install +++ b/scripts/install @@ -17,11 +17,9 @@ seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_ver ensure_vars_set -#================================================= -# STANDARD MODIFICATIONS #================================================= -ynh_script_progression --message="Creating base directory..." +ynh_script_progression "Creating base directory..." if [ -n "$(ls -A "$data_dir")" ]; then old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')" @@ -35,25 +33,25 @@ mkdir -p "$data_dir"/{seafile-data,seahub-data} mkdir -p "$install_dir"/{conf,ccnet} # Download new version from sources -ynh_script_progression --message="Installing sources files..." --weight=7 +ynh_script_progression "Installing sources files..." install_source # init databases -ynh_script_progression --message="Configuring MySQL database..." +ynh_script_progression "Configuring MySQL database..." db_user=seafile ynh_''mysql_setup_db --db_user="$db_user" --db_name=ccnetdb --db_pwd="$db_pwd" ynh_''mysql_setup_db --db_user="$db_user" --db_name=seahubdb --db_pwd="$db_pwd" -ynh_script_progression --message="Configuring application..." --weight=3 +ynh_script_progression "Configuring application..." # Run install script set_permission -ynh_replace_special_string --match_string='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \ - --replace_string='seafile_config.seafile_dir = seafile_dir' \ - --target_file="$seafile_code/setup-seafile-mysql.py" -ynh_replace_special_string --match_string="Utils.error('Ccnet config dir \\\"%s\\\" already exists.' % ccnet_config.ccnet_dir)" \ - --replace_string='patched = 1' \ - --target_file="$seafile_code/setup-seafile-mysql.py" +ynh_replace_regex --match='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \ + --replace='seafile_config.seafile_dir = seafile_dir' \ + --file="$seafile_code/setup-seafile-mysql.py" +ynh_replace_regex --match="Utils.error('Ccnet config dir \\\"%s\\\" already exists.' % ccnet_config.ccnet_dir)" \ + --replace='patched = 1' \ + --file="$seafile_code/setup-seafile-mysql.py" run_seafile_cmd bash "/opt/seafile/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \ --server-name "$server_name" \ --server-ip "$domain" \ @@ -69,79 +67,77 @@ run_seafile_cmd bash "/opt/seafile/seafile-server-$seafile_version/setup-seafile # Retrive values from auto generated config file 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" +ynh_app_setting_set --key=seahub_secret_key --value="$seahub_secret_key" # Update seafile config files -ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py -ynh_add_config --template=seafile.conf --destination="$install_dir"/conf/seafile.conf -ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf -ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py -ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf -ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf +ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py +ynh_config_add --template=seafile.conf --destination="$install_dir"/conf/seafile.conf +ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf +ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py +ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf +ynh_config_add --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf # Configure admin info # It will be used the first start admin_email=$(ynh_user_get_info --username="$admin" --key='mail') cp ../conf/create_admin.json $install_dir/conf/admin.txt -ynh_replace_string --match_string=__ADMIN__ --replace_string="$admin_email" --target_file=$install_dir/conf/admin.txt -ynh_replace_special_string --match_string=__PASSWORD__ --replace_string="$admin_password" --target_file=$install_dir/conf/admin.txt +ynh_replace --match=__ADMIN__ --replace="$admin_email" --file=$install_dir/conf/admin.txt +ynh_replace_regex --match=__PASSWORD__ --replace="$admin_password" --file=$install_dir/conf/admin.txt # Use symlink to store data if [ -e "$install_dir"/seafile-data ]; then mv -t "$data_dir"/seafile-data "$install_dir"/seafile-data/* - ynh_secure_remove --file="$install_dir"/seafile-data + ynh_safe_rm "$install_dir"/seafile-data fi if [ -e "$install_dir"/seahub-data ]; then mv -t "$data_dir"/seahub-data "$install_dir"/seahub-data/* - ynh_secure_remove --file="$install_dir"/seahub-data + ynh_safe_rm "$install_dir"/seahub-data fi if [ -e "$install_dir"/logs ]; then mv -t /var/log/"$app" "$install_dir"/logs/* - ynh_secure_remove --file="$install_dir"/logs + ynh_safe_rm "$install_dir"/logs fi ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data ln -s /var/log/"$app" "$install_dir"/logs # Fix local warning -ynh_replace_string --match_string=en_US.UTF-8 --replace_string="${LANG:-'en_US.UTF-8'}" --target_file="$seafile_code/seahub.sh" +ynh_replace --match=en_US.UTF-8 --replace="${LANG:-'en_US.UTF-8'}" --file="$seafile_code/seahub.sh" # Add Seafile Server to startup -ynh_script_progression --message="Configuring a systemd service..." -ynh_add_systemd_config --service=seafile --template=seafile.service -ynh_add_systemd_config --service=seahub --template=seahub.service +ynh_script_progression "Configuring $app's systemd service..." +ynh_config_add_systemd --service=seafile --template=seafile.service +ynh_config_add_systemd --service=seahub --template=seahub.service # register yunohost service yunohost service add seafile --description 'Main service for seafile server.' yunohost service add seahub --description 'Seafile server web interface.' # Config nginx -ynh_script_progression --message="Configuring nginx..." -ynh_add_nginx_config +ynh_script_progression "Configuring nginx..." +ynh_config_add_nginx # Add logrotate -ynh_script_progression --message="Configuring log rotation..." -ynh_use_logrotate --logfile=/var/log/"$app" +ynh_script_progression "Configuring log rotation..." +ynh_config_add_logrotate /var/log/"$app" # Add fail2ban -ynh_script_progression --message="Configuring fail2ban..." -ynh_add_fail2ban_config --use_template +ynh_script_progression "Configuring fail2ban..." +ynh_config_add_fail2ban -#================================================= -# GENERIC FINALIZATION #================================================= # Set all permissions -ynh_script_progression --message="Protecting directory..." +ynh_script_progression "Protecting directory..." set_permission # Start service sleep 3 -ynh_script_progression --message="Starting seafile services..." -ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_script_progression "Starting seafile services..." +ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log sleep 2 -ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd" +ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" sleep 2 -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index dd8fbd5..b2bff19 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,11 +18,11 @@ seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_ver # STANDARD REMOVE #================================================= -ynh_script_progression --message="Stoping services..." +ynh_script_progression "Stoping services..." # Stop all services -ynh_systemd_action --service_name=seafile --action=stop -ynh_systemd_action --service_name=seahub --action=stop +ynh_systemctl --service=seafile --action=stop +ynh_systemctl --service=seahub --action=stop # Force to kill all process in case of a process is not stoped cleanly pkill -f seafile-controller || true @@ -30,35 +30,36 @@ pkill -f seaf-server || true pkill -f ccnet-server || true pkill -f seahub || true -ynh_script_progression --message="Removing code..." -ynh_secure_remove --file=/var/www/"$app" -ynh_secure_remove --file=/opt/yunohost/"$app" +ynh_script_progression "Removing code..." +ynh_safe_rm /var/www/"$app" +ynh_safe_rm /opt/yunohost/"$app" # Remove databases -ynh_script_progression --message="Removing databases..." +ynh_script_progression "Removing databases..." db_helper=ynh_"mysql"_remove_db $db_helper --db_name ccnetdb --db_user seafile $db_helper --db_name seahubdb --db_user seafile # Remove systemd service -ynh_script_progression --message="Removing systemd units..." -ynh_remove_systemd_config --service=seafile -ynh_remove_systemd_config --service=seahub +ynh_script_progression "Removing systemd units..." +ynh_config_remove_systemdseafile +ynh_config_remove_systemdseahub # Remove nginx config -ynh_script_progression --message="Removing nginx configuration..." -ynh_remove_nginx_config +ynh_script_progression "Removing nginx configuration..." +ynh_config_remove_nginx # Remove logrotate -ynh_remove_logrotate +ynh_config_remove_logrotate # Remove the dedicated fail2ban config -ynh_script_progression --message="Removing fail2ban configuration..." -ynh_remove_fail2ban_config +ynh_script_progression "Removing fail2ban configuration..." +ynh_config_remove_fail2ban -ynh_script_progression --message="Removing seafile service..." +ynh_script_progression "Removing seafile service..." yunohost service remove seafile yunohost service remove seahub -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" + sleep 1 diff --git a/scripts/restore b/scripts/restore index 95587b1..4e63a89 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,18 +14,17 @@ source /usr/share/yunohost/helpers seafile_version="$(ynh_app_upstream_version)" seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" -ynh_script_progression --message="Loading settings..." +ynh_script_progression "Loading settings..." #================================================= # STANDARD RESTORATION STEPS #================================================= # Restore all config and data -ynh_script_progression --message="Restoring files..." --weight=10 -ynh_restore - +ynh_script_progression "Restoring files..." +ynh_restore_everything # Restore mysql dump -ynh_script_progression --message="Restoring database..." --weight=3 +ynh_script_progression "Restoring database..." 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" @@ -33,45 +32,43 @@ 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 seahubdb < ${YNH_CWD}/seahubdb.dmp" -#================================================= -# GENERIC FINALIZATION #================================================= # Add logrotate -ynh_script_progression --message="Configuring log rotation..." +ynh_script_progression "Configuring log rotation..." mkdir -p /var/log/"$app" -ynh_use_logrotate --logfile="$install_dir"/logs +ynh_config_add_logrotate "$install_dir"/logs # Set all permissions -ynh_script_progression --message="Protecting directory..." +ynh_script_progression "Protecting directory..." set_permission # Enable service and start seafile -ynh_script_progression --message="Reconfiguring application..." +ynh_script_progression "Reconfiguring application..." systemctl daemon-reload systemctl enable seafile --quiet systemctl enable seahub --quiet # Add Seafile to YunoHost's monitored services -ynh_script_progression --message="Register seafile service..." +ynh_script_progression "Register seafile service..." yunohost service add seafile --description 'Main service for seafile server.' yunohost service add seahub --description 'Seafile server web interface.' -ynh_script_progression --message="Reloading services..." +ynh_script_progression "Reloading services..." # Reload nginx systemctl reload nginx.service # Reload fail2ban -ynh_systemd_action --service_name=fail2ban --action=reload +ynh_systemctl --service=fail2ban --action=reload # Avoid the current effect sleep 5 # Restart service -ynh_script_progression --message="Starting seafile services..." --weight=3 -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" +ynh_script_progression "Starting seafile services..." +ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" sleep 2 -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 4b037bd..102c636 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,10 +23,10 @@ if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version ynh_die "Upgrade from this version not supported" fi -ynh_script_progression --message="Stoping services..." +ynh_script_progression "Stoping services..." -ynh_systemd_action --service_name=seafile --action=stop -ynh_systemd_action --service_name=seahub --action=stop +ynh_systemctl --service=seafile --action=stop +ynh_systemctl --service=seahub --action=stop sleep 5 pkill -f seafile-controller || true pkill -f seaf-server || true @@ -42,14 +42,15 @@ if mysqlshow | grep -q seafiledb; then $mysqlconn -e "RENAME TABLE seafiledb.$name to $db_name.$name"; done; $mysqlconn -e "DROP DATABASE seafiledb" - ynh_replace_string --match_string='db_name = seafiledb' --replace_string='db_name = seafile' --target_file="$install_dir"/conf/seafile.conf + ynh_replace --match='db_name = seafiledb' --replace='db_name = seafile' --file="$install_dir"/conf/seafile.conf sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" "$install_dir"/conf/seafile.conf fi # Set missing settings +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=seahub_secret_key --value="$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)" 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" + ynh_app_setting_set --key=seahub_secret_key --value="$seahub_secret_key" fi # @@ -97,15 +98,15 @@ if [ ! -L "$install_dir"/logs ]; then ln -s /var/log/"${app}" "$install_dir"/logs fi -ynh_script_progression --message="Upgrading source files..." --weight=6 +ynh_script_progression "Upgrading source files..." # Download new version from sources -ynh_script_progression --message="Installing sources files..." --weight=7 +ynh_script_progression "Installing sources files..." if [ "$YNH_APP_UPGRADE_TYPE" == UPGRADE_APP ]; then install_source fi -ynh_script_progression --message="Configuring application..." +ynh_script_progression "Configuring application..." # permission to execute update script and expect helper set_permission @@ -128,7 +129,7 @@ case "$installed_version" in run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/seahub.sh" python-env python3 "/opt/seafile/seafile-server-$seafile_version/seahub/manage.py" migrate_file_comment # Update seafile by script - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_7.0_7.1.sh" + ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_7.0_7.1.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh" # Fix seafile data link. Look like that the upgrade script of seafile don't always work correctly @@ -139,90 +140,86 @@ case "$installed_version" in ln -s "$data_dir" "$install_dir"/seafile-data ;& "7.1."* ) - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_8.0_9.0.sh" + ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_8.0_9.0.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" ;& "8.0."* ) - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_7.1_8.0.sh" + ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_7.1_8.0.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh" ;& "9."* ) - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_8.0_9.0.sh" + ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_8.0_9.0.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" ;& "10."* ) - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_9.0_10.0.sh" + ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_9.0_10.0.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/seahub.sh" python-env python3 "/opt/seafile/seafile-server-$seafile_version/migrate_ldapusers.py" ;& esac -ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/minor-upgrade.sh" +ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/minor-upgrade.sh" run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/minor-upgrade.sh" # Clean url in config in DB clean_url_in_db_config # Update seafile config files -ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py -ynh_add_config --template=seafile.conf --destination="$install_dir"/conf/seafile.conf -ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf -ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py -ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf -ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf +ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py +ynh_config_add --template=seafile.conf --destination="$install_dir"/conf/seafile.conf +ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf +ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py +ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf +ynh_config_add --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf # Fix local warning -ynh_replace_string --match_string=en_US.UTF-8 --replace_string="${LANG:-'en_US.UTF-8'}" --target_file="$seafile_code/seahub.sh" +ynh_replace --match=en_US.UTF-8 --replace="${LANG:-'en_US.UTF-8'}" --file="$seafile_code/seahub.sh" -#================================================= -# STANDARD UPGRADE STEPS #================================================= # Config nginx -ynh_add_nginx_config 'seahub_port fileserver_port webdav_port' +ynh_config_add_nginx 'seahub_port fileserver_port webdav_port' # Add Seafile Server to startup -ynh_script_progression --message="Updating systemd units..." -ynh_add_systemd_config --service=seafile --template=seafile.service -ynh_add_systemd_config --service=seahub --template=seahub.service +ynh_script_progression "Updating systemd units..." +ynh_config_add_systemd --service=seafile --template=seafile.service +ynh_config_add_systemd --service=seahub --template=seahub.service -#================================================= -# GENERIC FINALIZATION #================================================= # Set all permissions -ynh_script_progression --message="Protecting directory..." +ynh_script_progression "Protecting directory..." set_permission # Add logrotate -ynh_script_progression --message="Configuring log rotation..." -ynh_use_logrotate --logfile=/var/log/"$app" --nonappend +ynh_script_progression "Configuring log rotation..." +ynh_config_add_logrotate /var/log/"$app" # Add fail2ban -ynh_script_progression --message="Configuring fail2ban..." --weight=10 -ynh_add_fail2ban_config --use_template +ynh_script_progression "Configuring fail2ban..." +ynh_config_add_fail2ban # register yunohost service -ynh_script_progression --message="Register seafile service..." +ynh_script_progression "Register seafile service..." yunohost service add seafile --description 'Main service for seafile server.' yunohost service add seahub --description 'Seafile server web interface.' # delete seafile cache # restart seafile server -ynh_script_progression --message="Starting seafile services..." --weight=3 +ynh_script_progression "Starting seafile services..." sleep 5 -ynh_systemd_action --service_name=memcached.service -p "systemd" -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" +ynh_systemctl --service=memcached.service -p "systemd" +ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" sleep 2 # remove old version files -ynh_script_progression --message="Cleaning system and updating settings..." +ynh_script_progression "Cleaning system and updating settings..." for f in "$install_dir"/seafile-server-*;do if [[ ! "$f" =~ ${seafile_version//./\\.}|latest ]]; then - ynh_secure_remove --file="$f" + ynh_safe_rm "$f" fi done -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed" From db0c65931e21e72058a43b6d1bcf0b55cf27e248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 31 Aug 2024 10:34:22 +0200 Subject: [PATCH 02/10] Cleanup after auto patch --- manifest.toml | 2 -- scripts/install | 6 +++--- scripts/upgrade | 6 +----- tests.toml | 1 + 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/manifest.toml b/manifest.toml index 0dc33d2..ef2aa79 100644 --- a/manifest.toml +++ b/manifest.toml @@ -63,11 +63,9 @@ ram.runtime = "500M" [resources] [resources.system_user] allow_email = true - home = "/opt/yunohost/__APP__" [resources.install_dir] group = "www-data:r-x" - dir = "/opt/yunohost/__APP__" owner = "__APP__:rwx" group = "www-data:rx" diff --git a/scripts/install b/scripts/install index 57a7176..603894b 100644 --- a/scripts/install +++ b/scripts/install @@ -80,9 +80,9 @@ ynh_config_add --template=seafevents.conf --destination="$install_dir"/conf/seaf # Configure admin info # It will be used the first start admin_email=$(ynh_user_get_info --username="$admin" --key='mail') -cp ../conf/create_admin.json $install_dir/conf/admin.txt -ynh_replace --match=__ADMIN__ --replace="$admin_email" --file=$install_dir/conf/admin.txt -ynh_replace_regex --match=__PASSWORD__ --replace="$admin_password" --file=$install_dir/conf/admin.txt +cp ../conf/create_admin.json "$install_dir"/conf/admin.txt +ynh_replace --match=__ADMIN__ --replace="$admin_email" --file="$install_dir"/conf/admin.txt +ynh_replace_regex --match=__PASSWORD__ --replace="$admin_password" --file="$install_dir"/conf/admin.txt # Use symlink to store data if [ -e "$install_dir"/seafile-data ]; then diff --git a/scripts/upgrade b/scripts/upgrade index 102c636..9915cbb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -47,11 +47,7 @@ if mysqlshow | grep -q seafiledb; then fi # Set missing settings -# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=seahub_secret_key --value="$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)" -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 --key=seahub_secret_key --value="$seahub_secret_key" -fi +ynh_app_setting_set_default --key=seahub_secret_key --value="$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)" # # Update data dir if needed diff --git a/tests.toml b/tests.toml index 88b42ba..fe49775 100644 --- a/tests.toml +++ b/tests.toml @@ -24,3 +24,4 @@ test_format = 1.0 test_upgrade_from.8d41482.name = "Version 7.1 (Old_version_for_CI_4 branch)" test_upgrade_from.c11c24b.name = "Version 8.x (Old_version_for_CI_5 branch)" test_upgrade_from.7a4d00a.name = "Version 9.x" + test_upgrade_from.5a4717a.name = "Before helper 2.1" From eb0b904011d2a182d51124b0ff70d6df0fa93745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 31 Aug 2024 10:52:21 +0200 Subject: [PATCH 03/10] Update helper setup source --- scripts/ynh_setup_source | 176 ++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 103 deletions(-) diff --git a/scripts/ynh_setup_source b/scripts/ynh_setup_source index 70a58f0..b845c5f 100644 --- a/scripts/ynh_setup_source +++ b/scripts/ynh_setup_source @@ -1,80 +1,62 @@ -# Download, check integrity, uncompress and patch the source from app.src +# Download, check integrity, uncompress and patch upstream sources # -# Requires YunoHost version 2.6.4 or higher. +# NOTE this is a full copy of upstream ynh_setup_source but with some specific patch releated to seafile docker archive ynh_setup_source_custom() { - # Declare an array to define the options of this helper. - local legacy_args=dsk - local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=) + # ============ Argument parsing ============= + local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace) local dest_dir local source_id local keep local full_replace - # Manage arguments with getopts ynh_handle_getopts_args "$@" keep="${keep:-}" full_replace="${full_replace:-0}" + source_id="${source_id:-main}" + # =========================================== - if test -e $YNH_APP_BASEDIR/manifest.toml && cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq -e '.resources.sources' >/dev/null + local sources_json=$(ynh_read_manifest "resources.sources[\"$source_id\"]") + if jq -re ".url" <<< "$sources_json" then - source_id="${source_id:-main}" - local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]") - if jq -re ".url" <<< "$sources_json" - then - local arch_prefix="" - else - local arch_prefix=".$YNH_ARCH" - fi - - local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')" - local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')" - local src_sumprg="sha256sum" - local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')" - local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')" - local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')" - local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')" - local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')" - - [[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?" - [[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?" - - if [[ -z "$src_format" ]] - then - if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]] - then - src_format="zip" - elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]] - then - src_format="tar.gz" - elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]] - then - src_format="tar.xz" - elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]] - then - src_format="tar.bz2" - elif [[ -z "$src_extract" ]] - then - src_extract="false" - fi - fi + local arch_prefix="" else - source_id="${source_id:-app}" - local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src" - - # Load value from configuration file (see above for a small doc about this file - # format) - local src_url=$(grep 'SOURCE_URL=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_sum=$(grep 'SOURCE_SUM=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_format=$(grep 'SOURCE_FORMAT=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_rename=$(grep 'SOURCE_FILENAME=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_extract=$(grep 'SOURCE_EXTRACT=' "$src_file_path" | cut --delimiter='=' --fields=2-) - local src_platform=$(grep 'SOURCE_PLATFORM=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local arch_prefix=".$YNH_ARCH" fi - # Default value - src_sumprg=${src_sumprg:-sha256sum} + local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')" + local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')" + local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')" + local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')" src_in_subdir=${src_in_subdir:-true} + local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')" + local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')" + local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')" + + [[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?" + [[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?" + + if [[ -z "$src_format" ]] + then + if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]] + then + src_format="zip" + elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]] + then + src_format="tar.gz" + elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]] + then + src_format="tar.xz" + elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]] + then + src_format="tar.bz2" + elif [[ "$src_url" =~ ^.*\.tar$ ]] + then + src_format="tar" + elif [[ -z "$src_extract" ]] + then + src_extract="false" + fi + fi + src_format=${src_format:-tar.gz} src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') src_extract=${src_extract:-true} @@ -84,10 +66,6 @@ ynh_setup_source_custom() { ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter" fi - - # (Unused?) mecanism where one can have the file in a special local cache to not have to download it... - local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${source_id}" - # Gotta use this trick with 'dirname' because source_id may contain slashes x_x mkdir -p $(dirname /var/cache/yunohost/download/${YNH_APP_ID}/${source_id}) src_filename="/var/cache/yunohost/download/${YNH_APP_ID}/${source_id}" @@ -100,14 +78,10 @@ ynh_setup_source_custom() { fi # END APP CUSTOMIZATION else - if test -e "$local_src"; then - cp $local_src $src_filename - fi - [ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?" # If the file was prefetched but somehow doesn't match the sum, rm and redownload it - if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status + if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | sha256sum --check --status then rm -f "$src_filename" fi @@ -121,16 +95,16 @@ ynh_setup_source_custom() { local out # Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget) out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$src_filename $src_url 2>&1) \ - || ynh_die --message="$out" + || ynh_die "$out" fi # Check the control sum - if ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status + if ! echo "${src_sum} ${src_filename}" | sha256sum --check --status then - local actual_sum="$(${src_sumprg} ${src_filename} | cut --delimiter=' ' --fields=1)" + local actual_sum="$(sha256sum ${src_filename} | cut --delimiter=' ' --fields=1)" local actual_size="$(du -hs ${src_filename} | cut --fields=1)" rm -f ${src_filename} - ynh_die --message="Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})." + ynh_die "Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})." fi fi @@ -150,19 +124,12 @@ ynh_setup_source_custom() { fi if [ "$full_replace" -eq 1 ]; then - ynh_secure_remove --file="$dest_dir" + ynh_safe_rm "$dest_dir" fi # Extract source into the app dir mkdir --parents "$dest_dir" - if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then - _ynh_apply_default_permissions $dest_dir - fi - if [ -n "${final_path:-}" ] && [ "$dest_dir" == "$final_path" ]; then - _ynh_apply_default_permissions $dest_dir - fi - if [[ "$src_extract" == "false" ]]; then if [[ -z "$src_rename" ]] then @@ -179,11 +146,11 @@ ynh_setup_source_custom() { local tmp_dir=$(mktemp --directory) unzip -quo $src_filename -d "$tmp_dir" cp --archive $tmp_dir/*/. "$dest_dir" - ynh_secure_remove --file="$tmp_dir" + ynh_safe_rm "$tmp_dir" else unzip -quo $src_filename -d "$dest_dir" fi - ynh_secure_remove --file="$src_filename" + ynh_safe_rm "$src_filename" else local strip="" if [ "$src_in_subdir" != "false" ]; then @@ -194,30 +161,29 @@ ynh_setup_source_custom() { fi strip="--strip-components $sub_dirs" fi - if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]; then + if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz|tar$ ]]; then tar --extract --file=$src_filename --directory="$dest_dir" $strip else - ynh_die --message="Archive format unrecognized." + ynh_die "Archive format unrecognized." fi - ynh_secure_remove --file="$src_filename" + ynh_safe_rm "$src_filename" fi # Apply patches - if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then - local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/) - if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2>/dev/null | wc --lines) > "0")); then - pushd "$dest_dir" - for p in $patches_folder/${source_id}-*.patch; do - echo $p - patch --strip=1 <$p || ynh_print_warn --message="Packagers /!\\ patch $p failed to apply" - done - popd - fi - fi - - # Add supplementary files - if test -e "$YNH_APP_BASEDIR/sources/extra_files/${source_id}"; then - cp --archive $YNH_APP_BASEDIR/sources/extra_files/$source_id/. "$dest_dir" + if [ -d "$YNH_APP_BASEDIR/patches/" ]; then + local patches_folder=$(realpath "$YNH_APP_BASEDIR/patches/$source_id") + pushd "$dest_dir" + for patchfile in "$patches_folder/"*.patch; do + echo "Applying $patchfile" + if ! patch --strip=1 < "$patchfile"; then + if ynh_in_ci_tests; then + ynh_die "Patch $patchfile failed to apply!" + else + ynh_print_warn "Warn your packagers /!\\ Patch $patchfile failed to apply" + fi + fi + done + popd fi # Keep files to be backup/restored at the end of the helper @@ -239,4 +205,8 @@ ynh_setup_source_custom() { done fi rm -rf /var/cache/yunohost/files_to_keep_during_setup_source/ + + if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then + _ynh_apply_default_permissions $dest_dir + fi } From 8f16c2abad0671f31eff23cc818b0010f87aef6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 31 Aug 2024 10:52:31 +0200 Subject: [PATCH 04/10] Cleanup --- scripts/_common.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 0474e61..eb2fd9f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -82,9 +82,5 @@ clean_url_in_db_config() { } ensure_vars_set() { -# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=jwt_private_key_notification_server --value=$(ynh_string_random -l 32) - if [ -z "${jwt_private_key_notification_server:-}" ]; then - jwt_private_key_notification_server=$(ynh_string_random -l 32) - ynh_app_setting_set --key=jwt_private_key_notification_server --value="$jwt_private_key_notification_server" - fi + ynh_app_setting_set_default --key=jwt_private_key_notification_server --value=$(ynh_string_random -l 32) } From dd048268113ecb849b7b9356e35da58e0e1f376d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 31 Aug 2024 11:28:05 +0200 Subject: [PATCH 05/10] Add warning about config edition --- conf/gunicorn.conf.py | 2 ++ conf/seafevents.conf | 2 ++ conf/seafile.conf | 2 ++ conf/seahub_settings.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/conf/gunicorn.conf.py b/conf/gunicorn.conf.py index 533a73e..bcbdb4c 100644 --- a/conf/gunicorn.conf.py +++ b/conf/gunicorn.conf.py @@ -1,3 +1,5 @@ +# WARNING: Don't edit this file. All change will be removed after each app upgrade + import os daemon = True diff --git a/conf/seafevents.conf b/conf/seafevents.conf index 8cfa634..484984f 100644 --- a/conf/seafevents.conf +++ b/conf/seafevents.conf @@ -1,3 +1,5 @@ +# WARNING: Don't edit this file. All change will be removed after each app upgrade + [DATABASE] type = mysql host = 127.0.0.1 diff --git a/conf/seafile.conf b/conf/seafile.conf index a684aa8..38730e5 100644 --- a/conf/seafile.conf +++ b/conf/seafile.conf @@ -1,3 +1,5 @@ +# WARNING: Don't edit this file. All change will be removed after each app upgrade + [fileserver] port = __PORT_FILESERVER__ diff --git a/conf/seahub_settings.py b/conf/seahub_settings.py index 4c72450..7f054a4 100644 --- a/conf/seahub_settings.py +++ b/conf/seahub_settings.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +# WARNING: Don't edit this file. All change will be removed after each app upgrade + SECRET_KEY = "{{ seahub_secret_key }}" DATABASES = { From 04a18bb6aac4fc32d58015718a3586976d65f77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 31 Aug 2024 19:05:25 +0200 Subject: [PATCH 06/10] Small fix --- scripts/remove | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/remove b/scripts/remove index b2bff19..2296407 100644 --- a/scripts/remove +++ b/scripts/remove @@ -42,8 +42,8 @@ $db_helper --db_name seahubdb --db_user seafile # Remove systemd service ynh_script_progression "Removing systemd units..." -ynh_config_remove_systemdseafile -ynh_config_remove_systemdseahub +ynh_config_remove_systemd seafile +ynh_config_remove_systemd seahub # Remove nginx config ynh_script_progression "Removing nginx configuration..." From 76f62483994d321470a902ce826b64d21044dbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 31 Aug 2024 19:26:31 +0200 Subject: [PATCH 07/10] fix duplicate key --- manifest.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index ef2aa79..52ef651 100644 --- a/manifest.toml +++ b/manifest.toml @@ -65,9 +65,8 @@ ram.runtime = "500M" allow_email = true [resources.install_dir] - group = "www-data:r-x" owner = "__APP__:rwx" - group = "www-data:rx" + group = "www-data:r-x" [resources.data_dir] dir = "/home/yunohost.app/__APP__" From 73fc252d8f3a6347d2c5e6899f8565fd247aed6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sun, 1 Sep 2024 23:13:06 +0200 Subject: [PATCH 08/10] Update requirement --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 52ef651..779ea70 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,7 @@ code = "https://github.com/haiwen/seafile-server" cpe = "cpe:2.3:a:seafile:seafile" [integration] -yunohost = ">= 11.2.18" +yunohost = ">= 11.2.30" helpers_version = "2.1" architectures = ["amd64", "arm64"] multi_instance = false From 9f50f2539e266d8f8136a0fbb38a134528489337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Mon, 2 Sep 2024 12:19:00 +0200 Subject: [PATCH 09/10] Fix helper call --- scripts/backup | 4 ++-- scripts/change_url | 5 +++-- scripts/install | 8 ++++---- scripts/remove | 5 ++--- scripts/restore | 10 +++++----- scripts/upgrade | 5 +++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/backup b/scripts/backup index dee25a2..c3a91c8 100644 --- a/scripts/backup +++ b/scripts/backup @@ -41,7 +41,7 @@ ynh_backup "/var/log/$app" # Backup mysql ynh_print_info "Backing up database" ynh_mysql_dump_db > "${YNH_CWD}"/seafiledb.dmp -ynh_mysql_dump_db --database=ccnetdb > "${YNH_CWD}"/ccnetdb.dmp -ynh_mysql_dump_db --database=seahubdb > "${YNH_CWD}"/seahubdb.dmp +ynh_mysql_dump_db ccnetdb > "${YNH_CWD}"/ccnetdb.dmp +ynh_mysql_dump_db seahubdb > "${YNH_CWD}"/seahubdb.dmp ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 3d1bb1b..58f847c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -54,8 +54,9 @@ sleep 2 # Reload services ynh_script_progression "Starting services..." -ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log -ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" +ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log +sleep 2 +ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd" sleep 2 ynh_script_progression "Change of URL completed for $app" --time= diff --git a/scripts/install b/scripts/install index 603894b..329ad01 100644 --- a/scripts/install +++ b/scripts/install @@ -39,8 +39,8 @@ install_source # init databases ynh_script_progression "Configuring MySQL database..." db_user=seafile -ynh_''mysql_setup_db --db_user="$db_user" --db_name=ccnetdb --db_pwd="$db_pwd" -ynh_''mysql_setup_db --db_user="$db_user" --db_name=seahubdb --db_pwd="$db_pwd" +ynh_''mysql_create_db ccnetdb "$db_user" "$db_pwd" +ynh_''mysql_create_db seahubdb "$db_user" "$db_pwd" ynh_script_progression "Configuring application..." @@ -135,9 +135,9 @@ set_permission sleep 3 ynh_script_progression "Starting seafile services..." -ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log sleep 2 -ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" +ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd" sleep 2 ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 2296407..6e25f86 100644 --- a/scripts/remove +++ b/scripts/remove @@ -36,9 +36,8 @@ ynh_safe_rm /opt/yunohost/"$app" # Remove databases ynh_script_progression "Removing databases..." -db_helper=ynh_"mysql"_remove_db -$db_helper --db_name ccnetdb --db_user seafile -$db_helper --db_name seahubdb --db_user seafile +ynh_''mysql_drop_db ccnetdb +ynh_''mysql_drop_db seahubdb # Remove systemd service ynh_script_progression "Removing systemd units..." diff --git a/scripts/restore b/scripts/restore index 4e63a89..6a780ea 100644 --- a/scripts/restore +++ b/scripts/restore @@ -25,9 +25,8 @@ ynh_script_progression "Restoring files..." ynh_restore_everything # Restore mysql dump ynh_script_progression "Restoring database..." -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" +ynh_''mysql_create_db ccnetdb "$db_user" "$db_pwd" +ynh_''mysql_create_db seahubdb "$db_user" "$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 seahubdb < ${YNH_CWD}/seahubdb.dmp" @@ -67,8 +66,9 @@ sleep 5 # Restart service ynh_script_progression "Starting seafile services..." -ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log -ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" +ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log +sleep 2 +ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd" sleep 2 ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 9915cbb..55e6ef8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -206,8 +206,9 @@ yunohost service add seahub --description 'Seafile server web interface.' ynh_script_progression "Starting seafile services..." sleep 5 ynh_systemctl --service=memcached.service -p "systemd" -ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log -ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd" +ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log +sleep 2 +ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd" sleep 2 # remove old version files From 053b6388e8976af8c5644b2359b92a9d473cff8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Mon, 2 Sep 2024 21:30:21 +0200 Subject: [PATCH 10/10] Fix permissions --- scripts/_common.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index eb2fd9f..67d58c2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -47,8 +47,10 @@ install_source() { } set_permission() { + chown "$app:$app" "$install_dir" + chmod u=rwx,g=rx,o= "$install_dir" chown -R "$app:$app" "$install_dir"/{conf,ccnet} - chmod -R u+rwX,g-w,o= "$install_dir"/{conf,ccnet} + chmod -R u+rwX,g+rX-w,o= "$install_dir"/{conf,ccnet} chown -R "$app:$app" "$install_dir"/seafile_image/opt/seafile chmod -R u+rwX,g-w,o= "$install_dir"/seafile_image/opt/seafile @@ -67,6 +69,7 @@ set_permission() { test -e "$install_dir"/seahub-data && setfacl -m user:www-data:rX "$data_dir" test -e "$install_dir"/seahub-data && setfacl -R -m user:www-data:rX "$data_dir"/seahub-data + chmod u=rwx,g=rx,o= "$data_dir" find "$data_dir" \( \! -perm -o= \ -o \! -user "$app" \ -o \! -group "$app" \) \