Tip: Create new Script Installers for your CGI scripts

1 post / 0 new
#1 Tue, 07/12/2005 - 02:27
Joe
Joe's picture

Tip: Create new Script Installers for your CGI scripts

It's easy to add your own CGI scripts to the Virtualmin Install Scripts interface. Once you've created the installer script, it is easy to distribute it to other Virtualmin users...the beauty of this distribution mechanism is that it will work the same on all Virtualmin platforms.

To create a Virtualmin Install Scripts installer script (try saying "Install Scripts installer script" five times fast), simply copy one of the existing scripts located in the /usr/libexec/webmin/virtual-server/scripts directory and modify it to match your requirements. The TikiWiki installer is a pretty simple one so we'll use it. Open up tikiwiki.pl and you'll see a series of functions, labelled script_tikiwiki_*. Each function performs a few simple actions to interact with Virtualmin and provide the user with the feedback they expect.

Most of the routines are self-explanatory, for example, the script_tikiwiki_desc is a short description of the script, probably just the name of the script, like "TikiWiki".

Some may not be so obvious, but are really cool ways to insure your script works after being installed. the script_tikiwiki_depends function, for example, detects a few aspects of the Virtualmin domain in question to be sure TikiWiki will run with the available services. Here it is:

script_tikiwiki_depends(&domain, version)

sub script_tikiwiki_depends { local ($d, $ver) = @_; return "TikiWiki requires a website" if (!$d->{'web'}); return "TikiWiki cannot be installed onto virtual servers without a home directory" if (!$d->{'dir'}); &require_apache(); return "TikiWiki requires the Apache mod_php4 module" if (!$apache::httpd_modules{'mod_php4'}); return undef; }

In the above, $d is the domain, and checking for a configured website and home directory is simply a one-line if statement. Those two checks are pretty standard fare...to run scripts you pretty much have to have those two things. If your script is written in PHP, you'll want to hang onto the check for mod_php4, too.

If you need to ask the user for any information, like where to install the script, or which database to connect to, or something similar, you'll do it in the script_*_params function. Remember to use the standard Webmin uilib routines to keep your GUI consistent with the rest of Virtualmin.

Other functions grab the file from a website URL, and actually performs the installation. If possible, try to catch errors and respond appropriately (i.e. warn the user that something went wrong).

Once created, you can distribute just the scriptname.pl file and users will be able to install your script easily! If your software is Open Source, feel free to send over the installer script to me or Jamie, and we'll drop it into the next release (assuming it works correctly and fits into the look and feel of Virtualmin) and send you a T-shirt or something cool with the Virtualmin logo on it.