#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
# remove the 'https://' part
default_matrix_server=${default_matrix_server#*://}
# remove any trailing slash
default_matrix_server=${default_matrix_server%/}
ynh_app_setting_set --key=default_matrix_server --value="$default_matrix_server"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression "Setting up source files..."
ynh_setup_source --dest_dir="$install_dir"
# remove potential trailing slash to avoid double slashes
path_without_trailing_slash=${path%/}
ynh_replace --match="" --replace="" --file="$install_dir/index.html"
# patching main.dart.js to replace the default matrix server
ynh_replace --match="=\"matrix.org\"" --replace="=\"$default_matrix_server\"" --file="$install_dir/main.dart.js"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression "Adding system configurations related to $app..."
ynh_config_add_nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression "Installation of $app completed"