This commit is contained in:
YunoHost Bot 2024-08-31 13:21:47 +02:00 committed by GitHub
commit 01c47da41f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 94 additions and 219 deletions

1
.gitignore vendored
View file

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

View file

@ -7,7 +7,7 @@ Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__INSTALL_DIR__/
Environment="__YNH_NODE_LOAD_PATH__"
Environment="PATH=__PATH_WITH_NODEJS__"
ExecStart=__INSTALL_DIR__/bin/matrix-appservice-irc -c __INSTALL_DIR__/config.yaml
StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit

View file

@ -18,7 +18,8 @@ admindoc = "https://matrix-org.github.io/matrix-appservice-irc/latest/bridge_set
userdoc = "https://matrix-org.github.io/matrix-appservice-irc/latest/usage"
[integration]
yunohost = ">= 11.1"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = false

View file

@ -1,15 +1,11 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
nodejs_version=20
#=================================================
# PERSONAL HELPERS
#=================================================
__ynh_register_synapse_app_service() {
"$install_dir/bin/matrix-appservice-irc" -r \
-c "$install_dir/config.yaml" \
@ -21,10 +17,10 @@ __ynh_register_synapse_app_service() {
"/etc/matrix-$synapse_instance/app-service/$app.yaml"
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" \
|| ynh_die --message="Synapse can't restart with the appservice configuration"
|| ynh_die "Synapse can't restart with the appservice configuration"
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
ynh_store_file_checksum --file="$install_dir/appservice-registration-irc.yaml"
ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml"
ynh_store_file_checksum "$install_dir/appservice-registration-irc.yaml"
}
# TODO:
@ -35,11 +31,3 @@ __ynh_register_dendrite_app_service() {
__ynh_register_matrix_app_service() {
__ynh_register_synapse_app_service
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -8,40 +8,37 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
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"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/var/log/$app/"
ynh_backup "/var/log/$app/"
#=================================================
# 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
#=================================================
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,102 +0,0 @@
#!/bin/bash
# In simple cases, you don't need a config script.
# With a simple config_panel.toml, you can write in the app settings, in the
# upstream config file or replace complete files (logo ...) and restart services.
# The config scripts allows you to go further, to handle specific cases
# (validation of several interdependent fields, specific getter/setter for a value,
# display dynamic informations or choices, pre-loading of config type .cube... ).
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__amount() {
# Here we can imagine to have an API call to stripe to know the amount of donation during a month
local amount = 200
# It's possible to change some properties of the question by overriding it:
if [ $amount -gt 100 ]
then
cat << EOF
style: success
value: $amount
ask:
en: A lot of donation this month: **$amount €**
EOF
else
cat << EOF
style: danger
value: $amount
ask:
en: Not so much donation this month: $amount €
EOF
fi
}
get__prices() {
local prices = "$(grep "DONATION\['" "$final_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')"
if [ "$prices" == "," ];
then
# Return YNH_NULL if you prefer to not return a value at all.
echo YNH_NULL
else
echo $prices
fi
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
validate__publishable_key() {
# We can imagine here we test if the key is really a publisheable key
(is_secret_key $publishable_key) &&
echo 'This key seems to be a secret key'
}
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__prices() {
#---------------------------------------------
# IMPORTANT: setter are trigger only if a change is detected
#---------------------------------------------
for price in $(echo $prices | sed "s/,/ /"); do
frequency=$(echo $price | cut -d/ -f1)
currency=$(echo $price | cut -d/ -f2)
price_id=$(echo $price | cut -d/ -f3)
sed "d/DONATION\['$frequency'\]\['$currency'\]" "$final_path/settings.py"
echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py"
done
#---------------------------------------------
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
#---------------------------------------------
ynh_app_setting_set $app prices $prices
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1

View file

@ -14,8 +14,8 @@ source /usr/share/yunohost/helpers
# Retrieve some values from selected Synapse instance and store them
server_name=$(ynh_app_setting_get --app "$synapse_instance" --key server_name)
domain=$(ynh_app_setting_get --app "$synapse_instance" --key domain)
ynh_app_setting_set --app="$app" --key=server_name --value="$server_name"
ynh_app_setting_set --app="$app" --key=domain --value="$domain"
ynh_app_setting_set --key=server_name --value="$server_name"
ynh_app_setting_set --key=domain --value="$domain"
synapse_db_name="matrix_$synapse_instance"
enable_relaybot=true
@ -24,42 +24,40 @@ bot_synapse_db_user="@$botname:$server_name"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing NodeJS..." --weight=1
ynh_script_progression "Installing NodeJS..."
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_nodejs_install
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$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"
#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:$app" "$install_dir"
#=================================================
# Build
#=================================================
ynh_script_progression --message="Building the app..." --weight=3
ynh_script_progression "Building the app..."
(
cd "$install_dir"
ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" i
ynh_exec_as_app node_load_PATH" npm i
)
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_script_progression "Adding $app's configuration..."
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml"
chmod 400 "$install_dir/config.yaml"
chown "$app:$app" "$install_dir/config.yaml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config.yaml"
# Generate the password encryption key
openssl genpkey -out "$install_dir/passkey.pem" -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048
@ -69,35 +67,35 @@ chown "$app:$app" "$install_dir/passkey.pem"
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
ynh_script_progression "Registering Synapse app-service"
__ynh_register_matrix_app_service
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_script_progression "Adding system configurations related to $app..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add "$app" --description="$app daemon for bridging IRC and Matrix messages." --log="/var/log/$app/$app.log"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --specific_user "$app/$app"
chmod -R 600 "/var/log/$app"
chmod 700 "/var/log/$app"
chown -R "$app:$app" "/var/log/$app"
ynh_config_add_logrotate "/var/log/$app/$app.log" "$app/$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 | chmod -R 600 "/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 | chmod 700 "/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:$app" "/var/log/$app"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Error: No IRC servers specified."
ynh_systemctl --service="$app" --action="start" --wait_until="Error: No IRC servers specified."
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -10,27 +10,27 @@ source /usr/share/yunohost/helpers
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
ynh_script_progression "Removing system configurations related to $app..."
# 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
if ynh_hide_warnings yunohost service status "$app" >/dev/null; then
yunohost service remove "$app"
fi
# Remove the dedicated systemd config
ynh_remove_systemd_config
ynh_config_remove_systemd
# Remove the app-specific logrotate config
ynh_remove_logrotate
ynh_config_remove_logrotate
ynh_remove_nodejs
ynh_nodejs_remove
# Remove a directory securely
ynh_secure_remove --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die --message="Synapse can't restart with the appservice configuration"
ynh_safe_rm "/etc/matrix-$synapse_instance/app-service/$app.yaml"
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die "Synapse can't restart with the appservice configuration"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -8,7 +8,7 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
server_name=$(ynh_app_setting_get --key=server_name)
synapse_db_name="matrix_$synapse_instance"
bot_synapse_db_user="@$botname:$server_name"
@ -16,68 +16,66 @@ bot_synapse_db_user="@$botname:$server_name"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling NodeJS..." --weight=1
ynh_script_progression "Reinstalling NodeJS..."
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_nodejs_install
#=================================================
# 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"
chmod 750 "$install_dir"
chmod -R 750 "$install_dir"
chown -R "$app:$app" "$install_dir"
ynh_restore "$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"
#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 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 | chown -R "$app:$app" "$install_dir"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
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""
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
ynh_script_progression "Registering Synapse app-service"
__ynh_register_matrix_app_service
chmod 400 "$install_dir/config.yaml"
chown "$app:$app" "$install_dir/config.yaml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config.yaml"
#=================================================
# 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/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="$app daemon for bridging IRC and Matrix messages." --log="/var/log/$app/$app.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_restore_file --origin_path="/var/log/$app/"
chmod -R 600 "/var/log/$app"
chmod 700 "/var/log/$app"
chown -R "$app:$app" "/var/log/$app"
ynh_restore "/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 | chmod -R 600 "/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 | chmod 700 "/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:$app" "/var/log/$app"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -10,50 +10,48 @@ source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# ynh_script_progression "Ensuring downward compatibility..."
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Updating NodeJS..." --weight=1
ynh_script_progression "Updating NodeJS..."
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
ynh_nodejs_install
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 \
ynh_setup_source --dest_dir="$install_dir" --full_replace \
--keep="config.yaml passkey.pem appservice-registration-irc.yaml"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$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"
#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:www-data" "$install_dir"
#=================================================
# Build
#=================================================
ynh_script_progression --message="Upgrading the app..." --weight=1
ynh_script_progression "Upgrading the app..."
(
cd "$install_dir"
ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" i
ynh_exec_as_app node_load_PATH" npm i
)
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_script_progression "Updating configuration..."
configured_servers=$(python3 -c "import yaml
with open('$install_dir/config.yaml') as c: c = yaml.load(c, Loader=yaml.SafeLoader)
@ -61,7 +59,7 @@ print(yaml.dump(c['ircService']['servers']))")
### Same as during install
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml"
# Try to recover the previously configured IRC servers.
python3 -c "import yaml
@ -71,38 +69,38 @@ c['ircService']['servers'] = servers
print(yaml.dump(c))" > "$install_dir/config.yaml.temp"
mv "$install_dir/config.yaml.temp" "$install_dir/config.yaml"
chmod 400 "$install_dir/config.yaml"
chown "$app:$app" "$install_dir/config.yaml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config.yaml"
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_backup_if_checksum_is_different --file="$install_dir/appservice-registration-irc.yaml"
ynh_backup_if_checksum_is_different "$install_dir/appservice-registration-irc.yaml"
__ynh_register_matrix_app_service
#=================================================
# 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 systemd config
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add "$app" --description="$app daemon for bridging IRC and Matrix messages." --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --specific_user "$app/$app"
ynh_config_add_logrotate "$app/$app"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"

View file

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

View file

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