2017-08-24 22:10:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2017-12-23 10:34:49 +01:00
|
|
|
# This script only works with MySQL - it does:
|
|
|
|
#
|
|
|
|
# 1- updates c_defaults and c_settings to longtext in the sogo_user_profile table
|
|
|
|
# to avoid truncation of data at 64k
|
|
|
|
# 2- increase the c_mail column to text to contact quick table
|
|
|
|
# 3- add the c_hascertificate column to contact quick table
|
2017-08-24 22:10:30 +02:00
|
|
|
|
|
|
|
defaultusername=$USER
|
|
|
|
defaulthostname=127.0.0.1
|
|
|
|
defaultdatabase=sogo
|
2017-10-24 20:19:25 +02:00
|
|
|
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
|
2018-01-25 16:12:07 +01:00
|
|
|
storeurl=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ OCSStoreURL =/ {print $2}' | awk -F/ '{print $NF}')
|
2017-08-24 22:10:30 +02:00
|
|
|
|
|
|
|
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 growUserProfile() {
|
|
|
|
oldIFS="$IFS"
|
|
|
|
IFS=" "
|
|
|
|
part="`echo -e \"ALTER TABLE sogo_user_profile MODIFY c_defaults LONGTEXT;\\n\"`";
|
|
|
|
sqlscript="$sqlscript$part"
|
|
|
|
part="`echo -e \"ALTER TABLE sogo_user_profile MODIFY c_settings LONGTEXT;\\n\"`";
|
|
|
|
sqlscript="$sqlscript$part"
|
|
|
|
IFS="$oldIFS"
|
|
|
|
}
|
|
|
|
|
2017-12-23 10:34:49 +01:00
|
|
|
function growMailInContactsQuick() {
|
2017-10-24 20:19:25 +02:00
|
|
|
oldIFS="$IFS"
|
|
|
|
IFS=" "
|
|
|
|
part="`echo -e \"ALTER TABLE $table MODIFY c_mail text;\\n\"`";
|
|
|
|
sqlscript="$sqlscript$part"
|
|
|
|
IFS="$oldIFS"
|
|
|
|
}
|
|
|
|
|
2017-12-23 10:34:49 +01:00
|
|
|
function addCertificateInContactsQuick() {
|
|
|
|
oldIFS="$IFS"
|
|
|
|
IFS=" "
|
|
|
|
part="`echo -e \"ALTER TABLE $table ADD c_hascertificate INT4 DEFAULT 0;\\n\"`";
|
|
|
|
sqlscript="$sqlscript$part"
|
|
|
|
IFS="$oldIFS"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-24 20:19:25 +02:00
|
|
|
echo "This script will ask for the database password twice" >&2
|
2017-08-24 22:10:30 +02:00
|
|
|
echo "Converting c_content from TEXT to LONGTEXT in the sogo_user_profile table" >&2
|
|
|
|
growUserProfile
|
|
|
|
|
2017-10-24 20:19:25 +02:00
|
|
|
echo "Converting c_mail from VARCHAR(255) to TEXT in Contacts quick tables" >&2
|
2018-01-25 16:12:07 +01:00
|
|
|
if [ -z "$storeurl" ]; then
|
|
|
|
tables=`mysql -p -s -u $username -h $hostname $database -e "select SUBSTRING_INDEX(c_quick_location, '/', -1) from $indextable where c_path3 = 'Contacts';"`
|
|
|
|
else
|
|
|
|
tables="sogo_quick_contact"
|
|
|
|
fi
|
|
|
|
|
2017-10-24 20:19:25 +02:00
|
|
|
for table in $tables;
|
|
|
|
do
|
2017-12-23 10:34:49 +01:00
|
|
|
growMailInContactsQuick
|
|
|
|
addCertificateInContactsQuick
|
2017-10-24 20:19:25 +02:00
|
|
|
done
|
|
|
|
|
2018-01-26 16:10:41 +01:00
|
|
|
echo "$sqlscript" | mysql -p -f -s -u $username -h $hostname $database
|