-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathsql-update-3.2.10_to_4.0.0.sh
executable file
·69 lines (58 loc) · 1.86 KB
/
sql-update-3.2.10_to_4.0.0.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -e
# This script only works with PostgreSQL - it does:
#
# 1- increase the c_mail column to text to contact quick table
# 2- add the c_hascertificate column to contact quick table
defaultusername=$USER
defaulthostname=localhost
defaultdatabase=sogo
indextable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSFolderInfoURL =/ {print $2}' | awk -F/ '{print $NF}')
if [ -z "$indextable" ]; then
echo "Couldn't fetch OCSFolderInfoURL value, aborting" >&2
exit 1
fi
storeurl=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSStoreURL =/ {print $2}' | awk -F/ '{print $NF}')
read -p "Username ($defaultusername): " username
read -p "Hostname ($defaulthostname): " hostname
read -p "Database ($defaultdatabase): " database
if [ -z "$username" ]
then
username=$defaultusername
fi
if [ -z "$hostname" ]
then
hostname=$defaulthostname
fi
if [ -z "$database" ]
then
database=$defaultdatabase
fi
sqlscript=""
function growMailInContactsQuick() {
oldIFS="$IFS"
IFS=" "
part="`echo -e \"ALTER TABLE $table ALTER COLUMN c_mail TYPE TEXT;\\n\"`";
sqlscript="$sqlscript$part"
IFS="$oldIFS"
}
function addCertificateInContactsQuick() {
oldIFS="$IFS"
IFS=" "
part="`echo -e \"ALTER TABLE $table ADD c_hascertificate INT4 DEFAULT 0;\\n\"`";
sqlscript="$sqlscript$part"
IFS="$oldIFS"
}
echo "This script will ask for the database password twice" >&2
echo "Converting c_mail from VARCHAR(255) to TEXT in Contacts quick tables" >&2
if [ -z "$storeurl" ]; then
tables=`psql -t -U $username -h $hostname $database -c "select split_part(c_quick_location, '/', 5) from $indextable where c_path3 = 'Contacts';"`
else
tables="sogo_quick_contact"
fi
for table in $tables;
do
growMailInContactsQuick
addCertificateInContactsQuick
done
echo "$sqlscript" | psql -q -e -U $username -h $hostname $database