2015-02-13 18:10:02 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2019-11-01 22:04:11 +01:00
|
|
|
source ./_common.sh
|
2020-04-16 23:33:43 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-12-13 16:12:58 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
# LOAD SETTINGS
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2020-04-16 23:33:43 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
2020-10-08 23:57:54 +02:00
|
|
|
path_url=$(ynh_normalize_url_path --path_url $(ynh_app_setting_get --app $app --key path))
|
2020-04-16 23:33:43 +02:00
|
|
|
final_path=$(ynh_app_setting_get --app $app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
secret=$(ynh_app_setting_get --app $app --key=secret)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key mysqlpwd)
|
2022-06-19 18:25:06 +02:00
|
|
|
port=$(ynh_app_setting_get --app=$app --key web_port)
|
2017-10-30 17:52:57 +01:00
|
|
|
db_user=$app
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Checking backware compatibility..." --weight=10
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z "$db_name" ]; then
|
2020-04-16 23:33:43 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
2016-01-13 21:14:06 +01:00
|
|
|
fi
|
2015-02-13 18:10:02 +01:00
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
2018-08-04 00:35:34 +02:00
|
|
|
final_path=/opt/yunohost/$app
|
2020-04-16 23:33:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2015-02-13 18:10:02 +01:00
|
|
|
fi
|
|
|
|
|
2022-08-30 06:50:02 +02:00
|
|
|
if [ -z "${port:-}" ]; then
|
|
|
|
# Find available ports
|
|
|
|
port=$(ynh_find_port --port 6000)
|
|
|
|
ynh_app_setting_set --app $app --key web_port --value $port
|
|
|
|
fi
|
|
|
|
|
2018-01-29 22:44:33 +01:00
|
|
|
# If path_url doesn't exist, create it
|
|
|
|
if [ -z "$path_url" ]; then
|
2020-04-16 23:33:43 +02:00
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value="$path_url"
|
2018-01-29 22:44:33 +01:00
|
|
|
ynh_app_setting_delete "$app" path
|
|
|
|
fi
|
|
|
|
|
2017-11-16 23:23:51 +01:00
|
|
|
# Detect old installation style
|
2018-08-04 00:35:34 +02:00
|
|
|
if [ -e /etc/init.d/ffsync ]; then
|
2017-11-16 23:23:51 +01:00
|
|
|
service ffsync stop
|
|
|
|
update-rc.d -f ffsync remove
|
|
|
|
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_secure_remove --file=/etc/init.d/ffsync
|
|
|
|
ynh_secure_remove --file=/var/log/ffsync.log
|
|
|
|
ynh_secure_remove --file=/opt/yunohost/ffsync
|
2017-11-16 23:23:51 +01:00
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
yunohost service remove "$app"
|
2017-11-16 23:23:51 +01:00
|
|
|
fi
|
|
|
|
|
2020-05-23 20:57:23 +02:00
|
|
|
# Remove old service ending with ".service"
|
|
|
|
if ynh_exec_warn_less yunohost service status "uwsgi-app@$app.service" >/dev/null
|
|
|
|
then
|
|
|
|
yunohost service remove uwsgi-app@$app.service
|
|
|
|
fi
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10
|
2020-04-16 23:33:43 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
2017-10-30 17:52:57 +01:00
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
2020-04-16 23:33:43 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2022-06-19 18:25:06 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Checking backware compatibility..." --weight=10
|
|
|
|
|
|
|
|
# Detect old installation with uwsgi
|
|
|
|
if [ -e /etc/uwsgi/apps-available/$app.ini ]; then
|
|
|
|
systemctl stop uwsgi-app@$app.service
|
2022-08-21 09:12:56 +02:00
|
|
|
systemctl disable --quiet uwsgi-app@$app.service
|
2022-06-19 18:25:06 +02:00
|
|
|
yunohost service remove "uwsgi-app@$app"
|
|
|
|
ynh_secure_remove --file=/etc/uwsgi/apps-available/$app.ini
|
|
|
|
ynh_secure_remove --file=/etc/systemd/system/uwsgi-app@$app.service.d
|
|
|
|
ynh_secure_remove --file=$final_path
|
|
|
|
else
|
|
|
|
systemctl stop $app.service
|
|
|
|
fi
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2023-01-22 10:54:32 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2023-01-22 10:54:32 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=6
|
2017-10-30 17:52:57 +01:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2022-06-19 18:25:06 +02:00
|
|
|
if [ -e $final_path/syncserver.ini ]; then
|
|
|
|
config_backup="$(cat $final_path/syncserver.ini)"
|
|
|
|
install_sources
|
|
|
|
echo "$config_backup" > $final_path/syncserver.ini
|
|
|
|
else
|
|
|
|
install_sources
|
|
|
|
fi
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
# NGINX CONFIGURATION
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2023-01-22 10:54:32 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX"
|
|
|
|
|
2017-10-30 17:52:57 +01:00
|
|
|
if [ "$path_url" == "/" ]
|
2015-02-13 18:10:02 +01:00
|
|
|
then
|
2017-10-30 17:52:57 +01:00
|
|
|
# $finalnginxconf comes from ynh_add_nginx_config
|
|
|
|
# uwsgi_param is only needed for non-root installation
|
2020-12-07 16:26:56 +01:00
|
|
|
is_subpath="# "
|
|
|
|
else
|
|
|
|
is_subpath=" "
|
2015-02-13 18:10:02 +01:00
|
|
|
fi
|
2020-12-07 16:26:56 +01:00
|
|
|
ynh_add_nginx_config 'is_subpath'
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
ynh_system_user_create --username="$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Configuring application..."
|
2020-04-16 23:33:43 +02:00
|
|
|
|
2023-01-22 10:54:32 +01:00
|
|
|
# SETUP UWSGI
|
2018-09-05 22:23:48 +02:00
|
|
|
# create config file syncserver.ini
|
2022-06-19 18:25:06 +02:00
|
|
|
ynh_script_progression --message="Configuring application..."
|
|
|
|
ynh_add_config --template="syncserver.ini" --destination="$final_path/syncserver.ini"
|
2018-09-05 22:23:48 +02:00
|
|
|
|
2022-06-19 18:25:06 +02:00
|
|
|
# Configure init script
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
|
|
|
ynh_add_systemd_config
|
2018-09-05 22:23:48 +02:00
|
|
|
|
2020-10-08 23:57:54 +02:00
|
|
|
# Upgrade database table
|
|
|
|
ynh_mysql_execute_as_root --sql='ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `keys_changed_at` BIGINT NULL AFTER `replaced_at`;' --database=$db_name
|
|
|
|
ynh_mysql_execute_as_root --sql='ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `node` VARCHAR(255) NULL AFTER `keys_changed_at`;' --database=$db_name
|
|
|
|
|
2018-09-05 22:23:48 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2017-10-30 17:52:57 +01:00
|
|
|
#=================================================
|
2019-11-01 22:04:11 +01:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
|
|
|
|
|
|
|
# Set permissions on app files
|
2019-11-01 22:04:11 +01:00
|
|
|
set_permissions
|
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2021-03-15 12:03:05 +01:00
|
|
|
# Migrate legacy permissions to new system
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
2021-03-15 12:03:05 +01:00
|
|
|
ynh_script_progression --message="Set permissions..."
|
2023-01-22 10:54:32 +01:00
|
|
|
|
2021-03-15 12:03:05 +01:00
|
|
|
if ynh_legacy_permissions_exists
|
|
|
|
then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
ynh_permission_update --permission=main --add=visitors --protected=true --show_tile=true
|
|
|
|
|
2022-06-19 18:25:06 +02:00
|
|
|
yunohost service add "$app"
|
2020-04-16 23:33:43 +02:00
|
|
|
|
2020-12-07 16:26:56 +01:00
|
|
|
ynh_script_progression --message="Restarting $app services..." --weight=3
|
2022-06-19 18:25:06 +02:00
|
|
|
ynh_systemd_action --service_name "$app.service" \
|
|
|
|
--line_match "Booting worker with pid" --log_path "systemd" -t 20
|
2020-12-07 16:26:56 +01:00
|
|
|
|
2020-04-16 23:33:43 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-10-30 17:52:57 +01:00
|
|
|
|
2019-11-01 22:04:11 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|