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
2020-12-14 16:35:22 +01:00
seafile_version=$(ynh_app_upstream_version)
2024-04-12 22:19:27 +02:00
installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/}
2023-09-27 23:04:06 +02:00
2024-04-12 21:22:21 +02:00
ensure_vars_set
2024-04-12 22:19:27 +02:00
if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version --comparison=le --version='7.0~ynh1'; 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
2024-04-21 01:50:52 +02:00
install_pkg_conf
2024-04-20 23:17:25 +02:00
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Stoping services..."
2024-04-12 22:19:27 +02:00
ynh_systemd_action --service_name seafile --action stop
ynh_systemd_action --service_name seahub --action stop
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 23:04:06 +02:00
# Migrate DB name if needed
2023-09-27 20:13:07 +02:00
if mysqlshow | grep -q seafiledb; then
2023-09-27 23:04:06 +02:00
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"
2024-04-12 22:19:27 +02:00
ynh_replace_string --match_string='db_name = seafiledb' --replace_string='db_name = seafile' --target_file="$install_dir"/conf/seafile.conf
sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" "$install_dir"/conf/seafile.conf
2023-09-27 23:04:06 +02:00
fi
# Set missing settings
2024-04-12 22:19:27 +02:00
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"
2023-09-27 20:13:07 +02:00
fi
2024-04-12 22:19:27 +02:00
#
2023-10-26 10:14:27 +02:00
# Update data dir if needed
2024-04-12 22:19:27 +02:00
#
# 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
2023-10-26 11:14:43 +02:00
if [ ! -L /home/yunohost.app/seafile-data ] || \
2024-04-12 22:19:27 +02:00
[ "$(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
2023-10-26 10:14:27 +02:00
fi
2024-04-12 22:19:27 +02:00
# Move if needed old /home/yunohost.app/seafile-data dir to /home/yunohost.app/seafile/seafile-data
2023-10-26 10:14:27 +02:00
if [ -e /home/yunohost.app/seafile-data ]; then
2024-04-12 22:19:27 +02:00
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')"
2023-10-26 10:33:04 +02:00
fi
2024-04-12 22:19:27 +02:00
mv "$install_dir"/logs /var/log/"${app}"
ln -s /var/log/"${app}" "$install_dir"/logs
2023-10-26 10:14:27 +02:00
fi
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=6
2023-10-04 07:54:30 +02:00
# Download new version from sources
2023-08-08 23:21:11 +02:00
ynh_script_progression --message="Installing sources files..." --weight=7
2024-04-12 21:22:21 +02:00
if [ "$YNH_APP_UPGRADE_TYPE" == UPGRADE_APP ]; then
install_source
fi
2015-03-25 19:14:18 +01:00
2023-10-04 07:54:30 +02:00
ynh_script_progression --message="Installing python dependancies..."
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
2021-04-09 21:20:39 +02:00
set_permission
2023-08-08 23:21:11 +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
2023-08-08 23:21:11 +02:00
"4."* )
2015-08-24 20:45:36 +02:00
# 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."* )
2015-08-24 20:45:36 +02:00
# 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."
2019-07-30 11:56:10 +02:00
;&
2020-04-28 13:57:07 +02:00
"7.0"* )
2020-12-15 22:09:09 +01:00
# Fix file comment
2024-04-12 21:22:21 +02:00
pushd "$install_dir/seafile-server-$seafile_version"
sudo -u "$app" "$install_dir/seafile-server-$seafile_version/seahub.sh" python-env python3 seahub/manage.py migrate_file_comment
2021-04-09 21:20:39 +02:00
popd
# Update seafile by script
2024-04-12 21:22:21 +02:00
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh"
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
2024-04-12 21:22:21 +02:00
if [ -e "$install_dir"/seafile-data ]; then
2023-10-26 11:14:43 +02:00
old_data_dir_path="$install_dir/seafile-data$(date '+%Y%m%d.%H%M%S')"
2023-08-08 23:21:11 +02:00
mv "$install_dir/seafile-data" "$old_data_dir_path"
2020-12-15 22:09:09 +01:00
fi
2024-04-12 21:22:21 +02:00
ln -s "$data_dir" "$install_dir"/seafile-data
2020-04-28 13:57:07 +02:00
;&
2021-06-26 12:22:45 +02:00
"7.1."* )
2024-04-12 21:22:21 +02:00
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
2021-06-26 12:22:45 +02:00
;&
2022-01-18 21:10:55 +01:00
"8.0."* )
2024-04-12 21:22:21 +02:00
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh"
;&
"9."* )
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
;&
"10."* )
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh"
sudo -u "$app" "$install_dir"/venv/bin/python "$install_dir/seafile-server-$seafile_version/migrate_ldapusers.py"
2022-01-18 21:10:55 +01:00
;&
2015-08-24 20:45:36 +02:00
esac
2024-04-12 21:22:21 +02:00
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh"
2017-05-05 15:43:32 +02:00
2023-09-27 19:21:58 +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
2024-04-12 21:22:21 +02:00
ynh_add_jinja_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py
2023-09-27 19:21:58 +02:00
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
2024-04-12 21:22:21 +02:00
ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
2019-06-12 22:56:50 +02:00
2017-07-21 14:56:41 +02:00
# Fix local warning
2024-04-12 21:22:21 +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
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..."
2024-04-12 22:19:27 +02:00
ynh_use_logrotate --logfile=/var/log/"$app" --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..."
2024-02-20 21:28:59 +01:00
yunohost service add seafile --description 'Main service for seafile server.'
yunohost service add seahub --description 'Seafile server web interface.'
2015-03-25 19:14:18 +01:00
2015-08-29 13:25:04 +02:00
# delete seafile cache
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
2023-09-27 19:21:58 +02:00
ynh_systemd_action --service_name memcached.service -p "systemd"
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..."
2024-04-12 21:22:21 +02:00
ls "$install_dir" | grep "seafile-server-" | grep -E -v "(${seafile_version//./\\.})|(latest)" | \
while read -r f
2018-02-12 17:14:08 +01:00
do
2024-04-12 21:22:21 +02:00
ynh_secure_remove --file="$install_dir/$f"
2018-02-12 17:14:08 +01:00
done
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