mirror of
https://github.com/YunoHost-Apps/dendrite_ynh.git
synced 2024-09-03 18:25:58 +02:00
174 lines
6.4 KiB
Bash
174 lines
6.4 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_install_go
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
# Allow or deny registration based on is_public
|
|
if [ "$registration" -eq "1" ]
|
|
then
|
|
registration_disabled="false"
|
|
really_enable_open_registration="--really-enable-open-registration"
|
|
disable_federation="true"
|
|
else
|
|
registration_disabled="true"
|
|
really_enable_open_registration=""
|
|
disable_federation="false"
|
|
fi
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
|
|
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
#=================================================
|
|
# ADD USER TO THE SSL-CERT GROUP
|
|
#=================================================
|
|
|
|
usermod -a -G ssl-cert $app
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=2
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/build"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:root "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --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
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# 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 GOPATH="$install_dir/build/go"
|
|
export GOCACHE="$install_dir/build/.cache"
|
|
CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/dendrite > /dev/null 2>&1
|
|
CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/create-account > /dev/null 2>&1
|
|
CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys > /dev/null 2>&1
|
|
popd
|
|
|
|
ynh_secure_remove --file="$install_dir/build"
|
|
ynh_remove_go
|
|
|
|
ynh_script_progression --message="Generating the keys..." --weight=1
|
|
|
|
pushd "$install_dir"
|
|
# Generate a Matrix signing key for federation
|
|
./bin/generate-keys --private-key matrix_key.pem
|
|
# Generate a self-signed certificate
|
|
./bin/generate-keys --tls-cert server.crt --tls-key server.key
|
|
popd
|
|
|
|
# Set permissions to app files
|
|
chown -R $app:root "$install_dir"
|
|
|
|
#=================================================
|
|
## SET STANDARD SETTINGS FROM DEFAULT CONFIG
|
|
#=================================================
|
|
guests_disabled="true"
|
|
registration_shared_secret=""
|
|
enable_registration_captcha="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
|
|
ynh_app_setting_set --app=$app --key=guests_disabled --value=$guests_disabled
|
|
ynh_app_setting_set --app=$app --key=registration_shared_secret --value=$registration_shared_secret
|
|
ynh_app_setting_set --app=$app --key=enable_registration_captcha --value=$enable_registration_captcha
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..."
|
|
|
|
# Copy and modify the config file
|
|
ynh_add_config --template="../conf/dendrite.yaml" --destination="$install_dir/dendrite.yaml"
|
|
|
|
chmod 400 "$install_dir/dendrite.yaml"
|
|
chown $app:$app "$install_dir/dendrite.yaml"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
mkdir -p /var/log/$app
|
|
chown -R $app:root /var/log/$app
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate
|
|
# HACKY: Match the weirdly renamed rotated logs.
|
|
# Looking at you, matrix-org/dugong library
|
|
ynh_replace_string --match_string="/var/log/$app/*.log" --replace_string="/var/log/$app/*.log.????-??-??" --target_file="/etc/logrotate.d/$app"
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|