#! /bin/bash # Exit on command errors and treat unset variables as an error set -eu # Source YunoHost helpers source /usr/share/yunohost/helpers # retrieve arguments app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) is_public=$(ynh_app_setting_get "$app" is_public) filesize=$(ynh_app_setting_get "$app" filesize) # definie useful vars parent_path=/var/www data_path=/home/yunohost.app/"$app" final_path=$parent_path/"$app" if [ -z "$filesize" ] 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.*(?=;)') ynh_app_setting_set "$app" filesize "$filesize" fi # 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 ynh_app_setting_set "$app" version "$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/BoZoN-"$upstream_version"/* "$final_path" # configure nginx settings nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "$nginx_conf" # copy and set php-fpm configuration postsize=${filesize%?}.1${filesize: -1} phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" 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 sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf ## copy final and set permissions 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 ynh_app_setting_delete "$app" unprotected_uris ynh_app_setting_set "$app" unprotected_regex \ "${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