2017-07-16 12:51:05 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
admin=$(ynh_app_setting_get $app admin)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z $db_name ]; then # If db_name doesn't exist, create it
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
|
|
|
fi
|
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z $final_path ]; then
|
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-07-16 12:51:05 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2018-06-04 22:57:21 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2018-06-07 21:28:54 +02:00
|
|
|
# Create a temporary directory along with /user/plugin sub directory in it
|
2018-06-04 22:57:21 +02:00
|
|
|
tmpdir="$(mktemp -d)"
|
2018-06-09 14:02:58 +02:00
|
|
|
mkdir -p "$tmpdir/user/"
|
2018-06-04 22:57:21 +02:00
|
|
|
|
|
|
|
# Backup the app files in the temp dir
|
2018-06-09 14:02:58 +02:00
|
|
|
sudo cp -a "$final_path/index.php" "$tmpdir"
|
2018-06-04 22:57:21 +02:00
|
|
|
sudo cp -a "$final_path/.htaccess" "$tmpdir"
|
|
|
|
sudo cp -a "$final_path/user/config.php" "$tmpdir/user"
|
|
|
|
|
|
|
|
# Remove the app directory securely
|
|
|
|
ynh_secure_remove "$final_path"
|
2017-07-16 12:51:05 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
# Copy the app files from tmp to final_path
|
2018-06-09 14:02:58 +02:00
|
|
|
sudo cp -a "$tmpdir/index.php" "$final_path"
|
2018-06-04 22:57:21 +02:00
|
|
|
sudo cp -a "$tmpdir/.htaccess" "$final_path"
|
|
|
|
sudo cp -a "$tmpdir/user/config.php" "$final_path/user"
|
|
|
|
|
2019-01-04 16:15:48 +01:00
|
|
|
# The script "add_sso_conf.py" will just add en entry for the path "/admin" in the sso conf.json.persistent file in the cathegory "protected_urls".
|
|
|
|
cp ../conf/add_sso_conf.py $final_path
|
|
|
|
cp ../conf/remove_sso_conf.py $final_path
|
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/user/add_sso_conf.py"
|
|
|
|
ynh_replace_string "__PATH__" "$path_url" "$final_path/user/add_sso_conf.py"
|
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/user/remove_sso_conf.py"
|
|
|
|
ynh_replace_string "__PATH__" "$path_url" "$final_path/user/remove_sso_conf.py"
|
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
#remove tmp dir
|
|
|
|
sudo rm -Rf "$tmpdir"
|
2017-07-16 12:51:05 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2018-06-04 22:57:21 +02:00
|
|
|
ynh_add_nginx_config
|
2017-07-16 12:51:05 +02:00
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create $app
|
2017-07-16 12:51:05 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-06-04 22:57:21 +02:00
|
|
|
# PHP-FPM CONFIGURATION
|
2017-07-16 12:51:05 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
ynh_add_fpm_config
|
2017-07-16 12:51:05 +02:00
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
# Verify the checksum and backup the file if it's different
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/user/config.php"
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/user/config.php"
|
|
|
|
|
|
|
|
# Set right permissions for curl installation
|
|
|
|
chown -R $app: $final_path
|
2017-07-16 12:51:05 +02:00
|
|
|
|
2018-06-04 22:57:21 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2017-07-16 12:51:05 +02:00
|
|
|
|
2018-06-09 14:02:58 +02:00
|
|
|
|
2017-07-16 12:51:05 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo systemctl reload nginx
|