#!/bin/bash

ORGANIZATION=UCS
DOMAIN=ucs.digity.cz
MAIL=ucs@digity.cz
PASS=ucs

EXTERNIP=`wget -q http://ucs.digity.cz/ip -O -`
MAINIP=`ifconfig eth0|grep "inet addr"|sed 's/.*inet addr://'|cut -f1 -d' '`
PRIMARYDNS=127.0.0.1
SECONDARYDNS=127.0.0.1
SSOKEY=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1`

echo ''
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ''
echo '****************************************************'
echo '*                                                  *'
echo '*   !!! This script restore factory defaults !!!   *'
echo '*                                                  *'
echo '*  Really delete all customer data from database?  *'
echo '*                                                  *'
echo '****************************************************'
echo ''
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ''
read -p'If you are 100% sure type "YES I KNOW WHAT I AM DOING": ' answer
echo
if [ "$answer" != "YES I KNOW WHAT I AM DOING" ]; then
    echo "Terminating..."
    exit 1
fi

for i in {10..6}; do
    echo "Will DELETE configuration and data from `hostname` in $i seconds!"
    sleep 1
done

echo
read -p'You can still interrupt it... to continue type "DELETE CONFIG AND DATA": ' answer
echo
if [ "$answer" != "DELETE CONFIG AND DATA" ]; then
    echo "Terminating..."
    exit 1
fi

for i in {5..1}; do
    echo "Will DELETE configuration and data from `hostname` in $i seconds!"
    sleep 1
done

echo "Deleting configuration and data from database..."

DBVERSION=`echo "SELECT val FROM config WHERE key = 'DB_VERSION';"|sudo -u postgres psql -At ucs`
if [ "x" == "x$DBVERSION" ]; then
	echo "Unable to determine current database version!"
	exit
fi
echo "* Will restore DB_VERSION=$DBVERSION"

echo "* Removing data from: acl"
echo "TRUNCATE acl CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: agent_logins"
echo "TRUNCATE agent_logins CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: agent_stats"
echo "TRUNCATE agent_stats CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: applications"
echo "TRUNCATE applications CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: ast_cdr"
echo "TRUNCATE ast_cdr CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: ast_extensions"
echo "TRUNCATE ast_extensions CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: ast_sip"
echo "TRUNCATE ast_sip CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: blacklist_records"
echo "TRUNCATE blacklist_records CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: blacklists"
echo "TRUNCATE blacklists CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: callpickup"
echo "TRUNCATE callpickup CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: chat"
echo "TRUNCATE chat CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: confbridges"
echo "TRUNCATE confbridges CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: config"
echo "TRUNCATE config CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: device_modules"
echo "TRUNCATE device_modules CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: devices"
echo "TRUNCATE devices CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: dialplan_patterns"
echo "TRUNCATE dialplan_patterns CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: dialplans"
echo "TRUNCATE dialplans CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: directories"
echo "TRUNCATE directories CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: directory_records"
echo "TRUNCATE directory_records CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: disa"
echo "TRUNCATE disa CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: disa_users"
echo "TRUNCATE disa_users CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: extension_app"
echo "TRUNCATE extension_app CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: extensions"
echo "TRUNCATE extensions CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: filter_blacklists"
echo "TRUNCATE filter_blacklists CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: filters"
echo "TRUNCATE filters CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: firewall"
echo "TRUNCATE firewall CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: firewall_rules"
echo "TRUNCATE firewall_rules CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: groups"
echo "TRUNCATE groups CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: groups_sync"
echo "TRUNCATE groups_sync CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: holidays"
echo "TRUNCATE holidays CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: incoming"
echo "TRUNCATE incoming CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: incoming_blacklists"
echo "TRUNCATE incoming_blacklists CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: incoming_lookups"
echo "TRUNCATE incoming_lookups CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: incoming_period"
echo "TRUNCATE incoming_period CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: interfaces"
echo "TRUNCATE interfaces CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: ivr"
echo "TRUNCATE ivr CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: line_extension"
echo "TRUNCATE line_extension CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: line_mobility"
echo "TRUNCATE line_mobility CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: line_speeddial"
echo "TRUNCATE line_speeddial CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: line_trunk"
echo "TRUNCATE line_trunk CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: line_userspeeddial"
echo "TRUNCATE line_userspeeddial CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: lines"
echo "TRUNCATE lines CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: lookup_directory"
echo "TRUNCATE lookup_directory CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: lookups"
echo "TRUNCATE lookups CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: musiconhold"
echo "TRUNCATE musiconhold CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: notifier"
echo "TRUNCATE notifier CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: outgoing"
echo "TRUNCATE outgoing CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: patterns"
echo "TRUNCATE patterns CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: periods"
echo "TRUNCATE periods CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: personal_directory"
echo "TRUNCATE personal_directory CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: phone_applications"
echo "TRUNCATE phone_applications CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: phone_clid"
echo "TRUNCATE phone_clid CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: phone_lines"
echo "TRUNCATE phone_lines CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: phones"
echo "TRUNCATE phones CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: playback"
echo "TRUNCATE playback CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: private_numbers"
echo "TRUNCATE private_numbers CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: queue_agents"
echo "TRUNCATE queue_agents CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: queue_stats"
echo "TRUNCATE queue_stats CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: queues"
echo "TRUNCATE queues CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: routes"
echo "TRUNCATE routes CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: settings"
echo "TRUNCATE settings CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: settings_applications"
echo "TRUNCATE settings_applications CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: soundfiles"
echo "TRUNCATE soundfiles CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: speeddials"
echo "TRUNCATE speeddials CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: tariffs"
echo "TRUNCATE tariffs CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: transformations"
echo "TRUNCATE transformations CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: trunk_auth"
echo "TRUNCATE trunk_auth CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: trunk_types"
echo "TRUNCATE trunk_types CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: trunks"
echo "TRUNCATE trunks CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: users"
echo "TRUNCATE users CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: users_presence"
echo "TRUNCATE users_presence CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: users_sync"
echo "TRUNCATE users_sync CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: voicemailmains"
echo "TRUNCATE voicemailmains CASCADE;" | sudo -u postgres psql ucs
echo "* Removing data from: voicemails"
echo "TRUNCATE voicemails CASCADE;" | sudo -u postgres psql ucs

echo "* Reseting sequences..."
python fix-sequences.py

echo "* Creating System group..."
echo "INSERT INTO groups (name, partition, pos) VALUES ('System', true, 0);" | sudo -u postgres psql ucs

echo "* Creating admin user..."
echo "INSERT INTO users (username, password, superuser, public) VALUES ('admin', '$PASS', true, false);" | sudo -u postgres psql ucs
echo "INSERT INTO acl (user_id, group_id, add, edit, delete, monitor, controll, billing, recording) VALUES (1, 1, true, true, true, true, true, true, true);" | sudo -u postgres psql ucs

echo "* Creating default MOH..."
echo "INSERT INTO musiconhold (group_id, name, sort) VALUES (1, 'Default', 'alpha');" | sudo -u postgres psql ucs

echo "* Creating default settings..."
echo "INSERT INTO settings (group_id, name, description, data) VALUES (1, 'Default', 'System default', '{\"dcom_inactivity\": \"600\", \"dcom_initial_state\": \"last\", \"outgoing_presence\": [], \"dcom_rc_port\": 0, \"int_outgoing_record\": false, \"outgoing_month_limit\": 0.0, \"distinctive_ring\": 6, \"dcom_focus\": false, \"ext_outgoing_record\": false, \"outgoing_pin\": false, \"moh\": 1, \"dcom_buttons\": [], \"int_incoming_record\": false, \"ext_incoming_record\": false, \"outgoing_day_limit\": 0.0, \"applications\": [], \"account_codes\": []}');" | sudo -u postgres psql ucs
echo "UPDATE groups SET settings_id = 1;" | sudo -u postgres psql ucs

echo "* Creating default config..."
echo "INSERT INTO config VALUES ('DB_VERSION', '$DBVERSION', 'int');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('HOST', '$MAINIP', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('HOSTNAME', '$DOMAIN', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('JABBER_REALM', '$DOMAIN', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SSO_KEY', '$SSOKEY', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('INTERNATIONAL_DIALING_PREFIX', '00', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ORGANIZATION', '$ORGANIZATION', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('DNS_PRIMARY', '$PRIMARYDNS', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('DNS_SECONDARY', '$SECONDARYDNS', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('PHONE_USER', 'admin', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('PHONE_PASS', '$PASS', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_MAJOR', '1.8', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('CC_STATS_PERIOD', 300, 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('LOG_AGENTS', 't', 'bool');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('LOG_PRESENCE', 't', 'bool');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('CURRENCY', 'CZK', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('LANGUAGE', 'cs_CZ', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('FRST_LAST_DISPLAYNAME', 't', 'bool');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('UNITTEST', '0', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('LOG_LEVEL', '4', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('LOG_STDOUT', '4', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SESSION_TIMEOUT', '900', 'int');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('ROOT', '/opt/ucs', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_CTL', '/var/run/asterisk.ctl', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_EXTENSIONS', '/etc/asterisk/extensions.conf', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_EXTENSIONS_MERGE', '/etc/asterisk/extensions.merge', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_MUSICONHOLD', '/etc/asterisk/musiconhold.conf', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_QUEUES', '/etc/asterisk/queues.conf', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_QUEUES_MERGE', '/etc/asterisk/queues.merge', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_SIP', '/etc/asterisk/sip.conf', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_SIP_EM', '/etc/asterisk/sip_em.conf', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_SIP_MERGE', '/etc/asterisk/sip.merge', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_VOICEMAIL', '/etc/asterisk/voicemail.conf', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('ASTERISK_VOICEMAIL_MERGE', '/etc/asterisk/voicemail.merge', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('POLYCOM_FTP', '/var/lib/tftp/polycom', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('TFTP_ROOT', '/var/lib/tftp', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('VOICEMAIL_ROOT', '/var/spool/asterisk/voicemail', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('AGI_ADDR', '127.0.0.1', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('AGI_PORT', '4573', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('AMI_ADDR', '127.0.0.1', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('AMI_PORT', '5038', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('AMI_USER', 'admin', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('AMI_PASS', 'god', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('JABBER_ADDR', '0.0.0.0', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('JABBER_PORT', '5222', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('XMLRPC_ADDR', '0.0.0.0', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('XMLRPC_PORT', '1234', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('XCM_ADDR', '0.0.0.0', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('XCM_PORT', '3013', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('XMS_ADDR', '0.0.0.0', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('XMS_PORT', '3030', 'int');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('SNMP_ADDR', '0.0.0.0', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SNMP_PORT', '161', 'int');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SNMP_COMMUNITY', 'public', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SNMP_CONTACT', 'Contact person.', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SNMP_NAME', '$DOMAIN', 'str');" | sudo -u postgres psql ucs
echo "INSERT INTO config VALUES ('SNMP_LOCATION', 'Server location.', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('NETWORK_INTERFACES', '# created by UCS - do not modify
auto lo
iface lo inet loopback
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('NETWORK_HOSTS', '# created by UCS - do not modify
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('SIP_GENERAL', '; created by UCS - do not modify
[general]
nat=no
disallow=all
allow=alaw
allow=g722
allow=h264
allow=h263p
allow=h263
videosupport=yes
tos_sip=cs3
tos_audio=ef
tos_video=af41
tos_text=af41
cos_sip=3
cos_audio=5
cos_video=4
cos_text=3
canreinvite=no
bindport=5060
bindaddr=0.0.0.0
tcpenable=yes
transport=udp,tcp
srvlookup=no
language=cs
qualify=yes
callevents=yes
maxexpirey=900
defaultexpirey=600
useragent=Asterisk UCS
sdpsession=Asterisk UCS
externip=$EXTERNIP
localnet=10.0.0.0/255.0.0.0
localnet=172.16.0.0/255.240.0.0
localnet=192.168.0.0/255.255.0.0
context=trunk-1
pedantic=no
sendrpid=no
notifyringing=yes
notifyhold=yes
callcounter=yes
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('SIP_FRIEND', '[%(name)s]
type=%(type)s
context=%(context)s
secret=%(secret)s
host=%(host)s
t38pt_udptl=no
callerid=%(ext_name)s <%(ext)s>
setvar=EXT=%(ext)s
setvar=EXT_NAME=%(ext_name)s
setvar=EXT_ID_SRC=%(ext_id)s
setvar=CALL_SRC=1
setvar=GROUP_ID_SRC=%(group_id)s
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('SIP_PEER', '[trunk-%(trunk_id)s]
type=peer
host=%(host)s
port=%(port)s
setvar=CALL_SRC=0
setvar=EARLY_MEDIA=%(earlymedia)s
context=trunk-%(trunk_id)s
insecure=invite
nat=yes
qualify=no
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('SIP_PEER_PW', '[%(name)s]
type=friend
secret=%(secret)s
host=%(host)s
port=%(port)s
setvar=CALL_SRC=0
setvar=EARLY_MEDIA=%(earlymedia)s
context=trunk-%(trunk_id)s
nat=yes
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('EXTENSIONS_GENERAL', '; created by UCS - do not modify
[general]
priorityjumping=no
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('QUEUES_GENERAL', '; created by UCS - do not modify
[general]
persistentmembers = yes
monitor-type = MixMonitor
shared_lastcall=yes
', 'str');" | sudo -u postgres psql ucs

echo "INSERT INTO config VALUES ('VOICEMAIL_GENERAL', '; created by UCS - do not modify
[general]
format=wav
serveremail=$MAIL
attach=yes
maxmsg=100
maxsecs=600
minsecs=3
maxgreet=60
skipms=3000
maxsilence=3
silencethreshold=128
charset=ISO-8859-2
emailsubject=Nova zprava na zaznamniku od \${VM_CALLERID}
emailbody=Na zaznamniku je nova zprava:\\n\\nPrijata: \${VM_DATE}\\nOd: \${VM_CALLERID}\\nDelka: \${VM_DUR}s\\nCislo zpravy: \${VM_MSGNUM}\\n
emaildateformat=%e.%m.%Y v %H:%M:%S
sendvoicemail=yes
', 'str');" | sudo -u postgres psql ucs

echo "* Creating default firewall chains..."
echo "INSERT INTO firewall VALUES (1, 'filter', 'INPUT', true, 'Incoming packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (2, 'filter', 'FORWARD', true, 'Forwarding packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (3, 'filter', 'OUTPUT', true, 'Outgoing packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (4, 'nat', 'PREROUTING', true, 'Before routing (DNAT)');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (5, 'nat', 'OUTPUT', true, 'Locally generated packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (6, 'nat', 'POSTROUTING', true, 'After routing (SNAT)');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (7, 'mangle', 'PREROUTING', true, 'Before routing');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (8, 'mangle', 'INPUT', true, 'Incoming packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (9, 'mangle', 'FORWARD', true, 'Forwarding packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (10, 'mangle', 'OUTPUT', true, 'Outgoing packets');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (11, 'mangle', 'POSTROUTING', true, 'After routing');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (12, 'raw', 'PREROUTING', true, 'Before routing');" | sudo -u postgres psql ucs
echo "INSERT INTO firewall VALUES (13, 'raw', 'OUTPUT', true, 'Locally generated packets');" | sudo -u postgres psql ucs

echo "INSERT INTO callpickup VALUES (0, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (1, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (2, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (3, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (4, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (5, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (6, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (7, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (8, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (9, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (10, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (11, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (12, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (13, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (14, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (15, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (16, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (17, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (18, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (19, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (20, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (21, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (22, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (23, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (24, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (25, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (26, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (27, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (28, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (29, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (30, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (31, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (32, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (33, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (34, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (35, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (36, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (37, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (38, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (39, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (40, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (41, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (42, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (43, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (44, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (45, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (46, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (47, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (48, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (49, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (50, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (51, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (52, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (53, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (54, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (55, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (56, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (57, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (58, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (59, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (60, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (61, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (62, 1, NULL);" | sudo -u postgres psql ucs
echo "INSERT INTO callpickup VALUES (63, 1, NULL);" | sudo -u postgres psql ucs

echo ''
echo 'DONE.'
