matrix-puppet-discord_ynh/scripts/upgrade
2024-03-29 15:41:58 +01:00

124 lines
4.9 KiB
Bash

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language)
#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
#REMOVEME? log_path=$(ynh_app_setting_get --app=$app --key=log_path)
#REMOVEME? etc_path=$(ynh_app_setting_get --app=$app --key=etc_path)
user_config_path="$etc_path/user.config.yaml"
pip_path="$install_dir/.pip"
#REMOVEME? app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading NodeJS..." --weight=9
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/source" --full_replace=1
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating configuration files..." --weight=1
# Create startup script
ynh_add_config --template="run.sh" --destination="$install_dir/run.sh"
chmod 750 "$install_dir/run.sh"
chown "$app:$app" "$install_dir/run.sh"
ynh_add_config --template="base.config.yaml" --destination="$install_dir/base.config.yaml"
chmod 400 "$install_dir/base.config.yaml"
chown "$app:$app" "$install_dir/base.config.yaml"
#=================================================
# INSTALL NODE DEPENDENCIES
#=================================================
ynh_script_progression --message="Building Node dependencies..." --weight=30
pushd "$install_dir/source"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" npx yarn install
popd
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
pushd "$install_dir/source"
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" NODE_ENV=production \
"$install_dir/run.sh "-r -f "$install_dir/$app.yaml"
popd
cp "$install_dir/$app.yaml" "$app_service_registration_path/$app.yaml"
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" \
|| ynh_die --message="Synapse can't restart with the appservice configuration"
ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="$app daemon for bridging Discord and Matrix messages"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last