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

106 lines
3.6 KiB
Text
Raw Normal View History

#!/bin/bash
2016-03-23 19:30:43 +01:00
2017-07-26 21:32:00 +02:00
set -eu
source _common.sh
2016-10-13 06:51:38 +02:00
source /usr/share/yunohost/helpers
2016-04-26 20:37:18 +02:00
# manage script failure
ynh_abort_if_errors
2016-04-26 20:17:50 +02:00
# retrieve arguments
2016-10-13 06:51:38 +02:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
2016-10-13 06:51:38 +02:00
is_public=$(ynh_app_setting_get "$app" is_public)
filesize=$(ynh_app_setting_get "$app" filesize)
language=$(ynh_app_setting_get "$app" language)
admin_user=$(ynh_app_setting_get "$app" admin_user)
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
2016-04-26 20:17:50 +02:00
# definie useful vars
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
bozon_conf="$final_path/config.php"
2017-07-25 19:12:31 +02:00
bozon_auto_dropzone_php="$final_path/core/auto_dropzone.php"
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf"
# use prior backup and restore on error only if backup feature exists on installed instance
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_backup_after_failed_upgrade
}
fi
# retrieve & save real/right value if argument was not saved as a app setting in a previous realease
if [ -z "$filesize" ]; then # in old script filesize was not saved as a setting
filesize=$(cat "$nginx_conf" | grep -Po "client_max_body_size \K.*?(?=;)")
2016-10-13 06:51:38 +02:00
ynh_app_setting_set "$app" filesize "$filesize"
fi
if [ -z "$language" ]; then # in old script language was not saved as a setting
language=$(cat "$bozon_conf" | grep -Po "default_language='\K.*?(?=')")
ynh_app_setting_set "$app" language "$language"
fi
if [ "$is_public" = "Yes" ]; then # in old script is_public was not a boolean
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 [ -z "$backup_core_only" ]; then # in old script backup_core_only was not a setting
ynh_app_setting_set "$app" backup_core_only 1
fi
# add required packages
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
# create a dedicated system user
ynh_system_user_create "$app"
# download & unpack bozon
TMPDIR=$(mktemp -d)
ynh_setup_source "$TMPDIR"
# clean & copy files needed to final folder
sudo find "$TMPDIR" -type f -name ".htaccess" | xargs sudo rm
if [ -e "$TMPDIR/.gitignore" ]; then
for f in $(sudo cat "$TMPDIR/.gitignore") ; do
[ -e "$TMPDIR$f" ] && sudo rm -R "$TMPDIR$f"
done
sudo rm "$TMPDIR/.gitignore"
fi
[ -e "$TMPDIR/config.php" ] && sudo rm "$TMPDIR/config.php"
sudo cp -a "$TMPDIR/." "$final_path"
sudo rm -R "$TMPDIR"
2016-04-26 20:39:15 +02:00
2017-07-25 19:12:31 +02:00
# update auto_dropzone.php
myynh_update_bozon_auto_dropzone
# set permissions
2017-07-07 17:03:57 +02:00
myynh_set_permissions
2016-04-26 20:17:50 +02:00
# configure nginx settings
myynh_add_nginx_config
2016-03-23 19:30:43 +01:00
2016-05-23 20:59:08 +02:00
# copy and set php-fpm configuration
myynh_add_fpm_config
2016-05-23 20:59:08 +02:00
2016-04-26 20:17:50 +02:00
# if app is private, remove url to SSOWat conf from skipped_uris
if [ $is_public -eq 0 ]
2016-04-26 20:17:50 +02:00
then
ynh_app_setting_delete "$app" unprotected_regex # in old script unprotected_regex was used in place of protected_regex
# escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html)
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
pathluaregex=$([ "$path_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$"
ynh_app_setting_set "$app" protected_regex "$regexList"
else
ynh_app_setting_set "$app" unprotected_uris "/"
2016-04-26 20:17:50 +02:00
fi
sudo yunohost app ssowatconf
2016-03-23 19:30:43 +01:00
# Purge php sessions stored in /var/lib/php5/sessions
[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean