2017-01-08 12:17:57 +01:00
|
|
|
#!/bin/bash
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2017-07-26 21:32:00 +02:00
|
|
|
set -eu
|
2017-07-03 21:07:56 +02:00
|
|
|
source _common.sh
|
2016-10-13 06:51:38 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-04-26 20:37:18 +02:00
|
|
|
|
2017-07-03 21:07:56 +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)
|
2017-07-03 21:07:56 +02:00
|
|
|
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)
|
2017-07-03 21:07:56 +02:00
|
|
|
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
|
2017-07-03 21:07:56 +02:00
|
|
|
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"
|
2017-07-03 21:07:56 +02:00
|
|
|
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
|
2017-09-22 19:33:28 +02:00
|
|
|
myynh_clean_source
|
|
|
|
[ -e "$TMPDIR/config.php" ] && rm "$TMPDIR/config.php"
|
|
|
|
cp -a "$TMPDIR/." "$final_path"
|
|
|
|
rm -R "$TMPDIR"
|
2016-04-26 20:39:15 +02:00
|
|
|
|
2017-09-23 09:32:18 +02:00
|
|
|
# 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
|
2017-09-18 20:05:03 +02:00
|
|
|
g|G)
|
|
|
|
max_length=$((${filesize%?}*1024))
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
max_length=${filesize%?}
|
|
|
|
;;
|
|
|
|
esac
|
2017-09-23 09:32:18 +02:00
|
|
|
sed -i "54i\$max_length=$max_length;" "$bozon_conf"
|
|
|
|
fi
|
2017-07-25 19:12:31 +02:00
|
|
|
|
2017-07-03 21:07:56 +02:00
|
|
|
# set permissions
|
2017-07-07 17:03:57 +02:00
|
|
|
myynh_set_permissions
|
2016-04-26 20:17:50 +02:00
|
|
|
|
|
|
|
# configure nginx settings
|
2017-07-03 21:07:56 +02:00
|
|
|
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
|
2017-07-03 21:07:56 +02:00
|
|
|
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
|
2017-07-03 21:07:56 +02:00
|
|
|
if [ $is_public -eq 0 ]
|
2016-04-26 20:17:50 +02:00
|
|
|
then
|
2017-07-03 21:07:56 +02:00
|
|
|
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
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2017-07-03 21:07:56 +02:00
|
|
|
# Purge php sessions stored in /var/lib/php5/sessions
|
|
|
|
[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
|