diff options
| author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-02-28 17:33:31 +0000 |
|---|---|---|
| committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-02-28 17:33:31 +0000 |
| commit | 3f80e1cad02735f692a5a300ee3b200a21f330aa (patch) | |
| tree | d7bcd3c5d1cfd54c725f4c9a0eb7984632b6be67 /src/bin/mydbgen | |
| parent | 393b5ab26e952f427f40a8ed6d10acfdf6ead96c (diff) | |
Added in support for live updating MySQL databases and the ability to execute commands to Anope through MySQL. Currently database support only applies to NickServ, ChanServ and BotServ but will be expanded soon.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2798 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/bin/mydbgen')
| -rwxr-xr-x | src/bin/mydbgen | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/src/bin/mydbgen b/src/bin/mydbgen new file mode 100755 index 000000000..f3599a252 --- /dev/null +++ b/src/bin/mydbgen @@ -0,0 +1,225 @@ +#!/bin/sh +# +# $Id$ + +# Location of the .sql file with the schema +DBSQL="tables.sql" + +# Schema Version +SVER="1" + +# Local Version, defaults to 0 +LVER="0" + +TFILE="/tmp/.anopedb.$$" + +if [ "`eval echo -n 'a'`" = "-n a" ] ; then + c="\c" +else + n="-n" +fi + +# Fix for bug 10 +for try in HOME/services anope/data ../data data .. . +do + if [ -f "$try/$DBSQL" ]; then + DBFILE="$try/$DBSQL" + fi +done + +if [ ! -f "./$DBFILE" ] ; then + echo "Error: Required file $DBSQL was not found!"; + exit +fi + +echo "" +echo "This script will guide you through the process of configuring your Anope" +echo "installation to make use of MySQL support. This script must be used for both" +echo "new installs as well as for upgrading for users who have a previous version" +echo "of Anope installed" + +while [ -z "$SQLHOST" ] ; do + echo "" + echo "What is the hostname of your MySQL server?" + echo $n "-> $c" + read cc + if [ ! -z "$cc" ] ; then + SQLHOST=$cc + fi +done + +while [ -z "$SQLUSER" ] ; do + echo "" + echo "What is your MySQL username?" + echo $n "-> $c" + read cc + if [ ! -z "$cc" ] ; then + SQLUSER=$cc + fi +done + +OLD_TTY=`stty -g` + +echo "" +echo "What is your MySQL password?" +echo $n "-> $c" +stty -echo echonl +read cc +SQLPASS_PREFIX="" +if [ ! -z "$cc" ] ; then + SQLPASS_PREFIX="-p" + SQLPASS=$cc +fi +stty $OLD_TTY + +mysqlshow -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS >/dev/null 2>&1 +if test "$?" = "1" ; then + echo "Error: Unable to login, verify your login/password and hostname" + exit +fi + +while [ -z "$SQLDB" ] ; do + echo "" + echo "What is the name of the Anope SQL database?" + echo $n "-> $c" + read cc + if [ ! -z "$cc" ] ; then + SQLDB=$cc + fi +done + +MYSQLDUMP="mysqldump -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB" +MYSQLSHOW="mysqlshow -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB" +MYSQL="mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB" + +echo "" + +$MYSQLSHOW | grep -q $SQLDB +if test "$?" = "1" ; then + echo -n "Unable to find databse, creating... " + mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS -Bs -e "create database $SQLDB" >/dev/null 2>&1 + if test "$?" = "0" ; then + echo "done!" + else + echo "failed!" + FAILED="$FAILED 'database creation'" + fi +fi + +$MYSQL -Bs -e "show tables like 'anope_os_core'" | grep -q anope_os_core +if test "$?" = "1" ; then + echo -n "Unable to find Anope schema, creating... " + $MYSQL < $DBFILE + if test "$?" = "0" ; then + echo "done!" + else + echo "failed!" + FAILED="$FAILED 'schema creation'" + fi +else + # Introduced on Anope 1.6.0 -> Table anope_info + $MYSQL -Bs -e "show tables like 'anope_info'" | grep -q anope_info + if test "$?" = "1" ; then + echo -n "Unable to find Anope info table, creating... " + echo "CREATE TABLE anope_info (version int, date datetime) TYPE=MyISAM" > $TFILE + mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB < $TFILE >/dev/null 2>&1 + if test "$?" = "0" ; then + echo "done!" + + else + echo "failed!" + FAILED="$FAILED 'anope_info table'" + fi + else + LVER="$($MYSQL -sB -e "select version from anope_info")" + if test "x$LVER" = "x" ; then + LVER=0 + fi + fi + + # Introduced on Anope 1.5.14.5 -> anope_cs_info.memomax + $MYSQL -Bs -e "describe anope_cs_info memomax" 2> /dev/null | grep -q memomax + if test "$?" = "1" ; then + echo -n "Unable to find anope_cs_info.memomax, altering... " + echo "ALTER TABLE anope_cs_info ADD memomax smallint unsigned NOT NULL default 0" > $TFILE + mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB < $TFILE >/dev/null 2>&1 + if test "$?" = "0" ; then + echo "done!" + + else + echo "failed!" + FAILED="$FAILED 'anope_cs_info.memomax alter'" + fi + fi + + # Introduced on Anope 1.5.14.5 -> anope_cs_info.ttb + $MYSQL -Bs -e "describe anope_cs_info ttb" 2> /dev/null | grep -q ttb + if test "$?" = "1" ; then + echo -n "Unable to find anope_cs_info.ttb, altering... " + echo "ALTER TABLE anope_cs_info ADD ttb smallint NOT NULL default 0" > $TFILE + mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB < $TFILE >/dev/null 2>&1 + if test "$?" = "0" ; then + echo "done!" + + else + echo "failed!" + FAILED="$FAILED 'anope_cs_info.ttb alter'" + fi + fi + + # Introduced on Anope 1.7.7 -> status smallint to inst unsigned. + echo "Blindly altering status for bigger capacity... " + echo "ALTER TABLE anope_ns_alias CHANGE status status int(11) unsigned NOT NULL default 0" > $TFILE + mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB < $TFILE >/dev/null 2>&1 + + # Introduced on Anope 1.7.8 (620) proxy scanner removed. + echo "Removing proxy scanner cache... " + echo "DROP TABLE IF EXISTS anope_os_cache" > $TFILE + mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB < $TFILE >/dev/null 2>&1 + + echo "done!" + +fi + +echo "" + +# Insert initial version number. This will have to be redesigned for 1.7 +if [ $LVER -ne $SVER ]; then +echo -n "Inserting initial version number... " +$MYSQL -Bs -e "delete from anope_info" +echo "INSERT INTO anope_info (version, date) VALUES ($SVER, now())" > $TFILE +$MYSQL < $TFILE >/dev/null 2>&1 +if test "$?" = "0" ; then + echo "done!" +else + echo "failed!" + FAILED="$FAILED 'version insert'" +fi +fi + +rm -f $TFILE +if test "x$FAILED" = "x" ; then + # Try to find out more about this installation + SQLSOCK="$(mysql_config --socket 2> /dev/null)" + SQLPORT="$(mysql_config --port 2> /dev/null)" + echo "" + echo "Your MySQL setup is complete and your Anope schema is up to date. Make" + echo "sure you configure MySQL on your services.conf file prior to launching" + echo "Anope with MySQL support. Your configuration values are:" + echo "" + echo "mysql" + echo "{" + echo " database = \"$SQLDB\"" + echo " server = \"$SQLHOST\"" + echo " username = \"$SQLUSER\"" + echo " password = \"$SQLPASS\"" + echo " port = \"$SQLPORT\"" + echo " updatedelay = \"60\"" + echo "}" + echo "" +else + echo "The following operations failed:" + echo "$FAILED" +fi + +exit |
