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
2016-09-05 21:11:16 +02:00

86 lines
3.3 KiB
Bash

#! /bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Source YunoHost helpers
source /usr/share/yunohost/helpers
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
# retrieve arguments
if [ $ynh_version = "2.4" ]; then
app=$YNH_APP_INSTANCE_NAME
else
app=bozon
fi
path=$(sudo yunohost app setting $app path)
upstream_version=$(sudo yunohost app setting $app version)
is_public=$(sudo yunohost app setting $app is_public)
filesize=$(sudo yunohost app setting $app filesize)
domain=$(sudo yunohost app setting $app domain)
if [ "${#filesize}" -eq 0 ]
then # in old script filesize was not saved as an setting
filesize=$(cat /etc/nginx/conf.d/$domain.d/$app.conf | grep -Po 'client_max_body_size \K.*(?=;)')
sudo yunohost app setting $app filesize -v "$filesize"
fi
# definie useful vars
parent_path=/var/www
data_path=/home/yunohost.app/$app
final_path=$parent_path/$app
# add required packages
ynh_package_install_from_equivs ../conf/${app}-deps.control || ynh_die "Unable to install dependencies"
# retrieve upstream_version version of bozon
upstream_version=$(cat ../conf/upstream_version)
# save app settings
sudo yunohost app setting $app version -v "$upstream_version"
# download upstream_version version of bozon
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/$upstream_version.zip -P /tmp
sudo unzip -oq /tmp/$upstream_version.zip -d /tmp
sudo rsync -avz --exclude="config.php" --exclude=".htaccess" /tmp/$upstream_version/* $final_path
# configure nginx settings
## path
folder_path=${path%/}
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
## file upload size limit
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
## copy final
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# copy and set php-fpm configuration
## path
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
## file upload size limit
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
postsize=${filesize%?}.1${filesize: -1}
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
## copy final and set permissions
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf
sudo chmod 644 $phpfpm_conf
# if app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ];
then
# 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=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
# redirect to SSOwat login in
sudo yunohost app setting $app unprotected_uris -d
sudo yunohost app setting $app unprotected_regex -v "$domainluaregex$pathluaregex/index.php%?f=.+$","$domainluaregex$pathluaregex/index.php%?zipfolder=.+$","$domainluaregex$pathluaregex/private/temp/.+%.zip$","$domainluaregex$pathluaregex/core/js/.*$","$domainluaregex$pathluaregex/templates/.*$"
fi
# Restart services
sudo service php5-fpm restart || true
sudo service nginx restart || true
sudo yunohost app ssowatconf