1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rss-bridge_ynh.git synced 2024-09-03 20:25:51 +02:00
rss-bridge_ynh/scripts/upgrade
2020-03-31 05:07:25 +02:00

99 lines
2.9 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# Set app specific variables
app=$YNH_APP_INSTANCE_NAME
# Check destination directory
DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first."
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path_url)
path_url=$(ynh_normalize_url_path $path_url)
final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_restore_upgradebackup # restore it if the upgrade fails
}
ynh_abort_if_errors # Active trap to stop script execution if an error occurs
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Create tmp directory and fetch app inside
TMPDIR=$(ynh_mkdir_tmp)
extract_sources "$TMPDIR"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app # Create dedicated user if not existing
#=================================================
# SPECIFIC SETUP
#=================================================
# Remove last version (we don't keep whitelist)
ynh_secure_remove "$final_path"
# Install files and set permissions
mv "$TMPDIR" "$final_path"
# Set rights on directory
chown -R root: $final_path
chown -R $app: $final_path/cache
chmod 755 $final_path
# Enable every bridge
for i in $final_path/bridges/*.php ; do
echo $(basename $i) | sed "s|Bridge.php$||g" | tee -a $final_path/whitelist.txt
done
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
# Copy and set php-fpm configuration
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
ynh_replace_string "{POOLNAME}" "${app}" "$PKGDIR/conf/php-fpm.conf"
ynh_replace_string "{DESTDIR}" "${final_path}" "$PKGDIR/conf/php-fpm.conf"
ynh_replace_string "{USER}" "${app}" "$PKGDIR/conf/php-fpm.conf"
cp $PKGDIR/conf/php-fpm.conf "$phpfpm_conf"
# Set SSOwat rules
ynh_app_setting_set "$app" skipped_uris "/"
#=================================================
# RELOAD NGINX
#=================================================
systemctl restart php5-fpm
systemctl reload nginx