1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git synced 2024-09-03 19:46:01 +02:00
mautrix_whatsapp_ynh/scripts/install
CodeShakingSheep 51e6428211 Update install
Fix synapse DB name
2024-06-20 17:35:16 +02:00

166 lines
6.7 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
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
synapse_db_name="$(get_synapse_db_name $synapse_instance)"
# This is needed to convert the value from the manifest to a valid value for the config.yaml file.
# Without this the install script will throw a warning.
if [ "$encryption" -eq "1" ]
then
encryption="true"
else
encryption="false"
fi
#=================================================
# SET STANDARD SETTINGS FROM DEFAULT CONFIG
#=================================================
appserviceid=$app
async_media="false"
displayname="WhatsApp bridge bot"
avatar="mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr"
ephemeral_events="true"
enable_metrics="false"
listen_port="127.0.0.1:8001"
os_name="Mautrix-WhatsApp bridge"
browser_name="unknown"
username_template="whatsapp_{{.}}"
personal_filtering_spaces="false"
delivery_receipts="false"
send_presence_on_typing="false"
url_previews="false"
encryption_default="false"
encryption_require="false"
admin_only="true"
print_level="info"
enable_relaybot="true"
listrelay="*"
listadmin="$botadmin"
listuser="$botusers"
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
ynh_app_setting_set --app=$app --key=async_media --value=$async_media
ynh_app_setting_set --app=$app --key=displayname --value=$displayname
ynh_app_setting_set --app=$app --key=avatar --value=$avatar
ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events
ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics
ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port
ynh_app_setting_set --app=$app --key=os_name --value=$os_name
ynh_app_setting_set --app=$app --key=browser_name --value=$browser_name
ynh_app_setting_set --app=$app --key=username_template --value=$username_template
ynh_app_setting_set --app=$app --key=personal_filtering_spaces --value=$personal_filtering_spaces
ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts
ynh_app_setting_set --app=$app --key=send_presence_on_typing --value=$send_presence_on_typing
ynh_app_setting_set --app=$app --key=url_previews --value=$url_previews
ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default
ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require
ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot
ynh_app_setting_set --app=$app --key=admin_only --value=$admin_only
ynh_app_setting_set --app=$app --key=print_level --value=$print_level
ynh_app_setting_set --app=$app --key=listrelay --value=$listrelay
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=5
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod 750 "$install_dir"
chmod -R 750 "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=2
ynh_add_config --template="../conf/config.yaml" --destination="$install_dir/config.yaml"
chmod 400 "$install_dir/config.yaml"
chown $app:$app "$install_dir/config.yaml"
# This calls allows to set multiple users during install question "botusers" specifying them separated by a comma
set__listuser
set__listrelay
set__listadmin
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
$install_dir/mautrix-whatsapp -g -c $install_dir/config.yaml -r /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"
chown -R $app:$app "$install_dir"
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
ynh_store_file_checksum --file="$install_dir/config.yaml"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=5
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=3
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --nonappend --specific_user $app/$app
chmod -R 600 "/var/log/$app"
chmod 700 "/var/log/$app"
chown -R $app:$app /var/log/$app
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="$app daemon for bridging Whatsapp and Matrix messages" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=15
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
# Wait until the synapse user is created
sleep 30
# (Note that, by default, non-admins might not have your homeserver's permission to create Spaces.)
if [ "$bot_synapse_adm" = true ]
then
ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";"
#yunohost app action run $synapse_instance set_admin_user -a username=$botname
fi
ynh_systemd_action --service_name=$app --action="restart"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last