summaryrefslogtreecommitdiff
path: root/www/geeklog/files/createdb.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/geeklog/files/createdb.php')
-rw-r--r--www/geeklog/files/createdb.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/www/geeklog/files/createdb.php b/www/geeklog/files/createdb.php
new file mode 100644
index 00000000000..151c7c52d68
--- /dev/null
+++ b/www/geeklog/files/createdb.php
@@ -0,0 +1,61 @@
+#!@PREFIX@/bin/php
+<?php
+# $NetBSD: createdb.php,v 1.1.1.1 2006/06/15 13:26:44 taca Exp $
+#
+# After editing @GEEKLOG_DIR@/config.php,
+# execute this script to create new database.
+#
+
+require_once( '@GEEKLOG_DIR@/config.php' );
+
+define("MySQL_Admin", "@PREFIX@/bin/mysqladmin");
+define("MySQL", "@PREFIX@/bin/mysql");
+
+define("MySQL_Root", "root");
+
+if ($_DB_dbms != "mysql") {
+ print("Unknown DBMS: ". $_DB_dbms . "\n");
+ exit(1);
+}
+
+# Create database.
+print "Creating databse for geeklog, please enter DBMS's admin if promped.\n";
+
+$cmd = MySQL_Admin . " --host=" . $_DB_host .
+ " --user=" . MySQL_Root . " --password create " . $_DB_name;
+
+print($cmd . "\n");
+
+passthru($cmd, $result);
+
+if ($result != 0) {
+ print("Error on creating database, do you want to continue?: ");
+ $ans = fgets(STDIN, 10);
+ trim($ans);
+ if (!eregi("^y", $ans)) {
+ print("Abort now\n");
+ exit(1);
+ }
+}
+
+# Create user.
+print "\nCreating database user for geeklog, please enter DBMS's admin if promped.\n";
+
+$cmd = MySQL . " --host=" . $_DB_host ." --user=" . MySQL_Root . " --password";
+print($cmd . "\n");
+$handle = popen($cmd, "w");
+if ($handle == FALSE) {
+ print("Error on connecting database.\n");
+ exit(1);
+}
+
+$sql = "GRANT " .
+ "SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, " .
+ "ALTER, CREATE TEMPORARY TABLES, LOCK TABLES" .
+ " ON " . $_DB_name . ".* TO '" . $_DB_user . "'@'" . $_DB_host .
+ "' IDENTIFIED BY '" . $_DB_pass . "';\n";
+# print $sql;
+fwrite($handle, $sql);
+pclose($handle);
+
+?>