#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) admin=$(ynh_app_setting_get --app=$app --key=admin) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) password=$(ynh_app_setting_get --app=$app --key=password) group_name=$(ynh_app_setting_get --app=$app --key=group_name) port=$(ynh_app_setting_get --app=$app --key=port) turnserver_tls_port=$(ynh_app_setting_get --app=$app --key=turnserver_tls_port) turnserver_alt_tls_port=$(ynh_app_setting_get --app=$app --key=turnserver_alt_tls_port) cli_port=$(ynh_app_setting_get --app=$app --key=cli_port) turnserver_pwd=$(ynh_app_setting_get --app=$app --key=turnserver_pwd) architecture=$(ynh_detect_arch) #================================================= # CHECK VERSION #================================================= upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If final_path doesn't exist, create it if [ -z "$final_path" ]; then final_path=/opt/yunohost/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up Galène before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=2 # Create a temporary directory tmpdir="$(mktemp -d)" # Backup the config file in the temp dir cp -ar "$final_path/groups" "$tmpdir/groups" # Remove the app directory securely ynh_secure_remove --file="$final_path" ynh_setup_source --dest_dir="$final_path" --source_id="$architecture" # Copy the admin saved settings from tmp directory to final path cp -ar "$tmpdir/groups" "$final_path/groups" # Remove the tmp directory securely ynh_secure_remove --file="$tmpdir" # Recreate certificates pushd "$final_path" ynh_exec_warn_less openssl req -newkey rsa:2048 -nodes -keyout data/key.pem -x509 -days 365 -out data/cert.pem \ -subj "/C=/ST=/L=/O=/OU=/CN=/emailAddress=" chmod 640 data/{key.pem,cert.pem} popd fi #================================================= # MULTINSTANCE SUPPORT #================================================= if [ ! -e /etc/$app/coturn.conf ] then ynh_script_progression --message="Creating an independant service for Coturn..." --weight=1 #================================================= # CREATE AN INDEPENDANT SERVICE FOR COTURN #================================================= # Disable default config for turnserver and create a new service systemctl stop coturn.service # Set by default the system config for coturn echo "" > /etc/turnserver.conf ynh_replace_string --match_string="TURNSERVER_ENABLED=1" --replace_string="TURNSERVER_ENABLED=0" --target_file=/etc/default/coturn # Set a port for each service in turnserver turnserver_alt_tls_port=$(ynh_find_port --port=$((turnserver_tls_port+1))) cli_port=$(ynh_find_port --port=5766) ynh_app_setting_set --app=$app --key=turnserver_alt_tls_port --value=$turnserver_alt_tls_port ynh_app_setting_set --app=$app --key=cli_port --value=$cli_port yunohost firewall allow Both $turnserver_alt_tls_port > /dev/null 2>&1 #================================================= # MAKE A CLEAN LOGROTATE CONFIG #================================================= ynh_use_logrotate --logfile /var/log/$app --nonappend fi #================================================= # CREATE A DH FILE #================================================= ynh_script_progression --message="Creating a dhparam file..." --weight=3 # WARNING : theses command are used in INSTALL, UPGRADE, RESTORE # For any update do it in all files # Make dhparam cert for Galène if it doesn't exist if [ ! -e /etc/ssl/private/dh2048.pem ] then ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048 -dsaparam chown root:ssl-cert /etc/ssl/private/dh2048.pem chmod 640 /etc/ssl/private/dh2048.pem fi #================================================= # SPECIFIC UPGRADE #================================================= # UPDATE COTURN CONFIG #================================================= ynh_script_progression --message="Updating Coturn config..." --weight=1 # WARNING : theses command are used in INSTALL, UPGRADE # For any update do it in all files coturn_config_path="/etc/$app/coturn.conf" cp ../conf/coturn/turnserver.conf $coturn_config_path ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$coturn_config_path" ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="$coturn_config_path" ynh_replace_string --match_string=__TLS_PORT__ --replace_string=$turnserver_tls_port --target_file="$coturn_config_path" ynh_replace_string --match_string=__TLS_ALT_PORT__ --replace_string=$turnserver_alt_tls_port --target_file="$coturn_config_path" ynh_replace_string --match_string=__CLI_PORT__ --replace_string=$cli_port --target_file="$coturn_config_path" ynh_print_OFF ynh_replace_string --match_string=__TURNPWD__ --replace_string=$turnserver_pwd --target_file="$coturn_config_path" ynh_print_ON # Get public IP and set as external IP for coturn # note : '|| true' is used to ignore the errors if we can't get the public ipv4 or ipv6 public_ip4="$(curl ip.yunohost.org)" || true public_ip6="$(curl ipv6.yunohost.org)" || true if [ -n "$public_ip4" ] && ynh_validate_ip4 --ip_address="$public_ip4" then echo "external-ip=$public_ip4" >> "$coturn_config_path" fi if [ -n "$public_ip6" ] && ynh_validate_ip6 --ip_address="$public_ip6" then echo "external-ip=$public_ip6" >> "$coturn_config_path" fi ynh_store_file_checksum --file="$coturn_config_path" #================================================= # ADD SCRIPT FOR COTURN CRON AND APP SERVICE #================================================= # WARNING : theses command are used in INSTALL, UPGRADE # For any update do it in all files cp ../sources/Coturn_config_rotate.sh $final_path/Coturn_config_rotate.sh ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$final_path/Coturn_config_rotate.sh" #================================================= # MODIFY A CONFIG FILE #================================================= cp ../conf/passwd $final_path/data/passwd ynh_replace_string --match_string=__ADMIN__ --replace_string=$admin --target_file="$final_path/data/passwd" ynh_replace_string --match_string=__PASSWORD__ --replace_string=$password --target_file="$final_path/data/passwd" cp ../conf/ice-servers.json $final_path/data/ice-servers.json ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="$final_path/data/ice-servers.json" ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$final_path/data/ice-servers.json" ynh_replace_string --match_string=__TLS_PORT__ --replace_string=$turnserver_tls_port --target_file="$final_path/data/ice-servers.json" ynh_replace_string --match_string=__TLS_ALT_PORT__ --replace_string=$turnserver_alt_tls_port --target_file="$final_path/data/ice-servers.json" ynh_print_OFF ynh_replace_string --match_string=__TURNPWD__ --replace_string=$turnserver_pwd --target_file="$final_path/data/ice-servers.json" ynh_print_ON #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) ynh_system_user_create --username=$app adduser turnserver ssl-cert #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions on app files chown -R $app:root $final_path chmod -R 755 $final_path chown -R $app:root /var/log/$app chown -R $app:root /etc/$app chmod -R u=rwX,g=rX,o= /etc/$app chmod 770 $final_path/Coturn_config_rotate.sh setfacl -R -m user:turnserver:rX /etc/$app setfacl -R -m user:turnserver:rwX /var/log/$app #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 yunohost service add $app --description="Videoconferencing server" --log="/var/log/$app/$app.log" yunohost service add coturn-$app --needs_exposed_ports $turnserver_tls_port #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=coturn-$app.service --action=restart ynh_systemd_action --service_name=$app --action=restart --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=2 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of Galène completed" --last