1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dendrite_ynh.git synced 2024-09-03 18:25:58 +02:00
dendrite_ynh/scripts/upgrade
2024-05-20 07:44:06 +02:00

184 lines
6.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --line_match="Dendrite is exiting now" --log_path="systemd"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if ! groups $app | grep -q 'ssl-cert'; then
adduser $app ssl-cert
fi
#=================================================
# GET CONFIG PANEL SETTINGS
#=================================================
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
domain=$(ynh_app_setting_get --app=$app --key=domain)
registration_disabled=$(ynh_app_setting_get --app=$app --key=registration_disabled)
disable_federation=$(ynh_app_setting_get --app=$app --key=disable_federation)
guests_disabled=$(ynh_app_setting_get --app=$app --key=guests_disabled)
registration_shared_secret=$(ynh_app_setting_get --app=$app --key=registration_shared_secret)
enable_registration_captcha=$(ynh_app_setting_get --app=$app --key=enable_registration_captcha)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# MIGRATION : Manage old settings
#=================================================
# Define $server_name if not already defined
if [ -z ${server_name:-} ]; then
server_name=$domain
ynh_app_setting_set --app=$app --key=server_name --value=$domain
fi
# Define $disable_federation if not already defined
if [ -z ${enable_registration_captcha:-} ]; then
enable_registration_captcha="false"
ynh_app_setting_set --app=$app --key=enable_registration_captcha --value=$enable_registration_captcha
fi
# Define $guests_disabled if not already defined
if [ -z ${guests_disabled:-} ]; then
guests_disabled="true"
ynh_app_setting_set --app=$app --key=guests_disabled --value=$guests_disabled
fi
# Define $registration_shared_secret if not already defined
if [ -z ${registration_shared_secret:-} ]; then
registration_shared_secret=""
ynh_app_setting_set --app=$app --key=registration_shared_secret --value=$registration_shared_secret
fi
# Load up registration variables
registration=$(ynh_app_setting_get --app=$app --key=registration)
if [ -z ${registration:-} ]; then
if [[ $registration_disabled = *"alse" ]]
then
really_enable_open_registration="--really-enable-open-registration"
else
really_enable_open_registration=""
fi
else
ynh_app_setting_delete --app=$app --key=registration
if [[ $registration == *"rue" || $registration -eq 1 ]]
then
registration_disabled="false"
really_enable_open_registration="--really-enable-open-registration"
disable_federation="true"
ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled
ynh_app_setting_set --app=$app --key=disable_federation --value=$disable_federation
else
registration_disabled="true"
really_enable_open_registration=""
disable_federation="false"
ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled
ynh_app_setting_set --app=$app --key=disable_federation --value=$disable_federation
fi
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/build" --keep="dendrite.yaml" --full_replace
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:root "$install_dir"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# BUILDING SOURCES AND SETTING UP THE SERVER
#=================================================
ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6
ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION
pushd "$install_dir/build"
# Build the sources
ynh_use_go
export PATH="$PATH"
export GOPATH="$install_dir/build/go"
export GOCACHE="$install_dir/build/.cache"
export CGO_ENABLED=1
ynh_exec_warn_less go build -trimpath -v -o "$install_dir/bin/" ./cmd/dendrite
ynh_exec_warn_less go build -trimpath -v -o "$install_dir/bin/" ./cmd/create-account
ynh_exec_warn_less go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys
popd
ynh_secure_remove --file="$install_dir/build"
ynh_remove_go
chown -R $app:root "$install_dir"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml"
chmod 400 "$install_dir/dendrite.yaml"
chown $app:$app "$install_dir/dendrite.yaml"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create .well-known redirection for access by federation
if yunohost --output-as plain domain list | grep -q "^$server_name$"
then
ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
fi
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls"
mkdir -p /var/log/$app
chown -R $app:root /var/log/$app
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last