#!/bin/bash # # Copyright (C) 2006-2009 Eric Shubert # # do any conversions necessary for newer versions of the toaster # ################################################################################ # # change log # 08/04/12 shubes - fixed vpopmail 5.4.18 mods to do only after 5.4.17 # (was doing <= instead of >) # 08/22/09 shubes - only do database conversions when we're not in a sandbox # 07/19/09 shubes - added vpopmail 5.4.18 mysql database mods # 04/05/08 shubes - changed `` to $() # 11/03/06 shubes - added .qmail-alias conversion (commented out) # 10/20/06 shubes - split out from qtp-newmodel # - added logic to handle v1.0 upgrades: # migrate vpopmail password to new file # ################################################################################ ## check and set up the environment # a1_initialization(){ # Make sure we're root if [ "$UID" != "0" ]; then echo "Error: You are not root, please su -" exit 1 fi . qtp-config -s } ################################################################################ # move mrtg files to new location # this was a change from version ?? to version ?? # a2_convert_mrtg(){ OLDDIR=/usr/share/toaster/mrtg if [ -f "$OLDDIR/*.png" ] \ || [ -f "$OLDDIR/*.meta" ] \ || [ -f "$OLDDIR/*.html" ] \ || [ -f "$OLDDIR/*.log" ] \ || [ -f "$OLDDIR/*.old" ]; then NEWDIR=/usr/share/toaster/htdocs/mrtg echo "Migrating mrtg files from $OLDDIR to $NEWDIR ..." if [ -f "$OLDDIR/*.png" ]; then mv $OLDDIR/*.png $NEWDIR/. fi if [ -f "$OLDDIR/*.meta" ]; then mv $OLDDIR/*.meta $NEWDIR/. fi if [ -f "$OLDDIR/*.html" ]; then mv $OLDDIR/*.html $NEWDIR/. fi if [ -f "$OLDDIR/*.log" ]; then mv $OLDDIR/*.log $NEWDIR/. fi if [ -f "$OLDDIR/*.old" ]; then mv $OLDDIR/*.old $NEWDIR/. fi fi } ################################################################################ # check for old style (toaster v1.0) vpopmail mysql control file # a3_convert_mysqlpw(){ old_mysql=/var/qmail/control/sql mysqlpw=$(grep "pass " $old_mysql 2>/dev/null) if [ ! -z "$mysqlpw" ]; then new_mysql=/home/vpopmail/etc/vpopmail.mysql echo "vpopmail MySQL settings vpopmail have moved" echo "from $old_mysql to $new_mysql" echo "Password is being updated from your old settings" echo "localhost|0|vpopmail|${mysqlpw#pass +}|vpopmail" >$new_mysql mv $old_mysql ${old_mysql}.save fi } ################################################################################ # convert data that resides in a service/server # a5_convert_server_data(){ #b52_convert_dotqmail_aliases b53_convert_vpopmail_mysql # if [ -f ~vpopmail/etc/vpopmail.ldap ] && # ldap tables are empty (no conversion has been done yet) b56_convert_vpopmail_ldqp } ################################################################################ # Convert old .qmail aliases to new format # b52_convert_dotqmail_aliases(){ /home/vpopmail/bin/dotqmail2valias -a } ################################################################################ # check database mods for vpopmail 5.4.18 upgrade # b53_convert_vpopmail_mysql(){ QMT_PKGNAME=vpopmail-toaster QMT_VERSION=5.4.17-1.3.7 installed_pkgver=$(rpm -q $QMT_PKGNAME) x01_compare_versions if [ "$?" == "0" ]; then # the installed version is > 5.4.17-1.3.7 domain_field=$(c532_do_mysql "desc dir_control" | grep domain) echo "$domain_field" | grep "char(64)" >/dev/null 2>&1 if [ "$?" == "0" ]; then # the domain field has not been expanded yet for table in dir_control lastauth valias; do c532_do_mysql "ALTER TABLE \`$table\` CHANGE \`domain\` \`domain\` CHAR(96) NOT NULL;" done echo "$me - changed domain fields in vpopmail database from 64 to 96 bytes" fi fi } ################################################################################ ## execute a command against the vpopmail mysql database # c532_do_mysql(){ if [ "$mysql_port" == "0" ]; then mysql_portparm="" else mysql_portparm="--port=$mysqlport" fi mysql --user="$mysql_user" \ --password="$mysql_password" \ --host="$mysql_host" \ $mysql_portparm \ --execute="$1" \ --database="$mysql_database" } ################################################################################ # convert mysql database to ldap # b56_convert_vpopmail_ldqp(){ : # TODO } ################################################################################ ## main script execution begins here # me=${0##*/} myver=v0.3.2 echo "$me $myver" a1_initialization a2_convert_mrtg a3_convert_mysqlpw if [ ! -f "/boot/.${SANDBOX##*/}" ]; then a5_convert_server_data fi echo "$me - processing complete" exit 0