2015-03-25 19:14:18 +01:00
#!/bin/bash
2015-10-28 16:04:51 +01:00
2018-02-11 01:20:58 +01:00
#=================================================
# 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
# Stop script if errors
ynh_abort_if_errors
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Loading installation settings..."
2017-07-21 14:56:41 +02:00
# Retrieve arguments
2019-06-11 22:28:26 +02:00
domain=$(ynh_app_setting_get --app $app --key domain)
2019-10-01 20:53:33 +02:00
path_url=$(ynh_normalize_url_path --path_url $(ynh_app_setting_get --app $app --key path))
2019-06-11 22:28:26 +02:00
installed_version=$(ynh_app_setting_get --app $app --key installed_version)
seahub_port=$(ynh_app_setting_get --app $app --key seahub_port)
fileserver_port=$(ynh_app_setting_get --app $app --key fileserver_port)
webdav_port=$(ynh_app_setting_get --app $app --key webdav_port)
2019-08-05 15:34:00 +02:00
final_path=$(ynh_app_setting_get --app $app --key final_path)
seafile_user=$app
2020-12-14 16:35:22 +01:00
# TODO User env variable in 4.1
seafile_version=$(ynh_app_upstream_version)
2016-12-27 10:44:40 +01:00
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
2020-12-12 15:03:12 +01:00
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
2018-06-07 21:20:50 +02:00
sleep 2
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
2020-12-14 16:35:22 +01:00
# Backup the current version of the app
if [ "0$(ynh_app_setting_get --app=$app --key=disable_backup_before_upgrade)" -ne 1 ]
then
ynh_backup_before_upgrade
ynh_clean_setup () {
# Clean installation remainings that are not handled by the remove script.
ynh_clean_check_starting
ynh_restore_upgradebackup
}
fi
2020-11-29 17:30:05 +01:00
2018-02-11 01:20:58 +01:00
#=================================================
# MIGRATION FROM OLD VERSION
#=================================================
2019-08-05 15:34:00 +02:00
ynh_script_progression --message="Fixing old settings..." --weight=1
# Get configuration for user and final path
if [ -z $final_path ]; then
if [ -e /var/www/$app ]; then
final_path=/var/www/$app
elif [ -e /opt/yunohost/$app ]; then
final_path=/opt/yunohost/$app
else
ynh_die --message "Error : can't find seafile path"
fi
fi
if [ $final_path == "/var/www/$app" ]; then
final_path="/opt/yunohost/$app"
2019-11-03 17:19:25 +01:00
mkdir -p /opt/yunohost
mv /var/www/$app /opt/yunohost/$app
2019-08-05 15:34:00 +02:00
ynh_system_user_create --username $seafile_user --home_dir $final_path
ynh_app_setting_set --app $app --key final_path --value $final_path
2019-11-03 12:43:58 +01:00
test -e /var/log/seafile && rm /var/log/$app
2020-05-01 16:39:15 +02:00
if ! [ -z "$(ls -A $final_path/seafile_data)" ]; then
2020-11-02 15:38:09 +01:00
# Data directory NOT empty, transfer data to /home/yunohost.app/seafile
mv $final_path/seafile_data/* /home/yunohost.app/seafile-data/
2020-05-01 16:39:15 +02:00
ynh_secure_remove $final_path/seafile_data
2020-10-26 11:47:39 +01:00
ln -s /home/yunohost.app/seafile-data $final_path/
2020-05-01 16:39:15 +02:00
fi
2019-11-03 12:43:58 +01:00
ln -s $final_path/logs /var/log/seafile
2019-08-05 15:34:00 +02:00
set_permission
fi
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=6
2015-03-25 19:14:18 +01:00
# extract new version
2019-06-11 22:28:26 +02:00
test -e $final_path/seafile-server-$seafile_version && ynh_secure_remove --file="$final_path/seafile-server-$seafile_version"
2018-01-19 20:55:44 +01:00
install_source
2015-03-25 19:14:18 +01:00
2019-05-09 11:18:17 +02:00
# Upgrade dependances
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Upgrading dependencies..."
2019-05-09 11:18:17 +02:00
install_dependance
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Configuring application..."
2015-03-25 19:14:18 +01:00
# permission to execute update script and expect helper
2018-07-06 10:28:14 +02:00
chmod +x expect_scripts/upgrade_*.exp
chmod +x expect_scripts/minor-upgrade.exp
2017-07-21 14:56:41 +02:00
chmod +x $final_path/seafile-server-$seafile_version/upgrade/upgrade_*.sh
chmod +x $final_path/seafile-server-$seafile_version/upgrade/minor-upgrade.sh
2017-05-05 15:43:32 +02:00
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)
2015-08-24 20:45:36 +02:00
case $installed_version in
"4.0."* )
# Update seafile by script
2020-04-13 15:24:46 +02:00
ynh_die "Upgrade form the version 4.0 was removed. Upgrade from this version won't be supported any more."
2017-05-05 15:43:32 +02:00
;&
2015-08-24 20:45:36 +02:00
"4.1."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_4.2.1.exp $final_path/seafile-server-$seafile_version
2017-05-05 15:43:32 +02:00
;&
2015-10-22 22:38:59 +02:00
"4.3."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_4.4.3.exp $final_path/seafile-server-$seafile_version
2017-05-05 15:43:32 +02:00
;&
2015-12-26 13:44:45 +01:00
"4.4."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_5.0.3.exp $final_path/seafile-server-$seafile_version
2017-05-05 15:43:32 +02:00
;&
2016-12-27 10:44:40 +01:00
"5.0."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_5.1.exp $final_path/seafile-server-$seafile_version
2017-05-05 15:43:32 +02:00
;&
2016-12-27 10:44:40 +01:00
"5.1."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_6.0.exp $final_path/seafile-server-$seafile_version
2017-07-21 14:56:41 +02:00
;&
"6.0."* )
2020-05-01 15:39:29 +02:00
install_source_7_0
2018-03-09 20:37:26 +01:00
python3 ../conf/update_sso_conf.py || true
2017-07-21 14:56:41 +02:00
# Update seafile by script
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_6.1.exp $final_path/seafile-server-$seafile_version
2017-08-09 15:34:10 +02:00
# Enable manually wiki
echo 'ENABLE_WIKI = True' | tee -a $final_path/conf/seahub_settings.py
2017-05-05 15:43:32 +02:00
;&
2017-09-30 15:07:56 +02:00
"6.1."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_6.2.exp $final_path/seafile-server-$seafile_version
2018-07-06 10:28:14 +02:00
;&
"6.2."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_6.3.exp $final_path/seafile-server-$seafile_version
2018-07-06 10:28:14 +02:00
# Update logrotate to have the last version
2019-11-04 20:30:02 +01:00
ynh_use_logrotate --logfile $final_path/logs --nonappend
2017-09-30 15:07:56 +02:00
;&
2019-07-30 11:56:10 +02:00
"6.3."* )
# Update seafile by script
2020-05-01 15:39:29 +02:00
install_source_7_0
2020-04-13 15:24:46 +02:00
expect_scripts/upgrade_7.0.exp $final_path/seafile-server-$seafile_version
2019-07-30 21:58:38 +02:00
# SSO authentication
echo 'ENABLE_REMOTE_USER_AUTHENTICATION = True' | tee -a $final_path/conf/seahub_settings.py
2019-08-29 22:52:48 +02:00
echo "REMOTE_USER_HEADER = 'HTTP_EMAIL'" | tee -a $final_path/conf/seahub_settings.py
2019-07-30 21:58:38 +02:00
echo 'REMOTE_USER_CREATE_UNKNOWN_USER = False' | tee -a $final_path/conf/seahub_settings.py
echo "REMOTE_USER_PROTECTED_PATH = ['$path_url', '$path_url/accounts/login']" | tee -a $final_path/conf/seahub_settings.py
# Clean connexion from the SSO. If we don't do this we could have some when the user was loged by the old SSO auth mecanisme
2019-08-05 15:34:31 +02:00
ynh_mysql_execute_as_root --sql "DELETE FROM \`django_session\`" --database seahubdb
2019-12-01 21:11:24 +01:00
ynh_print_warn --message "To be able to continue to use the SSO you probybly need to migrate your account. You can use the command 'yunohost app action run seafile migrate_user_email_to_mail_email' to migrate all of theses account. Note that after this migratation you need to reconfigure all your client with the official email of the user."
2020-05-01 15:39:29 +02:00
ynh_secure_remove --file="$final_path/seafile-server-7.0.5"
2019-07-30 11:56:10 +02:00
;&
2020-04-28 13:57:07 +02:00
"7.0"* )
# Fix file comment
$final_path/seafile-server-$seafile_version/seahub.sh python-env seahub/manage.py migrate_file_comment
# Enable memcached
2020-12-14 16:35:22 +01:00
cat >> $final_path/conf/seahub_settings.py <<EOF
2020-04-28 13:57:07 +02:00
CACHES = {
'default': {
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
'LOCATION': '127.0.0.1:11211',
},
}
EOF
# Update seafile by script
expect_scripts/upgrade_7.1.exp $final_path/seafile-server-$seafile_version
;&
2015-08-24 20:45:36 +02:00
esac
2020-04-13 15:24:46 +02:00
expect_scripts/minor-upgrade.exp $final_path/seafile-server-$seafile_version
2017-05-05 15:43:32 +02:00
2015-08-24 20:45:36 +02:00
## Install webdav and logrotate if not installed
if [[ $installed_version = "4.0."* ]] || [[ $installed_version = "4.1."* ]]
then
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Configuring webdav..."
2017-07-21 14:56:41 +02:00
webdav_port=$(ynh_find_port 8080)
2019-06-11 22:28:26 +02:00
ynh_app_setting_set --app $app --key webdav_port --value $webdav_port
2015-08-24 20:45:36 +02:00
# Disallow port that was used by old seafile client
2019-06-11 22:28:26 +02:00
ccnet_port=$(ynh_app_setting_get --app $app --key ccnet_port)
seafile_port=$(ynh_app_setting_get --app $app --key seafile_port)
2017-07-21 14:56:41 +02:00
yunohost firewall disallow Both $ccnet_port
yunohost firewall disallow Both $seafile_port
2015-08-24 20:45:36 +02:00
# Add webdav config
2017-07-21 14:56:41 +02:00
cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
2019-06-11 22:28:26 +02:00
ynh_replace_string --match_string __WEBDAV_PORT__ --replace_string $webdav_port --target_file $final_path/conf/seafdav.conf
2015-08-24 20:45:36 +02:00
# Add sso config to unprotect domain.tld/seafdav in /etc/ssowat/conf.json.persistent
2019-06-11 22:28:26 +02:00
python3 ../conf/add_sso_conf_webdav.py
2015-08-24 20:45:36 +02:00
# Update seafile config
2017-07-21 14:56:41 +02:00
echo 'COMPRESS_URL = MEDIA_URL' | tee -a $final_path/conf/seahub_settings.py
echo "STATIC_URL = MEDIA_URL + 'assets/'" | tee -a $final_path/conf/seahub_settings.py
2015-08-24 20:45:36 +02:00
fi
2015-03-25 19:14:18 +01:00
2017-01-05 23:24:32 +01:00
# Update seahub config for old version to version 5.0.4
2017-07-21 14:56:41 +02:00
if [[ $(grep -c "LOGIN_URL" $final_path/conf/seahub_settings.py) == 0 ]]
2017-01-05 23:24:32 +01:00
then
2018-05-09 16:13:36 +02:00
echo "LOGIN_URL = '$path_url/accounts/login/'" | tee -a $final_path/conf/seahub_settings.py
2017-01-05 23:24:32 +01:00
fi
2019-06-12 22:56:50 +02:00
if [ $(grep -c "TIME_ZONE" $final_path/conf/seahub_settings.py) == 0 ]
then
echo "TIME_ZONE = \"$(cat /etc/timezone)\"" | tee -a $final_path/conf/seahub_settings.py
fi
2017-07-21 14:56:41 +02:00
# Fix local warning
2019-06-11 22:28:26 +02:00
ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $final_path/seafile-server-$seafile_version/seahub.sh
2017-07-21 14:56:41 +02:00
2018-08-03 22:24:07 +02:00
# Update gunicorn config
2020-04-28 13:57:07 +02:00
sed --in-place -r "s@bind = \"0\.0\.0\.0:[[:digit:]]+\"@bind = \"0.0.0.0:$seahub_port\"@g" $final_path/conf/gunicorn.conf.py
2018-08-03 22:24:07 +02:00
2019-06-11 22:28:26 +02:00
# In the 3.x seafile version package the seahub_port and fileserver_port wasn't saved in the settings. If the settings is empty we try to get it and save in the settings
if [[ -z $seahub_port ]] || [[ -z $fileserver_port ]]
then
seahub_port=$(head -n 20 /etc/nginx/conf.d/$domain.d/seafile.conf | grep -E "fastcgi_pass.*127.0.0.1:" | cut -d':' -f2 | cut -d';' -f1)
fileserver_port=$(head -n 50 /etc/nginx/conf.d/$domain.d/seafile.conf | grep -E "proxy_pass.*127.0.0.1:" | cut -d':' -f3 | cut -d';' -f1 | cut -d'/' -f1)
ynh_app_setting_set --app $app --key seahub_port --value $seahub_port
ynh_app_setting_set --app $app --key fileserver_port --value $fileserver_port
fi
2018-02-11 01:20:58 +01: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
2018-02-11 01:20:58 +01: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..."
2019-10-01 20:53:33 +02:00
ynh_use_logrotate --logfile $final_path/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
ynh_add_fail2ban_config --use_template --others_var 'final_path'
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
2015-03-25 19:14:18 +01:00
2015-08-29 13:25:04 +02:00
# delete seafile cache
2019-06-11 22:28:26 +02:00
ynh_secure_remove --file=/tmp/seahub_cache
2015-08-29 13:25:04 +02:00
2015-03-25 19:14:18 +01:00
# 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
2019-09-10 22:51:15 +02:00
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
2015-03-25 19:14:18 +01:00
# remove old version files
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Cleaning system and updating settings..."
2018-02-12 17:14:08 +01:00
ls $final_path | grep "seafile-server-" | egrep -v "(${seafile_version//./\\.})|(latest)" | \
while read f
do
2019-06-11 22:28:26 +02:00
ynh_secure_remove --file=$final_path/$f
2018-02-12 17:14:08 +01:00
done
2015-03-25 19:14:18 +01:00
# store new installed version
2019-06-11 22:28:26 +02:00
ynh_app_setting_set --app $app --key installed_version --value $seafile_version
2015-03-25 19:14:18 +01:00
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last