1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flarum_ynh.git synced 2024-09-03 18:36:24 +02:00
flarum_ynh/scripts/upgrade

378 lines
13 KiB
Text
Raw Normal View History

2016-10-05 19:44:08 +02:00
#!/bin/bash
2018-02-15 21:58:56 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-10-05 19:44:08 +02:00
2018-02-15 21:58:56 +01:00
source _common.sh
source /usr/share/yunohost/helpers
2017-02-22 16:51:47 +01:00
2018-02-15 21:58:56 +01:00
#=================================================
2019-08-24 12:54:18 +02:00
# LOAD SETTINGS
2018-02-15 21:58:56 +01:00
#=================================================
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Loading installation settings..." --time --weight=1
2016-10-05 19:44:08 +02:00
2018-02-15 21:58:56 +01:00
app=$YNH_APP_INSTANCE_NAME
2016-10-05 19:44:08 +02:00
2019-08-24 12:54:18 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
language=$(ynh_app_setting_get --app=$app --key=language)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
old_project_version=$(ynh_app_setting_get --app=$app --key=project_version)
old_core_version=$(ynh_app_setting_get --app=$app --key=core_version)
old_ssowat_version=$(ynh_app_setting_get --app=$app --key=ssowat_version)
bazaar_extension=$(ynh_app_setting_get --app=$app --key=bazaar_extension)
#=================================================
# CHECK VERSION
#=================================================
2018-02-15 21:58:56 +01:00
2019-08-24 12:54:18 +02:00
### This helper will compare the version of the currently installed app and the version of the upstream package.
### $upgrade_type can have 2 different values
### - UPGRADE_APP if the upstream app version has changed
### - UPGRADE_PACKAGE if only the YunoHost package has changed
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
upgrade_type=$(ynh_check_app_version_changed)
2018-02-15 21:58:56 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
2018-02-15 21:58:56 +01:00
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
2019-08-24 12:54:18 +02:00
ynh_app_setting_set --app=$app --key=is_public --value=1
2018-02-15 21:58:56 +01:00
is_public=1
elif [ "$is_public" = "No" ]; then
2019-08-24 12:54:18 +02:00
ynh_app_setting_set --app=$app --key=is_public --value=0
2018-02-15 21:58:56 +01:00
is_public=0
fi
# If db_name doesn't exist, create it
2019-08-24 12:54:18 +02:00
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
2018-02-15 21:58:56 +01:00
fi
# If final_path doesn't exist, create it
2019-08-24 12:54:18 +02:00
if [ -z "$final_path" ]; then
2018-02-15 21:58:56 +01:00
final_path=/var/www/$app
2019-08-24 12:54:18 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2018-02-15 21:58:56 +01:00
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
2018-02-15 21:58:56 +01:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
2019-08-24 12:54:18 +02:00
# N.B. : this is for app installations before YunoHost 2.7
# where this value might be something like /foo/ or foo/
# instead of /foo ....
# If nobody installed your app before 2.7, then you may
# safely remove this line
path_url=$(ynh_normalize_url_path --path_url=$path_url)
2018-02-15 21:58:56 +01:00
#=================================================
# STANDARD UPGRADE STEPS
2019-08-24 12:54:18 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
if [ $path_url = "/" ]; then
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
else
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
fi
ynh_install_app_dependencies $pkg_dependencies
2018-02-15 21:58:56 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-08-24 12:54:18 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
2016-10-05 19:44:08 +02:00
2019-08-24 12:54:18 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
2018-02-15 21:58:56 +01:00
2019-08-24 12:54:18 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
2018-02-15 21:58:56 +01:00
#=================================================
# COMPOSER UPGRADE
#=================================================
2018-02-18 11:06:21 +01:00
if ! type "$final_path/composer.phar" > /dev/null; then
2019-08-24 12:54:18 +02:00
ynh_install_composer $php_version $final_path
2017-02-22 16:51:47 +01:00
fi
2018-02-15 21:58:56 +01:00
#=================================================
# FLARUM UPGRADE
#=================================================
# Downward compatibility: remove the v before version number
2019-08-24 12:54:18 +02:00
if [[ $old_project_version == "v*" ]]; then $old_project_version = ${old_project_version:1}; fi
# Check if upgrade of Flarum core is needed
2019-08-24 12:54:18 +02:00
if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo true) ]]; then
2018-08-13 16:23:15 +02:00
# Upgrade Flarum
2019-08-24 12:54:18 +02:00
ynh_composer_exec $app $php_version $final_path "require -n flarum/core:$project_version"
# Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2
2019-08-24 12:54:18 +02:00
if [[ $project_version == "0.1.0-beta.7.2" ]]; then
2018-11-11 21:58:15 +01:00
curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k
fi
2018-08-13 16:23:15 +02:00
pushd $final_path
2019-08-24 12:54:18 +02:00
exec_as $app php flarum cache:clear
2018-08-13 16:23:15 +02:00
popd
2019-08-24 12:54:18 +02:00
ynh_print_info "Flarum has been updated to version $project_version."
upgraded_flarum=true
2018-08-13 16:23:15 +02:00
else
ynh_print_info "Flarum does not need updating."
upgraded_flarum=false
2018-08-13 16:23:15 +02:00
fi
2018-02-15 21:58:56 +01:00
# Check if upgrade of SSOwat extension is needed
2019-08-24 12:54:18 +02:00
if [[ $(dpkg --compare-versions $old_ssowat_version lt $ssowat_version && echo true) || -z $old_ssowat_version ]]; then
# Install and activate the SSOwat auth extension
2019-08-24 12:54:18 +02:00
install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
# Configure SSOwat auth extension
ssowatdomain=$(</etc/yunohost/current_host)
sql_command="INSERT IGNORE INTO \`settings\` (\`key\`, \`value\`) VALUES ('tituspijean-auth-ssowat.domain', '$ssowatdomain'), ('tituspijean-auth-ssowat.onlyUse', '0');"
ynh_mysql_execute_as_root "$sql_command" $db_name
2018-11-11 22:13:30 +01:00
ynh_print_info "SSOwat extension has been updated and configured."
upgraded_ssowat=true
else
ynh_print_info "SSOwat extension does not need updating."
2018-11-11 22:13:30 +01:00
upgraded_ssowat=false
fi
2018-03-05 15:28:04 +01:00
2018-09-11 13:03:31 +02:00
if [ $bazaar_extension -eq 1 ]; then
2018-08-13 16:23:15 +02:00
install_and_activate_extension $app $final_path $db_name "flagrow/bazaar" "flagrow-bazaar"
ynh_print_info "Bazaar extension has been installed."
2018-08-13 16:23:15 +02:00
fi
2019-08-24 12:54:18 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R $app: $final_path
chown -R $app:www-data $final_path/storage
sudo chmod -R 0775 $final_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --time --last
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
2018-02-15 21:58:56 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2018-02-18 11:06:21 +01:00
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
if [ $path_url = "/" ]; then
2019-08-24 12:54:18 +02:00
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
2018-02-18 11:06:21 +01:00
else
2019-08-24 12:54:18 +02:00
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
2018-02-18 11:06:21 +01:00
fi
2018-02-15 21:58:56 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
2016-10-05 19:44:08 +02:00
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# See install script
ynh_app_setting_set "$app" unprotected_uris "/"
fi
2018-02-15 21:58:56 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions
2019-08-24 12:54:18 +02:00
chown -R $app: $final_path
chown -R $app:www-data $final_path/storage
2018-02-15 21:58:56 +01:00
sudo chmod -R 0775 $final_path
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx
#===================================================
# STORE SETTINGS
#===================================================
if [ $upgraded_flarum ]; then
2019-08-24 12:54:18 +02:00
ynh_app_setting_set $app project_version $project_version
fi
if [ $upgraded_ssowat ]; then
2019-08-24 12:54:18 +02:00
ynh_app_setting_set $app ssowat_version $ssowat_version
fi