mirror of
https://github.com/YunoHost-Apps/ffsync_ynh.git
synced 2024-09-03 18:26:38 +02:00
183 lines
6.1 KiB
Bash
183 lines
6.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
db_user=$app
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key mysqlpwd)
|
|
secret=$(ynh_app_setting_get --app $app --key=secret)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=10
|
|
|
|
# If db_name doesn't exist, create it
|
|
if [ -z "$db_name" ]; then
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
fi
|
|
|
|
# If final_path doesn't exist, create it
|
|
if [ -z "$final_path" ]; then
|
|
final_path=/opt/yunohost/$app
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
fi
|
|
|
|
# If path_url doesn't exist, create it
|
|
if [ -z "$path_url" ]; then
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
ynh_app_setting_set --app=$app --key=path --value="$path_url"
|
|
ynh_app_setting_delete "$app" path
|
|
fi
|
|
|
|
# Detect old installation style
|
|
if [ -e /etc/init.d/ffsync ]; then
|
|
service ffsync stop
|
|
update-rc.d -f ffsync remove
|
|
|
|
ynh_secure_remove --file=/etc/init.d/ffsync
|
|
ynh_secure_remove --file=/var/log/ffsync.log
|
|
ynh_secure_remove --file=/opt/yunohost/ffsync
|
|
|
|
yunohost service remove "$app"
|
|
fi
|
|
|
|
# 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
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading source files..." --weight=6
|
|
|
|
install_sources
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring nginx"
|
|
|
|
if [ "$path_url" == "/" ]
|
|
then
|
|
# $finalnginxconf comes from ynh_add_nginx_config
|
|
# uwsgi_param is only needed for non-root installation
|
|
is_subpath="# "
|
|
else
|
|
is_subpath=" "
|
|
fi
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# CONFIGURE APPLICATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring application..."
|
|
|
|
# create config file syncserver.ini
|
|
rm "$final_path/syncserver.ini"
|
|
ln -s "/etc/uwsgi/apps-available/$app.ini" "$final_path/syncserver.ini"
|
|
|
|
# configure uwsgi
|
|
ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name'
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
ynh_script_progression --message="Securing files and directories..."
|
|
|
|
# Set permissions on app files
|
|
set_permissions
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
ynh_systemd_action --service_name "uwsgi-app@$app.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|