Manifestv2

This commit is contained in:
Salamandar 2024-03-29 15:26:17 +01:00
parent fabdf08036
commit eaae264103
17 changed files with 244 additions and 512 deletions

View file

@ -1,25 +0,0 @@
;; Test complet
; pre-install
sudo yunohost tools update apps
sudo yunohost app install https://github.com/YunoHost-Apps/synapse_ynh/ -a "domain=$domain&server_name=$server_name&is_free_registration=$is_free_registration&jitsi_server=$jitsi_server" --force
; Manifest
domain="domain.tld"
port="8343"
synapsenumber=1
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=0
setup_nourl=1
setup_private=0
setup_public=0
upgrade=1
backup_restore=1
multi_instance=1
port_already_use=1
change_url=0
actions=0
config_panel=0
;;; Options
Email=
Notification=none

View file

@ -1,7 +0,0 @@
SOURCE_URL=https://gitlab.com/mx-puppet/discord/mx-puppet-discord/-/archive/fd4402268e9a8b942ca632f3337702862e06d24f/mx-puppet-discord-master.tar.gz
SOURCE_SUM=b0edc4dfe9d3670eb8b53dc229a8fd7fb794ada5fe1f3d3ba4c38b54ce5ca176
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -142,7 +142,7 @@ logging:
# Log files are rotated daily by default
files:
# Log file path
- file: "__LOG_PATH__/bridge.log" # Will capture logs from DiscordBot
- file: "/var/log/__APP__/bridge.log" # Will capture logs from DiscordBot
# Log level for this file
#
# Allowed values starting with most verbose:

View file

@ -3,11 +3,11 @@
set -o errexit
set -o nounset
echo <<EOF > __FINALPATH__/config.yaml
echo <<EOF > __INSTALL_DIR__/config.yaml
# /!\ FILE GENERATED AUTOMATICALLY BEFORE EACH SERVICE RESTART
# CONSIDER EDITING /etc/__APP__/user.config.yaml
EOF
__PIP_PATH__/bin/yq -y -s '.[0] * .[1]' __FINALPATH__/base.config.yaml /etc/__APP__/user.config.yaml > __FINALPATH__/config.yaml
__INSTALL_DIR__/venv/bin/yq -y -s '.[0] * .[1]' __INSTALL_DIR__/base.config.yaml /etc/__APP__/user.config.yaml > __INSTALL_DIR__/config.yaml
__YNH_NPM__ start -- -c config.yaml $@
__YNH_NPM__ start -- -c config.yaml "$@"

View file

@ -8,8 +8,8 @@ Environment=NODE_ENV=production
Environment="__YNH_NODE_LOAD_PATH__"
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
ExecStart=__FINALPATH__/run.sh -f __APP__.yaml
WorkingDirectory=__INSTALL_DIR__/
ExecStart=__INSTALL_DIR__/run.sh -f __APP__.yaml
StandardOutput=syslog
StandardError=syslog

View file

@ -1,6 +1,6 @@
# You can edit this file.
# This will override the configuration contained in the __FINALPATH__/base.config.yaml file.
# Don't hesitate to take a look at __FINALPATH__/sample.config.yaml to see all the available options.
# This will override the configuration contained in the __INSTALL_DIR__/base.config.yaml file.
# Don't hesitate to take a look at __INSTALL_DIR__/sample.config.yaml to see all the available options.
# Then, in order to take into account the changes, run: systemctl restart __APP__
provisioning:

View file

@ -1,47 +0,0 @@
{
"name": "Matrix-Discord bridge",
"id": "matrix-puppet-discord",
"packaging_format": 1,
"description": {
"en": "Discord puppeting bridge for Matrix/Synapse.",
"fr": "Passerelle Discord pour Matrix/Synapse."
},
"version": "0.1.7~ynh4",
"url": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord",
"upstream": {
"license": "Apache-2.0",
"website": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord",
"admindoc": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord",
"code": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord"
},
"license": "Apache-2.0",
"maintainer": {
"name": "fflorent",
"email": "florent.git@zeteo.me"
},
"requirements": {
"yunohost": ">= 11.1"
},
"multi_instance": true,
"services": [
"postgresql"
],
"arguments": {
"install": [
{
"name": "synapsenumber",
"type": "string",
"ask": {
"en": "Choose the local synapse instance number to communicate with the Discord-Matrix bridge",
"fr": "Choisissez le numéro de l'instance synapse qui doit communiquer avec la passerelle Discord-Matrix"
},
"example": "2 (for instance synapse__2)",
"help": {
"en": "If you installed synapse only once time, then leave default value 1.",
"fr": "Si vous n'avez installé qu'une fois synapse, gardez la valeur par défaut 1."
},
"default": "1"
}
]
}
}

65
manifest.toml Normal file
View file

@ -0,0 +1,65 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "matrix-puppet-discord"
name = "Matrix-Discord bridge"
description.en = "Discord puppeting bridge for Matrix/Synapse."
description.fr = "Passerelle Discord pour Matrix/Synapse."
version = "0.1.7~ynh5"
maintainers = ["fflorent"]
[upstream]
license = "Apache-2.0"
admindoc = "https://gitlab.com/mx-puppet/discord/mx-puppet-discord"
code = "https://gitlab.com/mx-puppet/discord/mx-puppet-discord"
fund = "https://liberapay.com/Sorunome/donate"
[integration]
yunohost = ">= 11.2"
architectures = "all"
multi_instance = true
ldap = "not_releant"
sso = "not_releant"
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install.synapsenumber]
ask.en = "Choose the local synapse instance number to communicate with the Discord-Matrix bridge"
ask.fr = "Choisissez le numéro de l'instance synapse qui doit communiquer avec la passerelle Discord-Matrix"
help.en = "If you installed synapse only once time, then leave default value 1."
help.fr = "Si vous n'avez installé qu'une fois synapse, gardez la valeur par défaut 1."
type = "string"
example = "2 (for instance synapse__2)"
default = "1"
[resources]
[resources.sources.main]
url = "https://gitlab.com/mx-puppet/discord/mx-puppet-discord/-/archive/fd4402268e9a8b942ca632f3337702862e06d24f/mx-puppet-discord-master.tar.gz"
sha256 = "b0edc4dfe9d3670eb8b53dc229a8fd7fb794ada5fe1f3d3ba4c38b54ce5ca176"
autoupdate.strategy = "latest_gitlab_tag"
[resources.system_user]
[resources.install_dir]
[resources.permissions]
[resources.ports]
[resources.apt]
packages = [
"postgresql",
"libcairo2-dev",
"libpango1.0-dev",
"libjpeg-dev",
"libgif-dev",
"librsvg2-dev",
]
[resources.database]
type = "postgresql"

View file

@ -4,16 +4,21 @@
# COMMON VARIABLES
#=================================================
# Node version
NODEJS_VERSION=12
# dependencies used by the app (must be on a single line)
pkg_dependencies="postgresql libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev"
#=================================================
# PERSONAL HELPERS
#=================================================
_venv_install() {
ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv"
venvpy="$install_dir/venv/bin/python3"
ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip
ynh_exec_as "$app" "$venvpy" -m pip install setuptools wheel pyyaml
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,29 +8,6 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
log_path=$(ynh_app_setting_get --app=$app --key=log_path)
etc_path=$(ynh_app_setting_get --app=$app --key=etc_path)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@ -42,10 +17,10 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$install_dir"
#=================================================
# BACKUP SYSTEMD
# BACKUP SYSTEM FILES
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
@ -54,7 +29,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="$log_path"
ynh_backup --src_path="/var/log/$app"
ynh_backup --src_path="$etc_path"
#=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,141 +8,62 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
# INITIALIZE AND STORE SETTINGS
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER
app=$YNH_APP_INSTANCE_NAME
final_path=/opt/yunohost/$app
if [ $synapsenumber -eq "1" ]
then
synapse_instance="synapse"
if [ $synapsenumber -eq "1" ]; then
synapse_instance="synapse"
else
synapse_instance="synapse__$synapsenumber"
synapse_instance="synapse__$synapsenumber"
fi
synapse_config_path="/etc/matrix-$synapse_instance"
# Check Synapse is installed or die early
if [ ! -d $synapse_config_path ]
then
ynh_die --message="Could not find $synapse_config_path config directory. Ensure that you installed Matrix Synapse first and that you entered a correct \"synapse instance number\""
if [ ! -d "$synapse_config_path" ]; then
ynh_die --message="Could not find $synapse_config_path config directory. Ensure that you installed Matrix Synapse first and that you entered a correct \"synapse instance number\""
fi
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
app_service_registration_path="/etc/matrix-$synapse_instance/app-service"
log_path="/var/log/$app"
base_config_path="$final_path/base.config.yaml"
base_config_path="$install_dir/base.config.yaml"
user_config_path="/etc/$app/user.config.yaml"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=log_path --value=$log_path
ynh_app_setting_set --app=$app --key=app_service_registration_path --value=$app_service_registration_path
ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port=$(ynh_find_port --port=8434)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=4
ynh_script_progression --message="Installing NodeJS..." --weight=4
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=10
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
ynh_setup_source --dest_dir="$install_dir/source"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL NODE DEPENDENCIES
#=================================================
ynh_script_progression --message="Building Node dependencies..." --weight=30
pushd "$final_path"
ynh_use_nodejs
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH npx yarn install
popd
#=================================================
# SETUP PIP (FOR YQ)
#=================================================
ynh_script_progression --message="Install yq..." --weight=1
pip_path=$final_path/.pip
python3 -m venv $pip_path
$pip_path/bin/pip3 install yq
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# ADD CONFIGURATION FILES
#=================================================
ynh_script_progression --message="Adding configuration files..." --weight=1
# Create startup script
ynh_add_config --template="run.sh" --destination="$install_dir/run.sh"
chmod 750 "$install_dir/run.sh"
# TODO Add a way to override the config.yaml file
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"
etc_path=$(dirname $user_config_path)
ynh_app_setting_set --app=$app --key=etc_path --value=$etc_path
@ -153,74 +72,67 @@ chown "$app:$app" "$etc_path"
any_account_of_domain="@.*:${domain//\./\\\.}"
# TODO Add a way to override the config.yaml file
ynh_add_config --template="base.config.yaml" --destination="$base_config_path"
ynh_add_config --template="user.config.yaml" --destination="$user_config_path"
chmod 400 "$base_config_path"
chown $app:$app "$base_config_path"
chmod 600 "$user_config_path"
chown $app:$app "$user_config_path"
chown "$app:$app" "$user_config_path"
#=================================================
# SETUP SYSTEMD
# INSTALL NODE DEPENDENCIES
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_script_progression --message="Building Node dependencies..." --weight=30
# Create startup script
ynh_add_config --template="../conf/run.sh" --destination="$final_path/run.sh"
pushd "$install_dir/source"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" npx yarn install
popd
chmod 750 "$final_path/run.sh"
chown "$app:$app" "$final_path/run.sh"
#=================================================
# SETUP PIP (FOR YQ)
#=================================================
ynh_script_progression --message="Install yq..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
_venv_install
"$venvpy" -m pip install yq
#=================================================
# CREATE LOG DIR
#=================================================
mkdir -p -m 700 "$log_path"
chown $app:$app "$log_path"
chown "$app:$app" "$log_path"
#=================================================
# REGISTER MODULE IN SYNAPSE
#=================================================
ynh_script_progression --message="Register module in Synapse" --weight=1
pushd "$final_path"
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production $final_path/run.sh -r -f "$app.yaml"
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 "$final_path/$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"
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"
#=================================================
# GENERIC FINALIZATION
# SYSTEM CONFIGURATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages"
# 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 a systemd service..." --weight=1
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
ynh_script_progression --message="Sending a readme for the admin..."
# ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients=$admin_email --type='install'
ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,87 +8,34 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
log_path=$(ynh_app_setting_get --app=$app --key=log_path)
etc_path=$(ynh_app_setting_get --app=$app --key=etc_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# 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
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
yunohost service remove "$app"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove nodejs version if not used by another app
ynh_remove_nodejs
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..." --weight=1
# Remove the log files
ynh_secure_remove --file="$log_path"
ynh_secure_remove --file="/var/log/$app"
ynh_secure_remove --file="$etc_path"
#=================================================
# GENERIC FINALIZATION
# REMOVE DEPENDENCIES
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
ynh_script_progression --message="Uninstalling NodeJS..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
# Remove nodejs version if not used by another app
ynh_remove_nodejs
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -11,129 +9,68 @@ source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling NodeJS..." --weight=4
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
ynh_use_nodejs
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
ynh_restore_file --origin_path="$install_dir"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=4
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_use_nodejs
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=20
ynh_psql_test_if_first_run
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
log_path=$(ynh_app_setting_get --app=$app --key=log_path)
ynh_restore_file --origin_path="$log_path"
chown $app:$app "$log_path"
ynh_restore_file --origin_path="/var/log/$app"
chown "$app:$app" "/var/log/$app"
etc_path=$(ynh_app_setting_get --app=$app --key=etc_path)
ynh_restore_file --origin_path="$etc_path"
chown $app:$app "$etc_path"
chown "$app:$app" "$etc_path"
chmod 600 "$etc_path/user.config.yaml"
chown $app:$app "$etc_path/user.config.yaml"
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
cp "$final_path/$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"
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"
#=================================================
# RESTORE SYSTEMD
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
chmod 750 "$final_path/run.sh"
chown "$app:$app" "$final_path/run.sh"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages"
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="$app daemon for bridging Discord and Matrix messages"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start"
ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -12,157 +10,112 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
language=$(ynh_app_setting_get --app=$app --key=language)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
port=$(ynh_app_setting_get --app=$app --key=port)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
log_path=$(ynh_app_setting_get --app=$app --key=log_path)
etc_path=$(ynh_app_setting_get --app=$app --key=etc_path)
#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="$final_path/.pip"
app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
pip_path="$install_dir/.pip"
#REMOVEME? app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop"
ynh_systemd_action --service_name="$app" --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
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="$final_path" --keep="run.sh"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=9
ynh_script_progression --message="Upgrading NodeJS..." --weight=9
ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
#=================================================
# SPECIFIC UPGRADE
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# INSTALL NODE DEPENDENCIES
#=================================================
ynh_script_progression --message="Building Node dependencies..." --weight=3
ynh_script_progression --message="Upgrading source files..." --weight=1
pushd "$final_path"
ynh_use_nodejs
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH npx yarn install
popd
# 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
base_config_path="$final_path/base.config.yaml"
ynh_add_config --template="base.config.yaml" --destination="$base_config_path"
chmod 400 "$base_config_path"
chown $app:$app "$base_config_path"
# 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 "$final_path"
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production $final_path/run.sh -r -f "$app.yaml"
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 "$final_path/$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"
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"
#=================================================
# SETUP SYSTEMD
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
# Create startup script
ynh_add_config --template="../conf/run.sh" --destination="$final_path/run.sh"
chmod 750 "$final_path/run.sh"
chown "$app:$app" "$final_path/run.sh"
yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages"
yunohost service add "$app" --description="$app daemon for bridging Discord and Matrix messages"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# END OF SCRIPT

19
tests.toml Normal file
View file

@ -0,0 +1,19 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json
test_format = 1.0
[default]
preinstall = """
sudo yunohost tools update apps
sudo yunohost app install https://github.com/YunoHost-Apps/synapse_ynh/ \
-a "domain=$domain&server_name=$server_name&is_free_registration=$is_free_registration&jitsi_server=$jitsi_server" --force
"""
# ------------
# Tests to run
# ------------
# domain="domain.tld"
# port="8343"
# synapsenumber=1