#!/bin/bash #================================================= # GENERIC START #================================================= # Import common cmd source ./experimental_helper.sh source ./_common.sh source ./ynh_setup_source # Source YunoHost helpers source /usr/share/yunohost/helpers seafile_version="$(ynh_app_upstream_version)" installed_version="${YNH_APP_CURRENT_VERSION/~ynh*/}" seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" ensure_vars_set if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version --comparison=le --version='7.0~ynh1'; then ynh_die "Upgrade from this version not supported" fi ynh_script_progression "Stoping services..." ynh_systemctl --service=seafile --action=stop ynh_systemctl --service=seahub --action=stop sleep 5 pkill -f seafile-controller || true pkill -f seaf-server || true pkill -f ccnet-server || true pkill -f seahub || true # Migrate DB name if needed if mysqlshow | grep -q seafiledb; then 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" 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 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 # # Create link to /home/yunohost.app/seafile/seafile-data in case of old install with data dir defined in config instead of symlink # Also update link if not pointing to correct path if [ ! -L /home/yunohost.app/seafile-data ] || \ [ "$(readlink "$install_dir"/seafile-data)" != "$data_dir/seafile-data" ]; then mv "$install_dir"/seafile-data "$install_dir/seafile-data_$(date '+%Y%m%d.%H%M%S')" ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data fi # Move if needed old /home/yunohost.app/seafile-data dir to /home/yunohost.app/seafile/seafile-data if [ -e /home/yunohost.app/seafile-data ]; then if [ -e "$data_dir" ]; then mv "$data_dir" "${data_dir}_$(date '+%Y%m%d.%H%M%S')" fi mkdir -p "$data_dir" mv /home/yunohost.app/seafile-data "$data_dir"/ fi # In case of seafile-data content was directly stored in /home/yunohost.app/seafile if [ -e "$data_dir"/storage ]; then mkdir -p "$data_dir"/seafile-data mv -t "$data_dir"/seafile-data "$data_dir"/{commits,fs,httptemp,library-template,storage,tmpfiles,webdavtmp} || true # In case of some of dir don't exist fi # Move seahub data to /home/yunohost.app/seafile/seahub-data if [ ! -L "$install_dir"/seahub-data ]; then if [ -e "$data_dir"/seahub-data ]; then mv "$data_dir"/seahub-data "$data_dir/seahub-data_$(date '+%Y%m%d.%H%M%S')" fi mv "$install_dir"/seahub-data "$data_dir"/ ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data fi # Move logs storage to /var/log/seafile if [ ! -L "$install_dir"/logs ]; then if [ -e /var/log/"$app" ]; then mv /var/log/"$app" /var/log/"${app}_$(date '+%Y%m%d.%H%M%S')" fi mv "$install_dir"/logs /var/log/"${app}" ln -s /var/log/"${app}" "$install_dir"/logs fi ynh_script_progression "Upgrading source files..." # Download new version from sources ynh_script_progression "Installing sources files..." if [ "$YNH_APP_UPGRADE_TYPE" == UPGRADE_APP ]; then install_source fi ynh_script_progression "Configuring application..." # permission to execute update script and expect helper set_permission # do the upgrade ( the ";&" syntax mean when it go in the first case which is true it do all the next case) case "$installed_version" in "4."* ) # Update seafile by script ynh_die "Upgrade form the version 4.x was removed. Upgrade from this version won't be supported any more." ;& "5."* ) # Update seafile by script ynh_die "Upgrade form the version 5.x was removed. Upgrade from this version won't be supported any more." ;& "6."* ) ynh_die "Upgrade form the version 6.x was removed. Upgrade from this version won't be supported any more." ;& "7.0"* ) # Fix file comment 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 --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 if [ -e "$install_dir"/seafile-data ]; then old_data_dir_path="$install_dir/seafile-data$(date '+%Y%m%d.%H%M%S')" mv "$install_dir/seafile-data" "$old_data_dir_path" fi ln -s "$data_dir" "$install_dir"/seafile-data ;& "7.1."* ) 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 --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 --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 --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 --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_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 --match=en_US.UTF-8 --replace="${LANG:-'en_US.UTF-8'}" --file="$seafile_code/seahub.sh" #================================================= # Config nginx ynh_config_add_nginx 'seahub_port fileserver_port webdav_port' # Add Seafile Server to startup ynh_script_progression "Updating systemd units..." ynh_config_add_systemd --service=seafile --template=seafile.service ynh_config_add_systemd --service=seahub --template=seahub.service #================================================= # Set all permissions ynh_script_progression "Protecting directory..." set_permission # Add logrotate ynh_script_progression "Configuring log rotation..." ynh_config_add_logrotate /var/log/"$app" # Add fail2ban ynh_script_progression "Configuring fail2ban..." ynh_config_add_fail2ban # register yunohost 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 "Starting seafile services..." sleep 5 ynh_systemctl --service=memcached.service -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 ynh_script_progression "Cleaning system and updating settings..." for f in "$install_dir"/seafile-server-*;do if [[ ! "$f" =~ ${seafile_version//./\\.}|latest ]]; then ynh_safe_rm "$f" fi done ynh_script_progression "Upgrade of $app completed"