[Dbconfig-common-changes] [dbconfig-common] r439 - trunk/internal
Sean Finney
seanius at alioth.debian.org
Thu Apr 10 16:12:07 UTC 2008
Author: seanius
Date: 2008-04-10 16:12:06 +0000 (Thu, 10 Apr 2008)
New Revision: 439
Modified:
trunk/internal/mysql
Log:
various fixes found by new unit tests
Modified: trunk/internal/mysql
===================================================================
--- trunk/internal/mysql 2008-04-10 16:08:52 UTC (rev 438)
+++ trunk/internal/mysql 2008-04-10 16:12:06 UTC (rev 439)
@@ -23,17 +23,17 @@
# you can safely delete this file
[client]
-user = '$dbc_dbadmin'
-password = '$dbc_dbadmpass'
-host = '$dbc_dbserver'
-port = '$dbc_dbport'
+user = '${dbc_dbadmin:-}'
+password = '${dbc_dbadmpass:-}'
+host = '${dbc_dbserver:-}'
+port = '${dbc_dbport:-}'
socket = '/var/run/mysqld/mysqld.sock'
[mysqldump]
-user = '$dbc_dbadmin'
-password = '$dbc_dbadmpass'
-host = '$dbc_dbserver'
-port = '$dbc_dbport'
+user = '${dbc_dbadmin:-}'
+password = '${dbc_dbadmpass:-}'
+host = '${dbc_dbserver:-}'
+port = '${dbc_dbport:-}'
socket = '/var/run/mysqld/mysqld.sock'
EOF
@@ -71,7 +71,13 @@
if [ ! "$l_sqlfile" ]; then
dbc_error="no file supplied to execute"
dbc_log="no file supplied to execute"
+ rm -f "$l_errfile"
return 1
+ elif [ ! -f "$l_sqlfile" ]; then
+ dbc_error="file $l_sqlfile missing"
+ dbc_log="file $l_sqlfile missing"
+ rm -f "$l_errfile"
+ return 1
fi
l_dbname=
@@ -127,8 +133,8 @@
##
dbc_mysql_check_user(){
local l_dballow l_retval _dbc_nodb
- if [ ! "$dbc_dballow" ]; then
- if [ ! "$dbc_dbserver" ] || [ "$dbc_dbserver" = "localhost" ]; then
+ if [ ! "${dbc_dballow:-}" ]; then
+ if [ ! "${dbc_dbserver:-}" ] || [ "$dbc_dbserver" = "localhost" ]; then
l_dballow=localhost
else
l_dballow=`hostname`
@@ -173,11 +179,13 @@
dbc_logpart "verifying database $dbc_dbname exists:"
if ! _dbc_mysql_check_database "$dbc_dbname"; then
dbc_logline "failed"
+ return 1
else
dbc_logline "success"
fi
else
dbc_logline "failed"
+ return 1
fi
fi
}
@@ -201,11 +209,13 @@
dbc_logpart "verifying database $dbc_dbname was dropped:"
if _dbc_mysql_check_database "$dbc_dbname"; then
dbc_logline "failed"
+ return 1
else
dbc_logline "success"
fi
else
- dbc_logline "does not exist"
+ dbc_logline "failed"
+ return 1
fi
else
dbc_logline "database does not exist"
@@ -228,8 +238,8 @@
_dbc_sanity_check dbuser dbname dbadmin mysql || return 1
_dbc_mysql_check_connect || return 1
- if [ ! "$dbc_dballow" ]; then
- if [ ! "$dbc_dbserver" ] || [ "$dbc_dbserver" = "localhost" ]; then
+ if [ ! "${dbc_dballow:-}" ]; then
+ if [ ! "${dbc_dbserver:-}" ] || [ "$dbc_dbserver" = "localhost" ]; then
l_dballow=localhost
else
l_dballow=`hostname`
@@ -243,7 +253,7 @@
l_sqlfile=`mktemp -t dbconfig-common.sql.XXXXXX`
[ -f "$l_sqlfile" ] || return 1
- cat << EOF > $l_sqlfile
+ cat << EOF > "$l_sqlfile"
GRANT ALL PRIVILEGES ON \`$dbc_dbname\`.* TO \`$dbc_dbuser\`@'$l_dballow' IDENTIFIED BY '`dbc_mysql_escape_str $dbc_dbpass`';
FLUSH PRIVILEGES;
EOF
@@ -268,7 +278,7 @@
dbc_logline "failed"
fi
fi
- rm -f $l_sqlfile
+ rm -f "$l_sqlfile"
return $l_ret
}
@@ -282,13 +292,13 @@
# Description: drops a database user.
dbc_mysql_dropuser(){
- local l_sqlfile l_dballow
+ local l_sqlfile l_dballow l_ret _dbc_nodb
_dbc_sanity_check dbuser dbname dbadmin mysql || return 1
_dbc_mysql_check_connect || return 1
if [ ! "$dbc_dballow" ]; then
- if [ ! "$dbc_dbserver" ] || [ "$dbc_dbserver" = "localhost" ]; then
+ if [ ! "${dbc_dbserver:-}" ] || [ "$dbc_dbserver" = "localhost" ]; then
l_dballow=localhost
else
l_dballow=`hostname`
@@ -304,16 +314,21 @@
l_sqlfile=`mktemp -t dbconfig-common.sql.XXXXXX`
[ -f "$l_sqlfile" ] || return 1
- cat << EOF > $l_sqlfile
+ cat << EOF > "$l_sqlfile"
REVOKE ALL PRIVILEGES ON \`$dbc_dbname\`.* FROM '$dbc_dbuser'@'$l_dballow';
FLUSH PRIVILEGES;
EOF
- if _dbc_nodb="yes" dbc_mysql_exec_file "$l_sqlfile" 2>/dev/null; then
+ _dbc_nodb="yes"
+ if dbc_mysql_exec_file "$l_sqlfile" 2>/dev/null; then
dbc_logline "success"
+ l_ret=0
else
dbc_logline "failed"
+ l_ret=1
fi
- rm -f $l_sqlfile
+ # XXX no verification!
+ rm -f "$l_sqlfile"
+ return $l_ret
fi
}
@@ -327,8 +342,8 @@
dumpfile=$1
dumperr=0
mycnf=`_dbc_generate_mycnf`
- dbc_error=`mysqldump --defaults-file="$mycnf" $dbc_dbname 2>&1 >$dumpfile` || dumperr=1
- rm -f $mycnf
+ dbc_error=`mysqldump --defaults-file="$mycnf" $dbc_dbname 2>&1 >"$dumpfile"` || dumperr=1
+ rm -f "$mycnf"
return $dumperr
}
More information about the Dbconfig-common-changes
mailing list