1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dendrite_ynh.git synced 2024-09-03 18:25:58 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 22:47:20 +02:00 committed by Alexandre Aubin
parent d743240b27
commit 51f9515321
10 changed files with 141 additions and 210 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*~ *~
*.sw[op] *.sw[op]
.DS_Store

View file

@ -16,7 +16,8 @@ admindoc = "https://github.com/matrix-org/dendrite/tree/master/docs"
code = "https://github.com/matrix-org/dendrite" code = "https://github.com/matrix-org/dendrite"
[integration] [integration]
yunohost = ">= 11.2.12" yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = false multi_instance = false

View file

@ -1,20 +1,7 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#================================================= #=================================================
go_version="1.21"
GO_VERSION="1.21"
psql_version=$PSQL_VERSION psql_version=$PSQL_VERSION
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,50 +1,41 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup "/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup "/etc/systemd/system/$app.service"
if yunohost --output-as plain domain list | grep -q "^$server_name$" if yunohost --output-as plain domain list | grep -q "^$server_name$"
then then
ynh_backup --src_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" ynh_backup "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
fi fi
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the PostgreSQL database..." ynh_print_info "Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql ynh_psql_dump_db > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -26,44 +20,40 @@ else
really_enable_open_registration="" really_enable_open_registration=""
fi fi
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --line_match="Dendrite is exiting now" --log_path="systemd" ynh_systemctl --service=$app --action="stop" --wait_until="Dendrite is exiting now" --log_path="systemd"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config ynh_config_change_url_nginx
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Updating systemd configuration..." --weight=1 ynh_script_progression "Updating systemd configuration..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_config_add_systemd
#=================================================
# GENERIC FINALISATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --line_match="Cleaning old notifications" --log_path="systemd" ynh_systemctl --service=$app --action="start" --wait_until="Cleaning old notifications" --log_path="systemd"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression "Change of URL completed for $app"

View file

@ -1,23 +1,18 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Stop script if errors # Stop script if errors
ynh_abort_if_errors #REMOVEME? ynh_abort_if_errors
get_registration_disabled() { get_registration_disabled() {
registration_disabled=$(ynh_app_setting_get --app $app --key registration_disabled) registration_disabled=$(ynh_app_setting_get --key registration_disabled)
echo "${registration_disabled}" echo "${registration_disabled}"
} }
set__registration_disabled() { set__registration_disabled() {
if [ "$registration_disabled" -eq "1" ] if [ "$registration_disabled" -eq "1" ]
then then
really_enable_open_registration="" really_enable_open_registration=""
@ -26,16 +21,15 @@ set__registration_disabled() {
fi fi
ynh_write_var_in_file --file=$install_dir/dendrite.yaml --key=registration_disabled --value="${registration_disabled}" ynh_write_var_in_file --file=$install_dir/dendrite.yaml --key=registration_disabled --value="${registration_disabled}"
domain=$(ynh_app_setting_get --app $app --key domain)
port_tls=$(ynh_app_setting_get --app $app --key port_tls) domain=$(ynh_app_setting_get --key domain)
port=$(ynh_app_setting_get --app $app --key port) port_tls=$(ynh_app_setting_get --key port_tls)
psql_version=$(ynh_app_setting_get --app $app --key psql_version) port=$(ynh_app_setting_get --key port)
ynh_add_systemd_config psql_version=$(ynh_app_setting_get --key psql_version)
ynh_systemd_action --service_name=$app --action="restart" --line_match="Starting external listener" --log_path="systemd" ynh_config_add_systemd
ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled ynh_systemctl --service=$app --action="restart" --wait_until="Starting external listener" --log_path="systemd"
ynh_app_setting_set --key=registration_disabled --value=$registration_disabled
} }
#================================================= #=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1 ynh_app_config_run $1

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -29,8 +23,8 @@ fi
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_app_setting_set --app=$app --key=server_name --value=$server_name ynh_app_setting_set --key=server_name --value=$server_name
ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --key=domain --value=$domain
#================================================= #=================================================
# ADD USER TO THE SSL-CERT GROUP # ADD USER TO THE SSL-CERT GROUP
@ -41,33 +35,32 @@ usermod -a -G ssl-cert $app
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 ynh_script_progression "Creating a PostgreSQL database..."
ynh_psql_execute_as_root --sql="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" ynh_psql_db_shell <<< "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=2 ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/build" ynh_setup_source --dest_dir="$install_dir/build"
chmod -R o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
chown -R $app:root "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root "$install_dir"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1 ynh_script_progression "Configuring NGINX web server..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create .well-known redirection for access by federation # Create .well-known redirection for access by federation
if yunohost --output-as plain domain list | grep -q "^$server_name$" if yunohost --output-as plain domain list | grep -q "^$server_name$"
then then
ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" ynh_config_add --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
fi fi
#================================================= #=================================================
@ -75,13 +68,13 @@ fi
#================================================= #=================================================
# BUILDING SOURCES AND SETTING UP THE SERVER # BUILDING SOURCES AND SETTING UP THE SERVER
#================================================= #=================================================
ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 ynh_script_progression "Building the sources (it will take some time)..."
ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION ynh_go_install
pushd "$install_dir/build" pushd "$install_dir/build"
# Build the sources # Build the sources
ynh_use_go
export GOPATH="$install_dir/build/go" export GOPATH="$install_dir/build/go"
export GOCACHE="$install_dir/build/.cache" 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/dendrite > /dev/null 2>&1
@ -89,10 +82,10 @@ pushd "$install_dir/build"
CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys > /dev/null 2>&1 CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys > /dev/null 2>&1
popd popd
ynh_secure_remove --file="$install_dir/build" ynh_safe_rm "$install_dir/build"
ynh_remove_go ynh_go_remove
ynh_script_progression --message="Generating the keys..." --weight=1 ynh_script_progression "Generating the keys..."
pushd "$install_dir" pushd "$install_dir"
# Generate a Matrix signing key for federation # Generate a Matrix signing key for federation
@ -102,27 +95,26 @@ pushd "$install_dir"
popd popd
# Set permissions to app files # Set permissions to app files
chown -R $app:root "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root "$install_dir"
#================================================= #=================================================
## SET STANDARD SETTINGS FROM DEFAULT CONFIG ## SET STANDARD SETTINGS FROM DEFAULT CONFIG
#================================================= #=================================================
guests_disabled="true" guests_disabled="true"
registration_shared_secret="" registration_shared_secret=""
enable_registration_captcha="false" enable_registration_captcha="false"
ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled ynh_app_setting_set --key=registration_disabled --value=$registration_disabled
ynh_app_setting_set --app=$app --key=disable_federation --value=$disable_federation ynh_app_setting_set --key=disable_federation --value=$disable_federation
ynh_app_setting_set --app=$app --key=guests_disabled --value=$guests_disabled ynh_app_setting_set --key=guests_disabled --value=$guests_disabled
ynh_app_setting_set --app=$app --key=registration_shared_secret --value=$registration_shared_secret ynh_app_setting_set --key=registration_shared_secret --value=$registration_shared_secret
ynh_app_setting_set --app=$app --key=enable_registration_captcha --value=$enable_registration_captcha ynh_app_setting_set --key=enable_registration_captcha --value=$enable_registration_captcha
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." ynh_script_progression "Adding $app's configuration..."
# Copy and modify the config file # Copy and modify the config file
ynh_add_config --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" ynh_config_add --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml"
chmod 400 "$install_dir/dendrite.yaml" chmod 400 "$install_dir/dendrite.yaml"
chown $app:$app "$install_dir/dendrite.yaml" chown $app:$app "$install_dir/dendrite.yaml"
@ -130,44 +122,42 @@ chown $app:$app "$install_dir/dendrite.yaml"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1 ynh_script_progression "Configuring $app's systemd service..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_config_add_systemd
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1 ynh_script_progression "Configuring log rotation..."
mkdir -p /var/log/$app mkdir -p /var/log/$app
chown -R $app:root /var/log/$app #REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root /var/log/$app
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_config_add_logrotate
# HACKY: Match the weirdly renamed rotated logs. # HACKY: Match the weirdly renamed rotated logs.
# Looking at you, matrix-org/dugong library # 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" ynh_replace --match="/var/log/$app/*.log" --replace="/var/log/$app/*.log.????-??-??" --file="/etc/logrotate.d/$app"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls" yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd" ynh_systemctl --service=$app --action="start" --wait_until="Starting external listener" --log_path="systemd"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -16,26 +10,26 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null if ynh_hide_warnings yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service integration..." --weight=1 ynh_script_progression "Removing $app service integration..."
yunohost service remove $app yunohost service remove $app
fi fi
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_config_remove_systemd
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_config_remove_logrotate
# Remove the well-known location # Remove the well-known location
ynh_secure_remove --file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" ynh_safe_rm "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -19,52 +13,51 @@ usermod -a -G ssl-cert $app
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:root "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root "$install_dir"
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=3 ynh_script_progression "Restoring the PostgreSQL database..."
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name ynh_psql_db_shell < "./db.sql""
#================================================= #=================================================
# RESTORE SYSTEM CONFIGURATIONS # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
if yunohost --output-as plain domain list | grep -q "^$server_name$" if yunohost --output-as plain domain list | grep -q "^$server_name$"
then then
ynh_restore_file --origin_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" ynh_restore "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
fi fi
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable $app.service --quiet
yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls" yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls"
mkdir -p /var/log/$app mkdir -p /var/log/$app
chown -R $app:root /var/log/$app #REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root /var/log/$app
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd" ynh_systemctl --service=$app --action="start" --wait_until="Starting external listener" --log_path="systemd"
ynh_systemd_action --service_name=nginx --action=reload ynh_systemctl --service=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

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