On Wed, 11 Nov 2009 13:21:59 +0000
Hugo Monteiro <hugo.monte...@fct.unl.pt> wrote:

> Hi Julien et al,
> 
Hallo Hugo,


> Since you've been packaging DSPAM for a while now, for debian that is, i 
> was wondering if you have made any efforts to produce a post-install 
> script that would convert the database layout needed for upgrade from 
> 3.8.0 to the new 3.9.x series. Though i believe it's a rather simple 
> thing to do, i'm not very confortable with debconf to produce such a script.
> Any help from you, or others, would be much appreciated.
> 
You mean something like this:
------------------------------
#!/bin/sh

#
# Get DSPAM configuration file
#
_ds_conf="$(dspam --version | sed -n 
"s:^.*\-\-sysconfdir=\([^']*\).*:\1/dspam.conf:gp")"
if [ "${_ds_conf}" == "" -o ! -r "${_ds_conf}" ]
then
        echo "Can not read your dspam.conf file"
        exit 2
fi

#
# Get storage backend data
#
_ds_profile="$(sed -n "s:^DefaultProfile[\t ]\{1,99\}[\"']*\(.*\)[\"']*[\t 
]*$:\\\.\1:gp" ${_ds_conf}|head -n 1)"
_ds_server="$(sed -n "s:^MySQLServer${_ds_profile}[\t 
]\{1,99\}[\"']*\(.*\)[\"']*[\t ]*$:\1:gp" ${_ds_conf}|head -n 1)"
_ds_port="$(sed -n "s:^MySQLPort${_ds_profile}[\t 
]\{1,99\}[\"']*\(.*\)[\"']*[\t ]*$:\1:gp" ${_ds_conf}|head -n 1)"
_ds_user="$(sed -n "s:^MySQLUser${_ds_profile}[\t 
]\{1,99\}[\"']*\(.*\)[\"']*[\t ]*$:\1:gp" ${_ds_conf}|head -n 1)"
_ds_pass="$(sed -n "s:^MySQLPass${_ds_profile}[\t 
]\{1,99\}[\"']*\(.*\)[\"']*[\t ]*$:\1:gp" ${_ds_conf}|head -n 1)"
_ds_db="$(sed -n "s:^MySQLDb${_ds_profile}[\t ]\{1,99\}[\"']*\(.*\)[\"']*[\t 
]*$:\1:gp" ${_ds_conf}|head -n 1)"

#
# MySQL connect string
#
_mysql_dsn=""
if [ "${_ds_server:0:1}" == "/" ]
then
        _mysql_dsn="${_mysql_dsn} --socket=${_ds_server}"
else
        _mysql_dsn="${_mysql_dsn} --host=${_ds_server}"
        if [ "${_ds_port}" != "" ]
        then
                _mysql_dsn="${_mysql_dsn} --port=${_ds_port}"
        fi
fi
_mysql_dsn="--user=${_ds_user} --password=${_ds_pass} ${_mysql_dsn}"

#
# Instructions we would like to run against MySQL to upgrade
# the database schema
#
_ds_upgrade[1]='ALTER TABLE `dspam_signature_data` CHANGE `uid` `uid` INT 
UNSIGNED NOT NULL, CHANGE `data` `data` LONGBLOB NOT NULL, CHANGE `length` 
`length` INT UNSIGNED NOT NULL;'
_ds_upgrade[2]='ALTER TABLE `dspam_stats` CHANGE `uid` `uid` INT UNSIGNED NOT 
NULL, CHANGE `spam_learned` `spam_learned` BIGINT UNSIGNED NOT NULL, CHANGE 
`innocent_learned` `innocent_learned` BIGINT UNSIGNED NOT NULL, CHANGE 
`spam_misclassified` `spam_misclassified` BIGINT UNSIGNED NOT NULL, CHANGE 
`innocent_misclassified` `innocent_misclassified` BIGINT UNSIGNED NOT NULL, 
CHANGE `spam_corpusfed` `spam_corpusfed` BIGINT UNSIGNED NOT NULL, CHANGE 
`innocent_corpusfed` `innocent_corpusfed` BIGINT UNSIGNED NOT NULL, CHANGE 
`spam_classified` `spam_classified` BIGINT UNSIGNED NOT NULL, CHANGE 
`innocent_classified` `innocent_classified` BIGINT UNSIGNED NOT NULL;'
_ds_upgrade[3]='ALTER TABLE `dspam_token_data` CHANGE `uid` `uid` INT UNSIGNED 
NOT NULL, CHANGE `spam_hits` `spam_hits` BIGINT UNSIGNED NOT NULL, CHANGE 
`innocent_hits` `innocent_hits` BIGINT UNSIGNED NOT NULL;'
_ds_upgrade[4]='ALTER TABLE `dspam_preferences` CHANGE `uid` `uid` INT UNSIGNED 
NOT NULL;'
_ds_upgrade[5]='ALTER TABLE `dspam_virtual_uids` CHANGE `uid` `uid` INT 
UNSIGNED NOT NULL AUTO_INCREMENT;'
_ds_upgrade[6]='ALTER TABLE `dspam_virtual_uids` CHANGE `uid` `uid` INT 
UNSIGNED NOT NULL;'
_ds_upgrade[7]='ALTER TABLE `dspam_token_data` ADD INDEX(`spam_hits`), ADD 
INDEX(`innocent_hits`), ADD INDEX(`last_hit`);'

#
# Start processing
#
echo "Updating 'dspam_signature_data'"
mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[1]}" ${_ds_db}

echo "Updating 'dspam_stats'"
mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[2]}" ${_ds_db}

echo "Updating 'dspam_token_data'"
mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[3]}" ${_ds_db}

echo "Updating 'dspam_preferences'"
mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[4]}" ${_ds_db}

echo "Updating 'dspam_virtual_uids'"
if (mysql ${_mysql_dsn} --batch -e 'DESCRIBE `dspam_virtual_uids`' ${_ds_db} | 
grep -q "^uid[[:space:]]\{1,99\}.*auto_increment$")
then
        mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[5]}" ${_ds_db}
else
        mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[6]}" ${_ds_db}
fi

echo "Adding indices to 'dspam_token_data'"
mysql ${_mysql_dsn} --batch -e "${_ds_upgrade[7]}" ${_ds_db}

#
# Finish
#
echo "DONE!"
------------------------------


> Regards,
> 
Kind Regards from Switzerland,


> Hugo Monteiro.
> 
Stevan Bajić


> -- 
> ci.fct.unl.pt:~# cat .signature
> 
> Hugo Monteiro
> Email  : hugo.monte...@fct.unl.pt
> Telefone : +351 212948300 Ext.15307
> Web      : http://hmonteiro.net
> 
> Centro de Informática
> Faculdade de Ciências e Tecnologia da
>                  Universidade Nova de Lisboa
> Quinta da Torre   2829-516 Caparica   Portugal
> Telefone: +351 212948596   Fax: +351 212948548
> www.ci.fct.unl.pt           ap...@fct.unl.pt
> 
> ci.fct.unl.pt:~# _
> 
> 
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Dspam-devel mailing list
> Dspam-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dspam-devel
> 

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Dspam-devel mailing list
Dspam-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspam-devel

Reply via email to