#!/bin/bash #================================================= # GENERIC START #================================================= # Import common cmd source ./experimental_helper.sh source ./_common.sh # Source YunoHost helpers source /usr/share/yunohost/helpers # Retrieve arguments installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/} seafile_version=$(ynh_app_upstream_version) if [ "$YNH_APP_CURRENT_VERSION" == '-' ]; then ynh_die "Upgrade from this version not supported" fi ynh_script_progression --message="Stoping services..." # stop seafile server if [ -e /etc/init.d/seafile-server ] then # Old init script support systemctl stop seafile-server --quiet systemctl disable seafile-server --quiet ynh_secure_remove --file=/etc/init.d/seafile-server yunohost service remove seafile-server else ynh_systemd_action --service_name seafile --action stop ynh_systemd_action --service_name seahub --action stop fi sleep 5 pkill -f seafile-controller || true pkill -f seaf-server || true pkill -f ccnet-server || true pkill -f seahub || true ynh_script_progression --message="Upgrading source files..." --weight=6 ynh_script_progression --message="Installing sources files..." --weight=7 ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version # Upgrade dependances install_dependance ynh_script_progression --message="Configuring application..." # permission to execute update script and expect helper mv_expect_scripts set_permission chmod u+x,o= $install_dir/seafile-server-$seafile_version/upgrade/upgrade_*.sh chmod u+x,o= $install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh # TODO !! retrive config from config file if not already set # 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 pushd $install_dir/seafile-server-$seafile_version sudo -u $seafile_user $install_dir/seafile-server-$seafile_version/seahub.sh python-env python3 seahub/manage.py migrate_file_comment popd # Update seafile by script sudo -u $seafile_user $expect_scripts_dir/upgrade_7.1.exp $install_dir/seafile-server-$seafile_version # 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 $seafile_data $install_dir/seafile-data ;& "7.1."* ) sudo -u $seafile_user $expect_scripts_dir/upgrade_8.0.exp $install_dir/seafile-server-$seafile_version echo "FILTER = permission=cn=$app.main,ou=permission,dc=yunohost,dc=org" | tee -a $install_dir/conf/ccnet.conf ;& "8.0."* ) sudo -u $seafile_user $expect_scripts_dir/upgrade_9.0.exp $install_dir/seafile-server-$seafile_version ;& esac sudo -u $seafile_user $expect_scripts_dir/minor-upgrade.exp $install_dir/seafile-server-$seafile_version # Update seafile config files ynh_add_config --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 # Fix local warning ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh # Update gunicorn config sed --in-place -r "s@bind = \"0\.0\.0\.0:[[:digit:]]+\"@bind = \"0.0.0.0:$seahub_port\"@g" $install_dir/conf/gunicorn.conf.py #================================================= # STANDARD UPGRADE STEPS #================================================= # Config nginx ynh_add_nginx_config '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 #================================================= # GENERIC FINALIZATION #================================================= # Set all permissions ynh_script_progression --message="Protecting directory..." set_permission # Add logrotate ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate --logfile $install_dir/logs --nonappend # Add fail2ban ynh_script_progression --message="Configuring fail2ban..." --weight=10 ynh_add_fail2ban_config --use_template # register yunohost service ynh_script_progression --message="Register seafile service..." yunohost service add seafile yunohost service add seahub # delete seafile cache ynh_secure_remove --file=/tmp/seahub_cache # restart seafile server ynh_script_progression --message="Starting seafile services..." --weight=3 sleep 5 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 # remove old version files ynh_script_progression --message="Cleaning system and updating settings..." ls $install_dir | grep "seafile-server-" | egrep -v "(${seafile_version//./\\.})|(latest)" | \ while read f do ynh_secure_remove --file=$install_dir/$f done ynh_script_progression --message="Upgrade of $app completed" --last