From f653a017bfe5851f1db72be6746b32e6aed31e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Wed, 20 Jun 2018 19:16:01 +0200 Subject: [PATCH] Add a script to upgrade coturn config easly --- scripts/install | 10 +++++++ scripts/upgrade | 10 +++++++ sources/Coturn_config_rotate.sh | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 sources/Coturn_config_rotate.sh diff --git a/scripts/install b/scripts/install index 0923728..3290ca7 100644 --- a/scripts/install +++ b/scripts/install @@ -277,6 +277,16 @@ ynh_store_file_checksum "$coturn_config_path" ynh_use_logrotate /var/log/matrix-$app +#================================================= +# ADD SCRIPT FOR COTURN CRON +#================================================= + +# WARRNING : theses command are used in INSTALL, UPGRADE +# For any update do it in all files + +cp ../sources/Coturn_config_rotate.sh $final_path/ +ynh_replace_string __APP__ $app "$final_path/Coturn_config_rotate.sh" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2366dfb..8d0225d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -251,6 +251,16 @@ fi ynh_store_file_checksum "$coturn_config_path" +#================================================= +# ADD SCRIPT FOR COTURN CRON +#================================================= + +# WARRNING : theses command are used in INSTALL, UPGRADE +# For any update do it in all files + +cp ../sources/Coturn_config_rotate.sh $final_path/ +ynh_replace_string __APP__ $app "$final_path/Coturn_config_rotate.sh" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/sources/Coturn_config_rotate.sh b/sources/Coturn_config_rotate.sh new file mode 100644 index 0000000..6cf0aa4 --- /dev/null +++ b/sources/Coturn_config_rotate.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +app_instance=__APP__ + +ynh_validate_ip() +{ + # http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298 + + local IP_ADDRESS_FAMILY=$1 + local IP_ADDRESS=$2 + + [ "$IP_ADDRESS_FAMILY" == "4" ] || [ "$IP_ADDRESS_FAMILY" == "6" ] || return 1 + + python /dev/stdin << EOF +import socket +import sys +family = { "4" : socket.AF_INET, "6" : socket.AF_INET6 } +try: + socket.inet_pton(family["$IP_ADDRESS_FAMILY"], "$IP_ADDRESS") +except socket.error: + sys.exit(1) +sys.exit(0) +EOF +} + +external_IP_line="external-ip=__IPV4__,__IPV6__" + +public_ip4="$(curl ip.yunohost.org)" || true +public_ip6="$(curl ipv6.yunohost.org)" || true + +if [[ -n "$public_ip4" ]] && ynh_validate_ip 4 "$public_ip4" +then + external_IP_line="${external_IP_line/'__IPV4__'/$public_ip4}" +else + external_IP_line="${external_IP_line/'__IPV4__,'/}" +fi + +if [[ -n "$public_ip6" ]] && ynh_valide_ip 6 "$public_ip6" +then + external_IP_line="${external_IP_line/'__IPV6__'/$public_ip6}" +else + external_IP_line="${external_IP_line/',__IPV6__'/}" +fi + +sed --in-place "s@^external-ip=.*\$@$external_IP_line@g" "/etc/matrix-$app_instance/coturn.conf" + +exit 0 \ No newline at end of file