#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= ynh_print_info --message="Retrieving arguments from the manifest..." domain=$YNH_APP_ARG_DOMAIN path_url="/" app=$YNH_APP_INSTANCE_NAME #YOURSECRET3 focus_password=$(ynh_string_random --length=8) #YOURSECRET1 videobridge_secret=$(ynh_string_random --length=8) #YOURSECRET2 focus_secret=$(ynh_string_random --length=8) focus_user="svc${app}focus" jvb_user="svc${app}jvb" jvb_password=$(ynh_string_random --length=8) muc_nickname=$(ynh_string_random --length=32) #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_print_info --message="Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_print_info --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=focus_password --value=$focus_password ynh_app_setting_set --app=$app --key=videobridge_secret --value=$videobridge_secret ynh_app_setting_set --app=$app --key=focus_secret --value=$focus_secret ynh_app_setting_set --app=$app --key=focus_user --value=$focus_user ynh_app_setting_set --app=$app --key=jvb_user --value=$jvb_user ynh_app_setting_set --app=$app --key=jvb_password --value=$jvb_password ynh_app_setting_set --app=$app --key=muc_nickname --value=$muc_nickname #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= ynh_print_info --message="Configuring firewall..." # Find an available port port=$(ynh_find_port --port=4443) # Open this port ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port ynh_app_setting_set --app=$app --key=port --value=$port # Find an available port port_videobridge=$(ynh_find_port --port=10000) # Open this port ynh_exec_warn_less yunohost firewall allow --no-upnp UDP $port_videobridge ynh_app_setting_set --app=$app --key=port_videobridge --value=$port_videobridge # Find an available port port_component=$(ynh_find_port --port=5347) ynh_app_setting_set --app=$app --key=port_component --value=$port_component #================================================= # INSTALL DEPENDENCIES #================================================= ynh_print_info --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies #ynh_install_nodejs --nodejs_version=10 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_print_info --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src declare -A packages packages[jicofo]="jicofo" packages[jitsi-meet-prosody]="jitsi-meet/prosody-plugins" packages[jitsi-meet-web]="jitsi-meet" packages[jitsi-videobridge]="jitsi-videobridge" for package in "${!packages[@]}" do ynh_setup_source --dest_dir="$final_path/${package}_temp" --source_id=$package pushd "$final_path/${package}_temp" ar x $package.deb data.tar.xz tar xf data.tar.xz popd mv "$final_path/${package}_temp/usr/share/${packages[$package]}/" "$final_path/${package}/" ynh_secure_remove --file="$final_path/${package}_temp" done #================================================= # NGINX CONFIGURATION #================================================= ynh_print_info --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_print_info --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE METRONOME #================================================= ynh_print_info --message="Configuring metronome..." # Adapt prosody module to metronome ynh_replace_string --match_string="prosody" --replace_string="metronome" --target_file="$final_path/jitsi-meet-prosody/mod_muc_domain_mapper.lua" # Create focus user yunohost domain add auth.$domain yunohost user create $focus_user -f $focus_user -l $focus_user -m ${focus_user}@auth.$domain -p $focus_password -q 0 yunohost user create $jvb_user -f $jvb_user -l $jvb_user -m ${jvb_user}@auth.$domain -p $jvb_password -q 0 # Add Metronome domain conf template metronome_conf="/usr/share/yunohost/templates/jitsi/$domain.cfg.lua" mkdir -p /usr/share/yunohost/templates/jitsi/ cp ../conf/metronome.cfg.lua $metronome_conf ynh_replace_string --match_string="__PORT_COMPONENT__" --replace_string="$port_component" --target_file="$metronome_conf" ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="$metronome_conf" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$metronome_conf" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$metronome_conf" ynh_replace_string --match_string="__VIDEOBRIDGE_SECRET__" --replace_string="$videobridge_secret" --target_file="$metronome_conf" ynh_replace_string --match_string="__FOCUS_SECRET__" --replace_string="$focus_secret" --target_file="$metronome_conf" ynh_replace_string --match_string="__FOCUS_USER__" --replace_string="$focus_user" --target_file="$metronome_conf" ynh_replace_string --match_string="__JVB_USER__" --replace_string="$jvb_user" --target_file="$metronome_conf" touch "/usr/share/yunohost/templates/jitsi/auth.$domain.cfg.lua" # Add Metronome hook cp -R ../conf/metronome_regen_conf.hook /usr/share/yunohost/hooks/conf_regen/50-metronome_$app yunohost tools regen-conf metronome ynh_systemd_action --service_name=metronome --action=restart #================================================= # CONFIGURE JITSI-VIDEOBRIDGE #================================================= ynh_print_info --message="Configuring Jitsi-Videobridge..." public_ipv4="$(curl ip.yunohost.org)" || true private_ipv4="$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')" || true mkdir -p "$final_path/.sip-communicator" cp ../conf/sip-communicator.properties "$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__PRIVATE_IPV4__" --replace_string="$private_ipv4" --target_file="$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__PUBLIC_IPV4__" --replace_string="$public_ipv4" --target_file="$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__JVB_USER__" --replace_string="$jvb_user" --target_file="$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__JVB_PASSWORD__" --replace_string="$jvb_password" --target_file="$final_path/.sip-communicator/sip-communicator.properties" ynh_replace_string --match_string="__MUC_NICKNAME__" --replace_string="$muc_nickname" --target_file="$final_path/.sip-communicator/sip-communicator.properties" chown -R $app: $final_path #================================================= # CONFIGURE JITSI-MEET #================================================= ynh_print_info --message="Configuring Jitsi-Meet..." config="$final_path/jitsi-meet-web/config.js" cp ../conf/config.js "$config" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" #================================================= # SETUP SYSTEMD #================================================= ynh_print_info --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/jitsi-videobridge.service" ynh_replace_string --match_string="__VIDEOBRIDGE_SECRET__" --replace_string="$videobridge_secret" --target_file="../conf/jitsi-videobridge.service" ynh_replace_string --match_string="__PORT_COMPONENT__" --replace_string="$port_component" --target_file="../conf/jitsi-videobridge.service" ynh_add_systemd_config --service=$app-videobridge --template="jitsi-videobridge.service" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/jitsi-jicofo.service" ynh_replace_string --match_string="__PORT_COMPONENT__" --replace_string="$port_component" --target_file="../conf/jitsi-jicofo.service" ynh_replace_string --match_string="__FOCUS_SECRET__" --replace_string="$focus_secret" --target_file="../conf/jitsi-jicofo.service" ynh_replace_string --match_string="__FOCUS_USER__" --replace_string="$focus_user" --target_file="../conf/jitsi-jicofo.service" ynh_replace_string --match_string="__FOCUS_PASSWORD__" --replace_string="$focus_password" --target_file="../conf/jitsi-jicofo.service" ynh_add_systemd_config --service=$app-jicofo --template="jitsi-jicofo.service" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= ynh_print_info --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= ynh_print_info --message="Securing files and directories..." # Set permissions to app files chown -R $app: $final_path #================================================= # SETUP LOGROTATE #================================================= ynh_print_info --message="Configuring log rotation..." # Use logrotate to manage application logfile(s) ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_print_info --message="Integrating service in YunoHost..." yunohost service add $app-videobridge --description "$app jitsi-videobridge for jitsi" --log "/var/log/$app/$app-videobridge.log" yunohost service add $app-jicofo --description "$app jitsi-jicofo for jitsi" --log "/var/log/$app/$app-jicofo.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_print_info --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=$app-videobridge --action="start" --log_path="/var/log/$app/$app-videobridge.log" ynh_systemd_action --service_name=$app-jicofo --action="start" --log_path="/var/log/$app/$app-jicofo.log" #================================================= # SETUP SSOWAT #================================================= ynh_print_info --message="Configuring SSOwat..." # Make app public ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" #================================================= # RELOAD NGINX #================================================= ynh_print_info --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_print_info --message="Installation of $app completed"