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

88 lines
2.7 KiB
Bash

#!/bin/bash
set -eu
source _common.sh
source /usr/share/yunohost/helpers
# manage script failure
ynh_abort_if_errors
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
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)
# definie useful vars
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
bozon_conf="$final_path/config.php"
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
# 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
myynh_clean_source
[ -e "$TMPDIR/config.php" ] && rm "$TMPDIR/config.php"
cp -a "$TMPDIR/." "$final_path"
rm -R "$TMPDIR"
# Only add 'max_length' line in config.php if does not exist yet
if [ $(grep "max_length=" "$bozon_conf" | wc -l) -eq 0 ]; then
case ${filesize: -1} in
g|G)
max_length=$((${filesize%?}*1024))
;;
*)
max_length=${filesize%?}
;;
esac
sed -i "54i\$max_length=$max_length;" "$bozon_conf"
fi
# set permissions
myynh_set_permissions
# configure nginx settings
myynh_add_nginx_config
# copy and set php-fpm configuration
myynh_add_fpm_config
# if app is private, remove url to SSOWat conf from skipped_uris
if [ $is_public -eq 0 ]
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 "/"
fi
# Purge php sessions stored in /var/lib/php5/sessions
[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean