PCCS MySQLDatabase Admin Tool version 1.3.4


/installscript/ -> mysqldb_shinstallscript.php

1  <?php
2  /////////////////////////////////////////////////////////////////////////////////////
3  // coder: cthorn
4  // mysqldb_shinstallscript.php
5  //
6  /************************************************************************
7  PCCS MySQLDatabase Admin Tool
8  Copyright (C) 1999 Chauncey Thorn
9 
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
23  **************************************************************************/
24  // updated 10-19-2000
25  // -- added changelog to this file
26  // -- added this file to the code base
27  // Function: Create sh install script for php app and dump database
28  // schema without data put installscript/ directory
29    
30  // updated 10-23-2000
31  // -- moving to a single file for global include files
32    
33     require('../mysqldb_app_includes.php');
34     
35     common_header($_title);
36 
37 
38     pageTop("PCCS MySQLAdmin Tool version ". $appversion,"600");
39 
40 
41  $link_array = array(
42  "$str_mainMenu" => "../",
43  "$str_installscriptlink" => "mysqldb_installscript.php",
44  "LOGOUT" => "logout.php"
45  );
46 
47   print "<BR>";
48   print "<CENTER>";
49   navBar($link_array);
50   print "</CENTER>";
51   print "<BR>";
52 
53 
54  //
55  /////////////////////////////////////////////////////////////////////////////////////
56  //
57 
58  /*
59  $dbname = "class";
60  $filename = "myinstall-" .$dbname.".sh";
61  $application_name = "PCCS MySQLDatabase Admin Tool";
62  $install_filename = "INSTALL_linux";
63  */
64 
65  if($action == "start"):
66  print "
67  <H3 align=center>PHP Application Install Script Creator</H3>
68  <center>
69 
70  If you are a PHP developer. Using this script you can create an PHP application Install Script<P>\n
71 
72  ";
73 
74  print "
75 
76  <FORM ACTION=mysqldb_shinstallscript.php?action=createshinstallscript METHOD=POST>
77  <p><BR>
78  <table>
79  <tr>
80  <td><font face=\"Verdana\" size=\"2\">Application Name:</font></td>
81  <td><INPUT TYPE=\"text\" NAME=\"application_name\"></td>
82  </tr>
83  <tr>
84  <td><font face=\"Verdana\" size=\"2\">Your Email Address:</font> </td>
85  <td><INPUT TYPE=\"text\" NAME=\"installemail\"></td>
86  </tr>
87  <tr>
88  <td><font face=\"Verdana\" size=\"2\">Install File Name (INSTALL):</font></td>
89  <td><INPUT TYPE=\"text\" NAME=\"install_filename\"></td>
90  </tr>
91 
92  <tr>
93  <td><font face=\"Verdana\" size=\"2\">Application Database Name:</font></td>
94  <td>
95  <SELECT NAME=dbname SINGLE>";
96 
97                  $qry = "SHOW DATABASES";
98                  $res = mysqlquery("mysql",$qry) or die("Error running query");
99                   for ($i = 0; $i < mysql_numrows($res); $i++):
100                   $db_output = mysql_result($res,$i,"Database");
101 
102                   print "<OPTION VALUE=\"$db_output\">$db_output</OPTION>";
103                   endfor;
104 
105  print "
106  </SELECT>
107  </td>
108  </tr>
109 
110  <tr>
111  <td colspan=2><INPUT TYPE=submit VALUE=\"CREATE SCRIPT\"></td>
112  </tr>
113  </table>
114  </FORM>
115 
116  ";
117   print "<P><A HREF=../>BACK to Main</A>";
118   print " **** <A HREF=../mysqldb_admin.php>BACK to Databases</A>";
119   print "</center>";
120 
121 
122 
123  endif;
124 
125 
126 
127  if($action == "createshinstallscript"):
128          global $os_type;
129 
130           function createscriptdump($dbname) {
131           global $mysqldbuser, $mysqldbpasswd, $dumpfilename;
132           $_time = date("H:i:s");
133                  $_date = date("Y-m-d");
134                  $_admtool = "/usr/local/bin/mysqldump";
135                  // Support for Windows
136                  // Windows code hasn't been tested...
137                  if (eregi("Win",$os_type)) {
138                  $dumpdir = "." . "\\";
139                  } else {
140                  $dumpdir = "." . "/";
141                  }
142                  $par = "--opt -d -u$mysqldbuser -p$mysqldbpasswd $dbname";
143                  $command = "$_admtool $par";
144                  echo "Database dump for $dbname";
145                  echo "<BR>";
146                  echo "$_date :: $_time";
147                  echo "<P>";
148                  exec ($command, $dd, $result);
149                  $indexLimit = count($dd);
150                  // $csvfile="db_" . $dbname . date("Ymd") . ".sql";
151 
152                  $myfile = fopen($dumpdir . $dumpfilename,"w");
153                  for($index=0; $index < $indexLimit; $index++) {
154                  $_dumpdata = (" $dd[$index]\n ");
155                  
156                  // echo (" $_dumpdata<BR>\n ");
157                  fputs($myfile,$_dumpdata);
158 
159                  }
160                  fclose($myfile);
161                  echo "<a href=./$dumpfilename>DUMP</a> File Created schema only \"NO DATA\"<P>";
162          }
163          
164 
165  $dumpfilename="db_" . $dbname . "_" .date("m-d-Y").".sql";
166 
167  $filename = "myinstall-" .$dbname.".sh";
168 
169 
170  $script = fopen("$filename","w");
171  fputs($script,"#!/bin/sh\n");
172  fputs($script,"# Database setup utility v.03\n");
173  fputs($script,"\n");
174  fputs($script,"# Created by: Jason Hines - http://phpweblog.org\n");
175  fputs($script,"# Modified by Chauncey Thorn - http://web.wt.net/~cthorn\n");
176  fputs($script,"# -- Creating on the fly from selection\n");
177  fputs($script,"# -- removed reference to phpweblog\n");
178  fputs($script,"# Genereated by PCCS MySQLDatabase Admin Tool");
179  fputs($script,"# for $installemail'n");
180  fputs($script,"#\n");
181  fputs($script,"\n\n");
182  fputs($script,"mysqladmin=\"`which mysqladmin 2> /dev/null`\"\n");
183  fputs($script,"mysql=\"`which mysql 2>/dev/null`\"\n");
184  fputs($script, "\n\n");
185  fputs($script,"# check for mysql binaries\n");
186  fputs($script,"if [ ! -x \"$mysqladmin\" ]; then\n");
187  fputs($script," echo \"ERROR: mysqladmin not found in path...\"\n");
188  fputs($script," exit\n");
189  fputs($script,"fi\n\n");
190  fputs($script,"if [ ! -x \"$mysql\" ]; then\n");
191  fputs($script," echo \"ERROR: mysql not found in path...\"\n");
192  fputs($script," exit\n");
193  fputs($script,"fi\n");
194  fputs($script,"\n");
195  fputs($script,"\n");
196  fputs($script,"\n");
197  fputs($script,"# display intro\n");
198  fputs($script,"echo \"Welcome to $application_name!\"\n");
199  fputs($script,"echo \"---------------------\"\n");
200  fputs($script,"echo \"This script will attempt to create the required database\"\n");
201  fputs($script,"echo \"for use with $application_name, and import the default values.\"\n");
202  fputs($script,"echo \"If all goes well, your new site will be ready in no time.\"\n");
203  fputs($script,"echo \"I am assuming that you already have MySQL installed and\"\n");
204  fputs($script,"echo \"running, and Apache/PHP installed with MySQL support.\"\n");
205  fputs($script,"echo \"the included $install_filename for more information.\"\n");
206  fputs($script,"echo \"\"\n");
207  fputs($script,"\n");
208  fputs($script,"\n");
209  fputs($script,"echo -n \"Name of database to create ($dbname): \"\n");
210  fputs($script,"read database\n");
211  fputs($script,"echo -n \"Database username (root): \"\n");
212  fputs($script,"read username\n");
213  fputs($script,"echo -n \"Database password (none): \"\n");
214  fputs($script,"read password\n");
215  fputs($script,"echo -n \"Database host (localhost): \"\n");
216  fputs($script,"read host\n");
217  fputs($script,"echo -n \"Database port (3306): \"");
218  fputs($script,"read port\n");
219 
220  fputs($script,"# set defaults\n");
221  fputs($script,"if [ \"\$database\" = \"\" ]; then\n");
222  fputs($script," database=\"$dbname\"\n");
223  fputs($script,"fi\n\n");
224  fputs($script,"if [ \"\$username\" = \"\" ]; then\n");
225  fputs($script," username=\"root\"\n");
226  fputs($script,"fi\n\n");
227  fputs($script,"if [ \"\$password\" = \"\" ]; then\n");
228  fputs($script,"\t password=\"\"\n");
229  fputs($script,"fi\n\n");
230  fputs($script,"if [\"\$host\" = \"\" ]; then\n");
231  fputs($script,"\t host=\"localhost\"\n");
232  fputs($script,"fi\n\n");
233  fputs($script,"if [ \"\$port\" = \"\" ]; then\n");
234  fputs($script,"\t port=\"3306\"\n");
235  fputs($script,"fi\n\n");
236 
237  fputs($script,"# show values\n");
238  fputs($script,"echo \"\"\n");
239  fputs($script,"echo \"$application_name database settings\"\n");
240  fputs($script,"echo \"---------------------------\"\n");
241  fputs($script,"echo \"Database : \$database\"\n");
242  fputs($script,"echo \"Username : \$username\"\n");
243  fputs($script,"echo \"Password : \$password\"\n");
244  fputs($script,"echo \"Host : \$host\"\n");
245  fputs($script,"echo \"Port : \$port\"\n");
246  fputs($script,"echo \"\"\n");
247  fputs($script,"#echo \"Warning: Proceeding will destroy this database if it exists.\"\n");
248  fputs($script,"echo -n \"Continue with these values? (yN):\"\n");
249  fputs($script,"read yesorno\n");
250  fputs($script,"if [ \"\$yesorno\" != \"y\" -a \"\$yesorno\" != \"Y\" ]; then\n");
251  fputs($script," echo \"Aborting installation.\"\n");
252  fputs($script," exit\n");
253  fputs($script,"fi\n\n");
254  fputs($script,"\n");
255  fputs($script,"# proceed with installation\n");
256  fputs($script,"\n\n");
257  fputs($script,"if [ \"\$username\" != \"root\" ]; then\n");
258  fputs($script,"\t \$mysqladmin -u \$username -p create \$database\n");
259  fputs($script,"\t RET=\$?\n");
260  fputs($script,"\t if [ \$RET -ne 0 ]; then\n");
261  fputs($script,"\t echo \"Could not create database \"$database\"!\"\n");
262  fputs($script,"\t exit\n");
263  fputs($script,"\t fi\n\n");
264  fputs($script," \$mysql -u \$username -p \$database < $dumpfilename\n");
265  fputs($script," RET=\$?\n");
266  fputs($script," if [ \$RET -ne 0 ]; then\n");
267  fputs($script,"\t echo \"Could not import tables!\"\n");
268  fputs($script,"\t exit\n");
269  fputs($script," fi\n");
270  fputs($script,"\n");
271  fputs($script,"echo \"\"\n");
272  fputs($script,"echo \"Installation complete!\"\n");
273  fputs($script,"echo \"\"\n");
274  fclose($script);
275 
276  createscriptdump($dbname);
277 
278 
279  echo "Installation Script Written to installscript/<br>\n";
280  echo "Click with your right mouse button to download file: \n";
281  echo "<br><a href=$filename>$filename</a>\n";
282  echo "<P>\nYou will need to move these files to somewhere under your <br>\n";
283  echo "Application root directory...";
284  echo "<P>\n";
285  echo "<a href=$app_url>Back to Main</a>\n";
286 
287  endif;
288 
289 
290 
291  pageBottom();
292  ?>


Generated: Sat Jan 27 15:40:36 2001 Generated by PHPXref 0.1.2
PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002