mirror of
https://github.com/YunoHost-Apps/matrix-puppet-discord_ynh.git
synced 2024-09-03 19:36:25 +02:00
141 lines
4.9 KiB
Bash
Executable file
141 lines
4.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# INITIALIZE AND STORE SETTINGS
|
|
#=================================================
|
|
|
|
if [ $synapsenumber -eq "1" ]; then
|
|
synapse_instance="synapse"
|
|
else
|
|
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\""
|
|
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="$install_dir/base.config.yaml"
|
|
user_config_path="/etc/$app/user.config.yaml"
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing NodeJS..." --weight=4
|
|
|
|
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/source"
|
|
|
|
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
|
|
|
|
mkdir -p -m 750 "$etc_path"
|
|
chown "$app:$app" "$etc_path"
|
|
|
|
any_account_of_domain="@.*:${domain//\./\\\.}"
|
|
|
|
ynh_add_config --template="user.config.yaml" --destination="$user_config_path"
|
|
chmod 600 "$user_config_path"
|
|
chown "$app:$app" "$user_config_path"
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# SETUP PIP (FOR YQ)
|
|
#=================================================
|
|
ynh_script_progression --message="Install yq..." --weight=1
|
|
|
|
_venv_install
|
|
"$venvpy" -m pip install yq
|
|
|
|
#=================================================
|
|
# CREATE LOG DIR
|
|
#=================================================
|
|
|
|
mkdir -p -m 700 "$log_path"
|
|
chown "$app:$app" "$log_path"
|
|
|
|
#=================================================
|
|
# REGISTER MODULE IN SYNAPSE
|
|
#=================================================
|
|
ynh_script_progression --message="Register module in Synapse" --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"
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding 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="Installation of $app completed" --last
|