#!/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 # 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 #================================================= # CHECK THE PATH #================================================= # Normalize the URL path syntax path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # Download, check integrity, uncompress and patch the source from app.src # Create a temporary directory along with /user/plugin sub directory in it tmpdir="$(mktemp -d)" mkdir -p "$tmpdir/user/" # Backup the app files in the temp dir sudo cp -a "$final_path/index.php" "$tmpdir" 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" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" # Copy the app files from tmp to final_path sudo cp -a "$tmpdir/index.php" "$final_path" sudo cp -a "$tmpdir/.htaccess" "$final_path" sudo cp -a "$tmpdir/user/config.php" "$final_path/user" # 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/add_sso_conf.py" if [ "$path_url" != "/" ]; then ynh_replace_string "__PATH__" "$path_url" "$final_path/add_sso_conf.py" ynh_replace_string "__PATH__" "$path_url" "$final_path/remove_sso_conf.py" else ynh_replace_string "__PATH__" "" "$final_path/add_sso_conf.py" ynh_replace_string "__PATH__" "" "$final_path/remove_sso_conf.py" fi ynh_replace_string "__DOMAIN__" "$domain" "$final_path/remove_sso_conf.py" #remove tmp dir sudo rm -Rf "$tmpdir" #================================================= # NGINX CONFIGURATION #================================================= # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= # Create a system user ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= # Create a dedicated php-fpm config ynh_add_fpm_config # 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 #================================================= # SETUP SSOWAT #================================================= ynh_app_setting_set $app unprotected_uris "/" #================================================= # RELOAD NGINX #================================================= sudo systemctl reload nginx