#!/bin/bash

# Copyright (C) Metaswitch Networks 2015
# If license terms are provided to you in a COPYING file in the root directory
# of the source code repository by which you are accessing this code, then
# the license outlined in that COPYING file applies to your use.
# Otherwise no rights are granted except for those provided to you by
# Metaswitch Networks in a separate written agreement.

set -e

if [ $# -eq 0 ]
then
	echo "Usage: migrate_shared_config filename [filename2] [filename3]...[filenameN]"
	exit 1
fi

for i in $@; do
	source $i
done

cat <<EOF > /etc/clearwater/shared_config
home_domain="$home_domain"
sprout_hostname="$sprout_hostname"
bono_hostname="$bono_hostname"
hs_hostname="$hs_hostname"
hs_provisioning_hostname="$hs_provisioning_hostname"
ralf_hostname="$ralf_hostname"
cdf_identity="$cdf_identity"
xdms_hostname="$xdms_hostname"
hss_hostname="$hss_hostname"
signup_key="$signup_key"
turn_workaround="$turn_workaround"
smtp_smarthost="$smtp_smarthost"
smtp_username="$smtp_username"
smtp_password="$smtp_password"
email_recovery_sender="$email_recovery_sender"
ellis_api_key="$ellis_api_key"
icscf="$icscf"
scscf="$scscf"
homestead_provisioning_port="$homestead_provisioning_port"
sas_server="$sas_server"
reg_max_expires="$reg_max_expires"
sub_max_expires="$sub_max_expires"
upstream_hostname="$upstream_hostname"
upstream_port="$upstream_port"
sprout_rr_level="$sprout_rr_level"
hss_mar_lowercase_unknown="$hss_mar_lowercase_unknown"
enforce_user_phone="$enforce_user_phone"
enforce_global_only_lookups="$enforce_global_only_lookups"
hs_listen_port="$hs_listen_port"
ralf_listen_port="$ralf_listen_port"
default_session_expires="$default_session_expires"
enum_server="$enum_server"
enum_suffix="$enum_suffix"
enum_file="$enum_file"
icscf_uri="$icscf_uri"
scscf_uri="$scscf_uri"
additional_home_domains="$additional_home_domains"
hss_realm="$hss_realm"
billing_realm="$billing_realm"
diameter_timeout_ms="$diameter_timeout_ms"
max_peers="$max_peers"
num_http_threads="$num_http_threads"
num_http_worker_threads="$num_http_worker_threads"
gemini_enabled="$gemini_enabled"
memento_enabled="$memento_enabled"
max_call_list_length="$max_call_list_length"
call_list_store_ttl="$call_list_store_ttl"
memento_disk_limit="$memento_disk_limit"
memento_threads="$memento_threads"
signaling_dns_server="$signaling_dns_server"
target_latency_us="$target_latency_us"
max_tokens="$max_tokens"
init_token_rate="$init_token_rate"
min_token_rate="$min_token_rate"
override_npdi="$override_npdi"
exception_max_ttl="$exception_max_ttl"
check_destination_host="$check_destination_host"
astaire_cpu_limit_percentage="$astaire_cpu_limit_percentage"
sip_blacklist_duration="$sip_blacklist_duration"
http_blacklist_duration="$http_blacklist_duration"
diameter_blacklist_duration="$diameter_blacklist_duration"
cassandra_hostname="$cassandra_hostname"
ralf_secure_listen_port="$ralf_secure_listen_port"
hs_secure_listen_port="$hs_secure_listen_port"
ellis_cookie_key="$ellis_cookie_key"
impu_cache_ttl="$impu_cache_ttl"
hss_reregistration_time="$hss_reregistration_time"
hss_port="$hss_port"
snmp_ip="$snmp_ip"
trusted_peers="$trusted_peers"
EOF

# Comment out any blank values
perl -p -i -e 's/^(.*="")$/#$1/' /etc/clearwater/shared_config
