#!/bin/sh version=$(psql -qAt -U postgres -c "select value from provisioning_params where name='databaseversion'" provisioning) if [ -z "$version" ]; then version="0" fi echo "Version $version" if [ "$version" -lt "1" ]; then echo "Upgrading to database version 1" # if current is older than 0.0.7-r1 we update. #if [ "$(apk version -t $old 0.0.7-r1)" = "<" ]; then psql -U postgres -c "INSERT INTO provisioning_classes VALUES(default, (SELECT class_group_id FROM provisioning_class_groups WHERE name='device'), 'Unsupported Phone', '999')"\ provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg1', 'Registration 1 Unsupported', '10')"\ provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Unsupported Phone'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 1 Unsupported'))"\ provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 1 Unsupported'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)"\ provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 1 Unsupported'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, true)"\ provisioning #fi # if current is older than 0.0.8 we update. #if [ "$(apk version -t $old 0.0.8)" = "<" ]; then psql -U postgres -c "ALTER TABLE provisioning_params ADD COLUMN validate text" provisioning psql -U postgres -c "UPDATE provisioning_params SET descr='Phone dial pattern based on section 2.1.5 of RFC 3435, plus a comma to turn dialtone back on', regexp='^[*#0-9xT|,.%[%]-]*\$' WHERE name='digitmap'" provisioning psql -U postgres -c "UPDATE provisioning_params SET descr='Timeout in seconds for each segment of digit map (separated by ''|'')', regexp='^[0-9|]*\$' WHERE name='digitmaptimeout'" provisioning psql -U postgres -c "UPDATE provisioning_params SET regexp='^%x%x%x%x%x%x%x%x%x%x%x%x\$', validate='local value, functions, params = ...\nvalue = string.upper(value)\nlocal others = functions.getselectresponse(\"SELECT count(*) FROM provisioning_values WHERE param_id=\\'\"..params.value.device.value.mac.param_id..\"\\' AND device_id!=\\'\"..params.value.device_id.value..\"\\' AND value=\\'\"..value..\"\\'\")\nif tonumber(others[1].count) > 0 then\n\treturn value, \"MAC Address must be unique\"\nend\nreturn value' WHERE name='mac'" provisioning psql -U postgres -c "INSERT INTO provisioning_params VALUES(default, 'callwaitingenable', 'boolean', 'Call Waiting Enable', '', 'true', '205', '', null)" provisioning psql -U postgres -c "INSERT INTO provisioning_params VALUES(default, 'speeddialenable', 'boolean', 'Speed Dial Enable', '', 'true', '206', '', null)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Standard Phone'), (SELECT param_id FROM provisioning_params WHERE name='callwaitingenable'), 'true', false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Standard Phone'), (SELECT param_id FROM provisioning_params WHERE name='speeddialenable'), 'true', false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Public Phone'), (SELECT param_id FROM provisioning_params WHERE name='callwaitingenable'), 'true', false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Public Phone'), (SELECT param_id FROM provisioning_params WHERE name='speeddialenable'), 'false', false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Hotline'), (SELECT param_id FROM provisioning_params WHERE name='callwaitingenable'), 'true', false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Hotline'), (SELECT param_id FROM provisioning_params WHERE name='speeddialenable'), 'false', false)" provisioning #fi # if current is older than 0.0.9 we update. #if [ "$(apk version -t $old 0.0.9)" = "<" ]; then psql -U postgres -c "INSERT INTO provisioning_params VALUES(default, 'mailbox', 'text', 'Voice Mailbox', 'Mailbox extension or URL', '', '207', '', null)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Standard Phone'), (SELECT param_id FROM provisioning_params WHERE name='mailbox'), '', true)" provisioning #fi # if current is older than 0.0.11 we update. #if [ "$(apk version -t $old 0.0.11)" = "<" ]; then psql -U postgres -c "INSERT INTO provisioning_classes VALUES(default, (SELECT class_group_id FROM provisioning_class_groups WHERE name='device'), 'Polycom SoundPoint IP 450 SIP', '2')" provisioning psql -U postgres -c "INSERT INTO provisioning_classes VALUES(default, (SELECT class_group_id FROM provisioning_class_groups WHERE name='device'), 'Polycom SoundPoint IP 550/560 SIP', '3')" provisioning psql -U postgres -c "INSERT INTO provisioning_classes VALUES(default, (SELECT class_group_id FROM provisioning_class_groups WHERE name='device'), 'Polycom VVX 1500', '6')" provisioning psql -U postgres -c "UPDATE provisioning_classes SET label='Polycom SoundStation IP 5000/6000/7000 SIP', seq='5' WHERE label='Polycom SoundStation IP 6000 SIP'" provisioning psql -U postgres -c "UPDATE provisioning_classes SET label='Polycom SoundPoint IP 320/321/330/331/335 SIP', seq='1' WHERE label='Polycom SoundPoint IP 321/331/335 SIP'" provisioning psql -U postgres -c "UPDATE provisioning_classes SET label='Polycom SoundPoint IP 650/670 SIP', seq='4' WHERE label='Polycom SoundPoint IP 650 SIP'" provisioning psql -U postgres -c "UPDATE provisioning_classes SET seq='7' WHERE label='Linksys Internet Phone Adapter PAP2T'" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 450 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 1'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 450 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 2'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 450 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 3'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 450 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Polycom Device'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 550/560 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 1'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 550/560 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 2'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 550/560 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 3'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 550/560 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 4'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom SoundPoint IP 550/560 SIP'), (SELECT group_id FROM provisioning_groups WHERE label='Polycom Device'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom VVX 1500'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 1'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom VVX 1500'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 2'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom VVX 1500'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 3'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom VVX 1500'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 4'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom VVX 1500'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 5'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Polycom VVX 1500'), (SELECT group_id FROM provisioning_groups WHERE label='Polycom Device'))" provisioning psql -U postgres -c "UPDATE param_groups_to_params SET value=null WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Standard Phone') AND param_id=(SELECT param_id FROM provisioning_params WHERE name='mailbox')" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Standard Phone'), (SELECT param_id FROM provisioning_params WHERE name='mailcallback'), null, true)" provisioning psql -U postgres -c "INSERT INTO provisioning_params VALUES(default, 'mailcallback', 'text', 'Voice Mailbox Callback', 'Extension or URL for mailbox message retrieval', '', '208', '', null)" provisioning #fi # if current is older than 0.1.1 we update. #if [ "$(apk version -t $old 0.1.1)" = "<" ]; then psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'device', 'Snom Device', '1')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg1', 'Registration 1 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg2', 'Registration 2 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg3', 'Registration 3 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg4', 'Registration 4 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg5', 'Registration 5 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg6', 'Registration 6 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg7', 'Registration 7 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg8', 'Registration 8 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg9', 'Registration 9 No Forwarding', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg10', 'Registration 10 No Forwarding', '11')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg11', 'Registration 11 No Forwarding', '11')" provisioning psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg12', 'Registration 12 No Forwarding', '11')" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='template'), '/etc/provisioning/templates/snom-template.lua', false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='mac'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='registrar'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='digitmap'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='digitmaptimeout'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='sntpserver'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='timezone'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='musiconhold'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='adminpassword'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='pcportenable'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='urldialingenable'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='forwardnoanswer'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='forwardnoanswerenable'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='forwardbusy'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='forwardbusyenable'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='forwardall'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Snom Device'), (SELECT param_id FROM provisioning_params WHERE name='forwardallenable'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 1 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 1 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 1 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 2 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 2 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 2 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 3 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 3 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 3 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 4 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 4 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 4 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 5 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 5 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 5 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 6 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 6 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 6 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 7 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 7 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 7 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 8 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 8 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 8 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 9 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 9 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 9 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 10 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 10 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 10 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 11 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 11 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 11 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 12 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 12 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration 12 No Forwarding'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='template'), 'Snom', '/etc/provisioning/templates/snom-template.lua', '3')" provisioning psql -U postgres -c "INSERT INTO provisioning_classes VALUES(default, (SELECT class_group_id FROM provisioning_class_groups WHERE name='device'), 'Snom 300', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_classes VALUES(default, (SELECT class_group_id FROM provisioning_class_groups WHERE name='device'), 'Snom 320/360/370', '11')" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 300'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 1 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 300'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 2 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 300'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 3 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 300'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 4 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 300'), (SELECT group_id FROM provisioning_groups WHERE label='Snom Device'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 1 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 2 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 3 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 4 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 5 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 6 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 7 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 8 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 9 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 10 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 11 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Registration 12 No Forwarding'))" provisioning psql -U postgres -c "INSERT INTO classes_to_param_groups VALUES((SELECT class_id FROM provisioning_classes WHERE label='Snom 320/360/370'), (SELECT group_id FROM provisioning_groups WHERE label='Snom Device'))" provisioning psql -U postgres -c "UPDATE provisioning_params SET value='UTC0' WHERE name='timezone' and value=''" provisioning #fi # if current is older than 0.1.2 we update. #if [ "$(apk version -t $old 0.1.2)" = "<" ]; then for a in $(seq 1 34); do psql -U postgres -c "UPDATE provisioning_groups SET label='Registration $a (Polycom)' WHERE label='Registration $a'" provisioning psql -U postgres -c "DELETE FROM param_groups_to_params WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration $a')" provisioning psql -U postgres -c "DELETE FROM classes_to_param_groups WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration $a')" provisioning psql -U postgres -c "DELETE FROM provisioning_groups WHERE label='Registration $a'" provisioning done for a in $(seq 1 12); do psql -U postgres -c "UPDATE provisioning_groups SET label='Registration $a (Snom)' WHERE label='Registration $a No Forwarding'" provisioning psql -U postgres -c "DELETE FROM param_groups_to_params WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration $a No Forwarding')" provisioning psql -U postgres -c "DELETE FROM classes_to_param_groups WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration $a No Forwarding')" provisioning psql -U postgres -c "DELETE FROM provisioning_groups WHERE label='Registration $a No Forwarding'" provisioning done psql -U postgres -c "UPDATE provisioning_groups SET label='Registration 1 (Unsupported)' WHERE label='Registration 1 Unsupported'" provisioning psql -U postgres -c "DELETE FROM param_groups_to_params WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration 1 Unsupported')" provisioning psql -U postgres -c "DELETE FROM classes_to_param_groups WHERE group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration 1 Unsupported')" provisioning psql -U postgres -c "DELETE FROM provisioning_groups WHERE label='Registration 1 Unsupported'" provisioning for a in $(seq 1 2); do psql -U postgres -c "INSERT INTO provisioning_groups VALUES(default, 'reg$a', 'Registration $a (Linksys)', '10')" provisioning psql -U postgres -c "UPDATE classes_to_param_groups SET group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)') WHERE class_id=(SELECT class_id FROM provisioning_classes WHERE label='Linksys Internet Phone Adapter PAP2T') AND group_id=(SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Polycom)')" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='extension'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='password'), null, false)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='forwardnoanswer'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='forwardnoanswerenable'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='forwardbusy'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='forwardbusyenable'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='forwardall'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='forwardallenable'), null, true)" provisioning psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Linksys)'), (SELECT param_id FROM provisioning_params WHERE name='callerid'), null, true)" provisioning done psql -U postgres -c "INSERT INTO provisioning_params VALUES(default, 'polycomringtone', 'select', 'Ring Tone (Polycom)', '', '2', '110', '', null)" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Silent Ring', '1', '1')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Low Trill', '2', '2')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Low Double Trill', '3', '3')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Medium Trill', '4', '4')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Medium Double Trill', '5', '5')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'High Trill', '6', '6')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'High Double Trill', '7', '7')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Highest Trill', '8', '8')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Highest Double Trill', '9', '9')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Beeble', '10', '10')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Triplet', '11', '11')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Ringback-style', '12', '12')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Low Trill Precedence', '13', '13')" provisioning psql -U postgres -c "INSERT INTO provisioning_options VALUES((SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), 'Ring Splash', '14', '14')" provisioning for a in $(seq 1 34); do psql -U postgres -c "INSERT INTO param_groups_to_params VALUES((SELECT group_id FROM provisioning_groups WHERE label='Registration $a (Polycom)'), (SELECT param_id FROM provisioning_params WHERE name='polycomringtone'), null, true)" provisioning done #fi psql -U postgres -c "INSERT INTO provisioning_params VALUES(default, 'databaseversion', 'text', 'Provisioning Database Version', 'Do not edit or delete!', '1', '999', '', null)" provisioning psql -U postgres -c "UPDATE provisioning_params SET value='1' WHERE name='databaseversion'" provisioning fi if [ "$version" -lt "2" ]; then echo "Upgrading to database version 2" # provisioning_params validate field changed the order of the first two Lua parameters $(pwd)/swapvalidateparams psql -U postgres -c "UPDATE provisioning_params SET value='2' WHERE name='databaseversion'" provisioning fi exit 0