Best way to populate a db from an installer script

2 posts / 0 new
Last post
#1 Tue, 09/23/2008 - 17:40
emduck

Best way to populate a db from an installer script

I'm writing an Perl installer for my own custom software, and have looked at many examples. Most of them end by displaying a URL for the sysadmin to click on. Clicking on the URL takes the person to the rest of the installation, which includes populating the database, and any other unsundries.

I'd prefer to skip this step, as the only way I can make money at this business is through automating every tedious process I can. :-)

My first thought was to insert this into my script_XXX_install function:

my $install_script = $opts->{'dir'} . '/install.sql'; my $cmd = "/usr/bin/mysql --port=3306 --database=$dbname --host=$dbhost --user=$dbuser --password=$dbpass < $install_script"; my $error_code = system($cmd);

So inelegant. Hard-wired path to mysql, for instance. I'm thinking there must be a function built into the API to accomplish this. E.g., there's a create_script_database() function which is the first thing my script calls:

local $err = &create_script_database($d, $opts->{'db'});

My problem is, though I have the URL for the excellent documentation on writing script installers: http://www.virtualmin.com/documentation/id,script_installers/

However, I don't know of an API document describing the functions used by the scdript installers -- e.g., create_script_database() and all the other built-in functions.

A pointer to a document for the API would be appreciated.

TIA, Emily

Post edited by: emduck, at: 2008/09/23 18:03<br><br>Post edited by: emduck, at: 2008/09/23 18:06

Sun, 06/07/2009 - 07:29
Joe
Joe's picture

Hi Emily,

There is actually just such a function in Webmin, for running a file of SQL. You can call it with code like :

[code:1]&amp;require_mysql();
($exitstatus, $out) = &amp;mysql::execute_sql_file($dbname, $opts-&gt;{'dir'}.'/install.sql', $dbuser, $dbpass);
if ($exitstatus != 0) {
return (-1, &quot;Setup SQL failed&quot;&Acirc;&laquo;&Acirc;&raquo;);
}[/code:1]

Some of these inter-module API calls aren't well documented yet, but I am working on it..

--

Check out the forum guidelines!

Topic locked