seafile_ynh/scripts/upgrade

168 lines
5.8 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
2020-11-17 23:49:06 +01:00
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
2017-07-21 14:56:41 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve arguments
2021-02-13 14:56:18 +01:00
installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/}
2020-12-14 16:35:22 +01:00
seafile_version=$(ynh_app_upstream_version)
2021-01-26 22:09:47 +01:00
if [ "$YNH_APP_CURRENT_VERSION" == '-' ]; then
2023-08-08 23:21:11 +02:00
ynh_die "Upgrade from this version not supported"
2021-01-26 22:09:47 +01:00
fi
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Stoping services..."
2017-01-05 23:24:32 +01:00
# stop seafile server
2019-06-11 22:28:26 +02:00
if [ -e /etc/init.d/seafile-server ]
then
# Old init script support
systemctl stop seafile-server --quiet
systemctl disable seafile-server --quiet
2019-06-11 22:28:26 +02:00
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
2020-12-15 22:09:09 +01:00
sleep 5
2018-06-07 21:20:50 +02:00
pkill -f seafile-controller || true
pkill -f seaf-server || true
pkill -f ccnet-server || true
pkill -f seahub || true
2017-01-05 23:24:32 +01:00
2023-09-27 20:13:07 +02:00
# Migrate DB 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'"'
fi
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=6
2023-08-08 23:21:11 +02:00
ynh_script_progression --message="Installing sources files..." --weight=7
ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version
# Upgrade dependances
install_dependance
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Configuring application..."
# permission to execute update script and expect helper
mv_expect_scripts
set_permission
2023-08-08 23:21:11 +02:00
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
2019-06-11 22:28:26 +02:00
# 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
2023-08-08 23:21:11 +02:00
"4."* )
# Update seafile by script
2023-08-08 23:21:11 +02:00
ynh_die "Upgrade form the version 4.x was removed. Upgrade from this version won't be supported any more."
2017-05-05 15:43:32 +02:00
;&
2023-08-08 23:21:11 +02:00
"5."* )
# Update seafile by script
2023-08-08 23:21:11 +02:00
ynh_die "Upgrade form the version 5.x was removed. Upgrade from this version won't be supported any more."
2017-05-05 15:43:32 +02:00
;&
2023-08-08 23:21:11 +02:00
"6."* )
ynh_die "Upgrade form the version 6.x was removed. Upgrade from this version won't be supported any more."
;&
"7.0"* )
2020-12-15 22:09:09 +01:00
# Fix file comment
2023-08-08 23:21:11 +02:00
pushd $install_dir/seafile-server-$seafile_version
2023-09-27 20:13:07 +02:00
sudo -u $YNH_APP_ID $install_dir/seafile-server-$seafile_version/seahub.sh python-env python3 seahub/manage.py migrate_file_comment
popd
# Update seafile by script
2023-09-27 20:13:07 +02:00
sudo -u $YNH_APP_ID $expect_scripts_dir/upgrade_7.1.exp $install_dir/seafile-server-$seafile_version
2023-08-08 23:21:11 +02:00
2020-12-15 22:09:09 +01:00
# Fix seafile data link. Look like that the upgrade script of seafile don't always work correctly
2023-08-08 23:21:11 +02:00
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"
2020-12-15 22:09:09 +01:00
fi
2023-08-08 23:21:11 +02:00
ln -s $seafile_data $install_dir/seafile-data
;&
2021-06-26 12:22:45 +02:00
"7.1."* )
2023-09-27 20:13:07 +02:00
sudo -u $YNH_APP_ID $expect_scripts_dir/upgrade_8.0.exp $install_dir/seafile-server-$seafile_version
2021-06-26 12:22:45 +02:00
;&
"8.0."* )
2023-09-27 20:13:07 +02:00
sudo -u $YNH_APP_ID $expect_scripts_dir/upgrade_9.0.exp $install_dir/seafile-server-$seafile_version
;&
esac
2023-09-27 20:13:07 +02:00
sudo -u $YNH_APP_ID $expect_scripts_dir/minor-upgrade.exp $install_dir/seafile-server-$seafile_version
2017-05-05 15:43:32 +02:00
# Clean url in config in DB
clean_url_in_db_config
2023-08-08 23:21:11 +02:00
# Update seafile config files
ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py
ynh_add_config --template=seafile.conf --destination=$install_dir/conf/seafile.conf
2023-08-08 23:21:11 +02:00
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
2019-06-12 22:56:50 +02:00
2017-07-21 14:56:41 +02:00
# Fix local warning
2023-08-08 23:21:11 +02:00
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
2017-07-21 14:56:41 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2017-09-30 15:07:56 +02:00
# Config nginx
2019-06-11 22:28:26 +02:00
ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
2017-09-30 15:07:56 +02:00
2019-06-11 22:28:26 +02:00
# 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
2017-09-30 15:07:56 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2019-06-11 22:28:26 +02:00
# Set all permissions
ynh_script_progression --message="Protecting directory..."
set_permission
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
2023-08-08 23:21:11 +02:00
ynh_use_logrotate --logfile $install_dir/logs --nonappend
2019-06-11 22:28:26 +02:00
2019-06-12 22:56:50 +02:00
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." --weight=10
2021-08-28 01:38:46 +02:00
ynh_add_fail2ban_config --use_template
2019-06-12 22:56:50 +02:00
2019-06-11 22:28:26 +02:00
# register yunohost service
ynh_script_progression --message="Register seafile service..."
yunohost service add seafile
yunohost service add seahub
# delete seafile cache
# restart seafile server
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Starting seafile services..." --weight=3
2018-06-06 19:22:00 +02:00
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"
sleep 2
# remove old version files
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Cleaning system and updating settings..."
2023-08-08 23:21:11 +02:00
ls $install_dir | grep "seafile-server-" | egrep -v "(${seafile_version//./\\.})|(latest)" | \
2018-02-12 17:14:08 +01:00
while read f
do
2023-08-08 23:21:11 +02:00
ynh_secure_remove --file=$install_dir/$f
2018-02-12 17:14:08 +01:00
done
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last