Skip to content

Commit

Permalink
initial trial commit for freenats build system
Browse files Browse the repository at this point in the history
  • Loading branch information
purplepixie committed Feb 6, 2016
0 parents commit d5bcf33
Show file tree
Hide file tree
Showing 269 changed files with 34,861 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
release/

45 changes: 45 additions & 0 deletions build-config.php
@@ -0,0 +1,45 @@
<?php
/* -------------------------------------------------------------
This file is part of FreeNATS
FreeNATS is (C) Copyright 2008-2016 PurplePixie Systems
FreeNATS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FreeNATS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FreeNATS. If not, see www.gnu.org/licenses
For more information see www.purplepixie.org/freenats
-------------------------------------------------------------- */

/*
Build Configuration Options
*/

$_FREENATS_SRC = "./src/";
$_FREENATS_BASE = $_FREENATS_SRC."server/base/";
$_FREENATS_NATS = $_FREENATS_BASE."nats.php";
$_FREENATS_RELEASE = "./release/";

// If FREENATS_DB_CONFIG is FALSE then the FreeNATS config.inc.php
// will be used (standard behaviour). Override here if needed.
$_FREENATS_DB_CONFIG = false;
$_FREENATS_DB_SERVER = "";
$_FREENATS_DB_DATABASE = "";
$_FREENATS_DB_USERNAME = "";
$_FREENATS_DB_PASSWORD = "";

// For override of official release URL (normally uploaded to Purplepixie.org)
$_FREENATS_UPLOAD_URL = "";

?>
6 changes: 6 additions & 0 deletions build-tools/dbdump.sh
@@ -0,0 +1,6 @@
#!/bin/bash
if [ "$5" == "drop" ]; then
/usr/bin/mysqldump -h $1 -u $3 -p$4 --add-drop-table -n -d $2
else
/usr/bin/mysqldump -h $1 -u $3 -p$4 --skip-add-drop-table -n -d $2
fi
98 changes: 98 additions & 0 deletions build-tools/dbupg.php
@@ -0,0 +1,98 @@
<?php
// dbupg.sh - Copyright 2008-2016 PurplePixie Systems, all rights reserved.
// http://www.purplepixie.org
// v4 06/02/2016

// n.b. replaced with myrug tools -- NOT USED IN BUILD; kept for reference only

if (($argc<2)||($argc>3))
{
echo "Usage: dbupg.sh database [filter]\n";
exit();
}

if ($argc==3)
$filter=" LIKE \"".mysql_escape_string($argv[2])."%\"";
else
$filter="";

$sql=mysql_connect("localhost","root","marvin")
or die("Couldn't connect to MySQL");
mysql_select_db($argv[1])
or die("Couldn't select database");

function c($t="")
{
echo "-- ".$t."\n";
}

c("dbupg.sh -- PurplePixie Systems");
c();

$q="SHOW TABLES".$filter;
echo "-- ".$q."\n";
$r=mysql_query($q);
while ($row=mysql_fetch_array($r))
{
$table=$row[0];
echo "-- Table: ".$table."\n";

//echo "DROP INDEX FROM ".$table."\n";

$tq="DESCRIBE ".$table;
c($tq);
$tr=mysql_query($tq);
while ($trow=mysql_fetch_array($tr))
{
// Field Type Null Key Default Extra

$f="ALTER TABLE `".$table."` CHANGE `".$trow['Field']."` `".$trow['Field']."` ".$trow['Type'];
if (($trow['Null']=="")||($trow['Null']=="NO")) $f.=" NOT NULL";
if ($trow['Extra']!="") $f.=" ".$trow['Extra'];
if ($trow['Default']!="") $f.=" DEFAULT '".$trow['Default']."'";
echo $f.";\n";

$f="ALTER TABLE `".$table."` ADD `".$trow['Field']."` ".$trow['Type'];
if (($trow['Null']=="")||($trow['Null']=="NO")) $f.=" NOT NULL";
if ($trow['Extra']!="") $f.=" ".$trow['Extra'];
if ($trow['Default']!="")
{
/*
$typarr=explode("(",$trow['Type']);
$type=$typarr[0];
$quot=true;
switch($type)
{
case "TINYINT": case "SMALLINT": case "MEDIUMINT": case "INT": case "INTEGER": case "BIGINT":
case "FLOAT": case "DOUBLE":
$quot=false;
break;
}
*/
$f.=" DEFAULT '".$trow['Default']."'";
}

echo $f.";\n";

if ($trow['Key']!="")
{
if ($trow['Key']=="PRI")
echo "ALTER TABLE `".$table."` ADD PRIMARY KEY( `".$trow['Field']."` );\n";
else if ($trow['Key']=="MUL")
{
// the one at a time way
//echo "ALTER TABLE `".$table."` DROP INDEX `".$trow['Field']."` ;\n";
//echo "ALTER TABLE `".$table."` ADD INDEX ( `".$trow['Field']."` );\n";
echo "CREATE INDEX `".$trow['Field']."` ON `".$table."` ( `".$trow['Field']."` );\n";
}
else
c("Unknown Key Type ".$trow['Key']);
//else if ($trow['Key']=="MUL")
// echo "ALTER TABLE `".$table."` ADD INDEX ( `".$trow['Field']."` );\n";
}
}
mysql_free_result($tr);
c();
}
mysql_close($sql);
?>
116 changes: 116 additions & 0 deletions build-tools/myrug.cli.php
@@ -0,0 +1,116 @@
<?php
// myrug.cli.php
// Copyright 2008 PurplePixie Systems, All Rights Reserved
// http://www.purplepixie.org/myrug

// CLI:
// myrug [options] database
// Options:
// -u= --user= --username=
// -p= --pass= --password=
// -t= --table=
// -h= --host=
// On/Offs:
// --optimize --nooptimize (off)
// --createtables --nocreatetables (off)
// --primarykey --noprimarykey (on)
// --createindex --nocreateindex (on)
// --createfield --nocreatefield (on)
// --alterfield --noalterfield (on)

require(realpath(dirname(__FILE__))."/myrug.inc.php");

$cfg=array(
'username' => "root",
'password' => "",
'database' => "",
'host' => "127.0.0.1",
'table' => "",
'optimize' => false,
//'createtables' => false, // NYI
'primarykey' => true,
'createindex' => true,
'createfield' => true,
'alterfield' => true );

function display_help()
{
echo "MySQL Rough Upgrader - outputs a SQL script which can be forced to\n";
echo "upgrade a schema (with many errors). For more information please see\n";
echo "http://www.purplepixie.org/myrug/\n\n";
echo "Usage: myrug [options] database\n\n";
echo "Where options are as follows:\n\n";
echo "--username=X | -u=X Set username (default root)\n";
echo "--password=X | -p=X Set password (default blank)\n";
echo "--host=X | -h=X Connect to host (default 127.0.0.1)\n";
echo "--table=X | -t=X Table name (can use % wildcard)\n";
echo "database Database to connect to\n\n";
echo "--primarykey | --noprimarykey\n";
echo " Turns on or off PRIMARY KEY queries (default on)\n\n";
echo "--createindex | --nocreateindex\n";
echo " Turns on or off CREATE INDEX queries (default on)\n\n";
echo "--createfield | --createfield\n";
echo " Turns on or off new field queries (default on)\n\n";
echo "--alterfield | --noalterfield\n";
echo " Turns on or off update field queries (default on)\n\n";
echo "--optimize | --nooptimize\n";
echo " Turns on or off OPTIMIZE TABLE queries (default off)\n\n";
exit();
}

if ($argc<2) display_help();
if ($argv[1]=="help") display_help();

$cfg['database']=$argv[$argc-1];

for ($i=1; $i<($argc-1); $i++)
{
$opt=$argv[$i];
if (strpos($opt,"=")!=false)
{
$cmd=substr($opt,0,strpos($opt,"="));
$val=substr($opt,strpos($opt,"=")+1,128);
}
else $cmd=$opt;

switch ($cmd)
{
case "-u": case "--username": case "--user":
$cfg['username']=$val;
break;

case "-p": case "--password": case "--pass":
$cfg['password']=$val;
break;

case "-t": case "--table":
$cfg['table']=$val;
break;

case "-h": case "--host":
$cfg['host']=$val;
break;

case "--optimize": case "--createtables": case "--primarykey": case "--createindex":
case "--createfield": case "--alterfield":
$name=substr($cmd,2,128);
$cfg[$name]=true;
break;

case "--nooptimize": case "--nocreatetables": case "--noprimarykey": case "--nocreateindex":
case "--nocreatefield": case "--noalterfield":
$name=substr($cmd,4,128);
$cfg[$name]=false;
break;


default:
echo "Error parsing: ".$opt."\n";
display_help();
}

}
myrug($cfg);
//print_r($cfg);

?>
99 changes: 99 additions & 0 deletions build-tools/myrug.inc.php
@@ -0,0 +1,99 @@
<?php
// myrug.inc.php - Copyright 2008 PurplePixie Systems, all rights reserved.
// http://www.purplepixie.org
// v3 26/05/2009
// MySQL Rough Upgrader
function myrug($cfg)
{
if ($cfg['table']!="")
$filter=" LIKE \"".mysql_escape_string($cfg['table'])."%\"";
else
$filter="";



$sql=mysql_connect($cfg['host'],$cfg['username'],$cfg['password'])
or die("MySQL Error: ".mysql_error()."\n");
mysql_select_db($cfg['database'])
or die("MySQL Error: ".mysql_error()."\n");

function c($t="")
{
echo "-- ".$t."\n";
}

c("myrug -- PurplePixie Systems");
c("http://www.purplepixie.org/myrug");
c();

$q="SHOW TABLES".$filter;
echo "-- ".$q."\n";
$r=mysql_query($q);
while ($row=mysql_fetch_array($r))
{
$table=$row[0];
echo "-- Table: ".$table."\n";

$tq="DESCRIBE ".$table;
c($tq);
$tr=mysql_query($tq);
while ($trow=mysql_fetch_array($tr))
{
// Field Type Null Key Default Extra

$f="ALTER TABLE `".$table."` CHANGE `".$trow['Field']."` `".$trow['Field']."` ".$trow['Type'];
if (($trow['Null']=="")||(strtoupper($trow['Null'])=="NO")) $f.=" NOT NULL";
if ($trow['Extra']!="") $f.=" ".$trow['Extra'];
if ($trow['Default']!="") $f.=" DEFAULT '".$trow['Default']."'";
if ($cfg['alterfield']) echo $f.";\n";

$f="ALTER TABLE `".$table."` ADD `".$trow['Field']."` ".$trow['Type'];
if (($trow['Null']=="")||(strtoupper($trow['Null'])=="NO")) $f.=" NOT NULL";
if ($trow['Extra']!="") $f.=" ".$trow['Extra'];
if ($trow['Default']!="")
{
/*
$typarr=explode("(",$trow['Type']);
$type=$typarr[0];
$quot=true;
switch($type)
{
case "TINYINT": case "SMALLINT": case "MEDIUMINT": case "INT": case "INTEGER": case "BIGINT":
case "FLOAT": case "DOUBLE":
$quot=false;
break;
}
*/
$f.=" DEFAULT '".$trow['Default']."'";
}

if ($cfg['createfield']) echo $f.";\n";

if ($trow['Key']!="")
{
if ($trow['Key']=="PRI")
{
if ($cfg['primarykey'])
echo "ALTER TABLE `".$table."` ADD PRIMARY KEY( `".$trow['Field']."` );\n";
}
else if ($trow['Key']=="MUL")
{
// the one at a time way
//echo "ALTER TABLE `".$table."` DROP INDEX `".$trow['Field']."` ;\n";
//echo "ALTER TABLE `".$table."` ADD INDEX ( `".$trow['Field']."` );\n";
if ($cfg['createindex'])
echo "CREATE INDEX `".$trow['Field']."` ON `".$table."` ( `".$trow['Field']."` );\n";
}
else
c("Unknown Key Type ".$trow['Key']);
//else if ($trow['Key']=="MUL")
// echo "ALTER TABLE `".$table."` ADD INDEX ( `".$trow['Field']."` );\n";
}
}
mysql_free_result($tr);
if ($cfg['optimize']) echo "OPTIMIZE TABLE ".$table.";\n";
c();
}
mysql_close($sql);
}
?>
4 changes: 4 additions & 0 deletions build-tools/myrug.sh
@@ -0,0 +1,4 @@
#!/usr/bin/php -q
<?php
require("myrug.cli.php");
?>

0 comments on commit d5bcf33

Please sign in to comment.