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
|
|
|
|
|
|
|
|
# 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
|
2017-07-03 21:07:56 +02:00
|
|
|
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-09-18 20:05:03 +02:00
|
|
|
# update config.php with 'max_length' line
|
|
|
|
case ${filesize: -1} in
|
|
|
|
g|G)
|
|
|
|
max_length=$((${filesize%?}*1024))
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
max_length=${filesize%?}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
sed -i "54i\$max_length=$max_length;" "$bozon_conf"
|
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
|
2017-07-03 21:07:56 +02:00
|
|
|
sudo yunohost app ssowatconf
|
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
|