mirror of
https://github.com/YunoHost-Apps/matrix-appservice-irc_ynh.git
synced 2024-09-03 19:36:37 +02:00
108 lines
3.9 KiB
Bash
108 lines
3.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Updating NodeJS..." --weight=1
|
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
ynh_use_nodejs
|
|
|
|
#=================================================
|
|
# 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" --full_replace=1 \
|
|
--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"
|
|
|
|
#=================================================
|
|
# Build
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading the app..." --weight=1
|
|
|
|
(
|
|
cd "$install_dir"
|
|
ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" i
|
|
)
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
configured_servers=$(python3 -c "import yaml
|
|
with open('$install_dir/config.yaml') as c: c = yaml.load(c, Loader=yaml.SafeLoader)
|
|
print(yaml.dump(c['ircService']['servers']))")
|
|
|
|
### Same as during install
|
|
|
|
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
|
|
|
|
# Try to recover the previously configured IRC servers.
|
|
python3 -c "import yaml
|
|
with open('$install_dir/config.yaml') as c: c = yaml.load(c, Loader=yaml.SafeLoader)
|
|
servers = yaml.safe_load('''$configured_servers''')
|
|
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"
|
|
|
|
#=================================================
|
|
# REGISTER SYNAPSE APP-SERVICE
|
|
#=================================================
|
|
|
|
ynh_backup_if_checksum_is_different --file="$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
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
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"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|