Index: locker/sql/bin/create-database
===================================================================
--- locker/sql/bin/create-database	(revision 131)
+++ locker/sql/bin/create-database	(revision 131)
@@ -0,0 +1,11 @@
+#!/usr/bin/php
+<?php
+
+list($h,$u,$p) = explode("\t",`/mit/scripts/sql/bin/get-password`);
+$d = $argv[1];
+$create_r = explode(',',file_get_contents("http://sql.mit.edu/~sql/main/do/batch/create_db?d=$d&u=$u&p=$p"));
+$return_r = array_shift($create_r);
+$created = implode(',',$create_r);
+if ($return_r == '0') echo $created;
+
+?>
Index: locker/sql/bin/get-next-database
===================================================================
--- locker/sql/bin/get-next-database	(revision 131)
+++ locker/sql/bin/get-next-database	(revision 131)
@@ -0,0 +1,16 @@
+#!/usr/bin/php
+<?php
+
+list($h,$u,$p) = explode("\t",`/mit/scripts/sql/bin/get-password`);
+$newdb = str_replace($u.'+','',$argv[1]);
+$testdb = str_replace('.','',$u).'+'.$newdb;
+$dbs = explode("\n",file_get_contents("http://sql.mit.edu/~sql/tools/list_dbs.php?h=$h&u=$u&p=$p"));
+if (in_array($testdb,$dbs)) {
+	$i = 1;
+	while(in_array($testdb.$i,$dbs)) {
+		$i++;
+	}
+	echo $newdb.$i;
+} else echo $newdb;
+
+?>
Index: locker/sql/bin/get-password
===================================================================
--- locker/sql/bin/get-password	(revision 131)
+++ locker/sql/bin/get-password	(revision 131)
@@ -0,0 +1,46 @@
+#!/usr/bin/php
+<?php
+
+$host = 'sql.mit.edu';
+$env_user = getenv('USER');
+$home = '/mit/'.$env_user;
+
+$cnfPath = $home.'/.sql/my.cnf';
+
+function getMyCnfInfo($path) {
+if (file_exists($path)) {
+	global $env_user;
+	$cnfFile = file_get_contents($path);
+	preg_match('/\[mysql\][^\[]*host=([^\n]*)/',$cnfFile,$match);
+	$host = $match[1];
+	preg_match('/\[mysql\][^\[]*user=([^\n]*)/',$cnfFile,$match);
+	$user = $match[1];
+	preg_match('/\[mysql\][^\[]*password=([^\n]*)/',$cnfFile,$match);
+	$password = $match[1];
+	if (empty($host)) $host = 'sql.mit.edu';
+	if (empty($user)) $user = $env_user;
+	if (empty($password)) $password = 'password';
+	return array($host,$user,$password);
+}
+}
+
+$cnfinfo = getMyCnfInfo($cnfPath);
+if (is_array($cnfinfo)) {
+	list($h,$u,$p) = $cnfinfo;
+	echo "$h\t$u\t$p";
+	exit;
+}
+
+$sql_status = file_get_contents('http://sql.mit.edu/~sql/main/do/batch/status?u='.$env_user);
+switch($sql_status) {
+	case 1:
+		$myPassword = `/usr/bin/sql-signup`;
+        file_put_contents($cnfPath, "[mysql]\nhost=$host\nuser=$env_user\npassword=$myPassword");
+        $cnfinfo = getMyCnfInfo($cnfPath);
+        if (is_array($cnfinfo)) {
+            list($h,$u,$p) = $cnfinfo;
+    	    echo "$h\t$u\t$p";
+        }
+		break;
+	case 0:
+}
Index: locker/sql/bin/get-status
===================================================================
--- locker/sql/bin/get-status	(revision 131)
+++ locker/sql/bin/get-status	(revision 131)
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+status=`wget http://sql.mit.edu/~sql/main/do/batch/status?u=$USER -q -O-`
+
+echo $status
+exit $status
Index: locker/sql/bin/save-password
===================================================================
--- locker/sql/bin/save-password	(revision 131)
+++ locker/sql/bin/save-password	(revision 131)
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+mkdir $lroot/.sql 2>/dev/null
+fs sa $lroot/.sql system:anyuser none
+fs sa $lroot/.sql daemon.scripts write
+rm -f $lroot/.sql/my.cnf $lroot/.my.cnf
+
+echo "[mysql]
+host=sql.mit.edu
+user=$sqluser
+password=$sqlpass" > $lroot/.sql/my.cnf
+
+ln -nfs $lroot/.sql/my.cnf $lroot/.my.cnf 2>/dev/null
Index: locker/sql/bin/test-password
===================================================================
--- locker/sql/bin/test-password	(revision 131)
+++ locker/sql/bin/test-password	(revision 131)
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+mysql -e "select 1" 2>&1 | grep -i error
