SYSTEM INFORMATION | |
---|---|
OS type and version: | Ubuntu 20.04 |
Webmin version: | 1.973 |
Virtualmin version: | 6.16 |
I made a test script to install a software but it doesn’t work when I import the following happens:
I’ll post the code here because it’s likely I have done something wrong!
# script_fastgs_desc()
sub script_fastgs_desc
{
return "FastGM";
}
sub script_fastgs_uses
{
return ( "php" );
}
sub script_fastgs_longdesc
{
return "Servers Panel";
}
# script_fastgs_versions()
sub script_fastgs_versions
{
return ( "1" );
}
sub script_fastgs_gpl
{
return 1;
}
sub script_fastgs_category
{
return ("Commerce");
}
sub script_fastgs_php_vers
{
return ( 5 );
}
sub script_fastgs_php_modules
{
return ( "cli", "gd", "mysql", "pdo", "mbstring", "tokenizer", "bcmath", "xml", "fpm", "curl", "zip" );
}
#sub script_fastgs_php_optional_modules
#{
#return ( "" );
#}
sub script_fastgs_dbs
{
return ( "mysql" );
}
sub script_fastgs_release
{
return 5;
}
# script_fastgs_depends(&domain, version)
sub script_fastgs_depends
{
my ($d, $ver, $sinfo, $phpver) = @_;
my @rv;
# Check for PHP
my $wantver = &script_fastgs_php_fullver($d, $ver, $sinfo);
my $phpv = get_php_version($phpver || 5, $d);
if (!$phpv) {
push(@rv, "Could not work out exact PHP version");
}
elsif (&compare_versions($phpv, $wantver) < 0) {
push(@rv, "FastGS requires PHP version $wantver or later");
}
return @rv;
}
sub script_fastgs_php_fullver
{
my ($d, $ver, $sinfo) = @_;
return "1.0";
}
# script_fastgs_params(&domain, version, &upgrade-info)
# Returns HTML for table rows for options for installing FastGS
sub script_fastgs_params
{
my ($d, $ver, $upgrade) = @_;
my $rv;
my $hdir = public_html_dir($d, 1);
if ($upgrade) {
# Options are fixed when upgrading
my ($dbtype, $dbname) = split(/_/, $upgrade->{'opts'}->{'db'}, 2);
$rv .= ui_table_row("Database for FastGS tables", $dbname);
my $dir = $upgrade->{'opts'}->{'dir'};
$dir =~ s/^$d->{'home'}\///;
$rv .= ui_table_row("Install directory", $dir);
}
else {
# Show editable install options
my @dbs = domain_databases($d, [ "mysql" ]);
$rv .= ui_table_row("Database for FastGS tables",
ui_database_select("db", undef, \@dbs, $d, "fastgs"));
$rv .= ui_table_row("Install sub-directory under <tt>$hdir</tt>",
ui_opt_textbox("dir", &substitute_scriptname_template("fastgs", $d), 30, "At top level"));
if (&has_fastgs_cli()) {
# Can select the blog title
$rv .= ui_table_row("FastGS title",
ui_textbox("title", $d->{'owner'}, 40));
}
}
return $rv;
}
# script_fastgs_parse(&domain, version, &in, &upgrade-info)
# Returns either a hash ref of parsed options, or an error string
sub script_fastgs_parse
{
my ($d, $ver, $in, $upgrade) = @_;
if ($upgrade) {
# Options are always the same
return $upgrade->{'opts'};
}
else {
my $hdir = public_html_dir($d, 0);
$in{'dir_def'} || $in{'dir'} =~ /\S/ && $in{'dir'} !~ /\.\./ ||
return "Missing or invalid installation directory";
my $dir = $in{'dir_def'} ? $hdir : "$hdir/$in{'dir'}";
my ($newdb) = ($in->{'db'} =~ s/^\*//);
return { 'db' => $in->{'db'},
'newdb' => $newdb,
'dir' => $dir,
'dbtbpref' => $in->{'dbtbpref'},
'path' => $in{'dir_def'} ? "/" : "/$in{'dir'}",
'title' => $in{'title'} };
}
}
# script_fastgs_check(&domain, version, &opts, &upgrade-info)
# Returns an error message if a required option is missing or invalid
sub script_fastgs_check
{
local ($d, $ver, $opts, $upgrade) = @_;
$opts->{'dir'} =~ /^\// || return "Missing or invalid install directory";
$opts->{'db'} || return "Missing database";
if (-r "$opts->{'dir'}/server.php") {
return "FastGS appears to be already installed in the selected directory";
}
$opts->{'dbtbpref'} =~ s/^\s+|\s+$//g;
$opts->{'dbtbpref'} = 'egg_' if (!$opts->{'dbtbpref'});
$opts->{'dbtbpref'} =~ /^\w+$/ || return "Database table prefix either not set or contains invalid characters";
$opts->{'dbtbpref'} .= "_" if($opts->{'dbtbpref'} !~ /_$/);
my ($dbtype, $dbname) = split(/_/, $opts->{'db'}, 2);
my $clash = find_database_table($dbtype, $dbname, "$opts->{'dbtbpref'}.*");
$clash && return "FastGS appears to be already using \"$opts->{'dbtbpref'}\" database table prefix";
return undef;
}
# script_fastgs_files(&domain, version, &opts, &upgrade-info)
# Returns a list of files needed by FastGS, each of which is a hash ref
# containing a name, filename and URL
sub script_fastgs_files
{
my ($d, $ver, $opts, $upgrade) = @_;
if ($d && &has_fastgs_cli($opts) && !$opts->{'nocli'}) {
# Nothing to download
return ( );
}
#my @files = ( { 'name' => "source",
# 'file' => "wordpress-$ver.zip",
# 'url' => "http://wordpress.org/wordpress-$ver.zip",
# 'virtualmin' => 1 } );
#return @files;
my @files = ( { 'name' => "source",
'file' => "v1.5.1.zip",
'url' => "https://github.com/pterodactyl/panel/archive/refs/tags/v1.5.1.zip",
'virtualmin' => 1 } );
return @files;
}
sub script_fastgs_commands
{
return ("unzip");
}
# script_fastgs_install(&domain, version, &opts, &files, &upgrade-info)
# Actually installs FastGs, and returns either 1 and an informational
# message, or 0 and an error
sub script_wordpress_install
{
local ($d, $version, $opts, $files, $upgrade) = @_;
local ($out, $ex);
if ($opts->{'newdb'} && !$upgrade) {
local $err = &create_script_database($d, $opts->{'db'});
return (0, "Database creation failed : $err") if ($err);
}
local ($dbtype, $dbname) = split(/_/, $opts->{'db'}, 2);
local $dbuser = $dbtype eq "mysql" ? &mysql_user($d) : &postgres_user($d);
local $dbpass = $dbtype eq "mysql" ? &mysql_pass($d) : &postgres_pass($d, 1);
local $dbphptype = $dbtype eq "mysql" ? "mysql" : "psql";
local $dbhost = &get_database_host($dbtype);
local $dberr = &check_script_db_connection($dbtype, $dbname, $dbuser, $dbpass);
return (0, "Database connection failed : $dberr") if ($dberr);
# Create target dir
if (!-d $opts->{'dir'}) {
$out = &run_as_domain_user($d, "mkdir -p ".quotemeta($opts->{'dir'}));
-d $opts->{'dir'} ||
return (0, "Failed to create directory : <tt>$out</tt>.");
}
# Extract tar file to temp dir
local $temp = &transname();
mkdir($temp, 0755);
chown($d->{'uid'}, $d->{'gid'}, $temp);
$out = &run_as_domain_user($d, "cd ".quotemeta($temp).
" && unzip $files->{'source'}");
local $verdir = "fastgs";
-r "$temp/$verdir/server.php" ||
return (0, "Failed to extract source : <tt>$out</tt>.");
# Move html dir to target
$out = &run_as_domain_user($d, "cp -rp ".quotemeta($temp)."/$verdir/* ".
quotemeta($opts->{'dir'}));
local $cfileorig = "$opts->{'dir'}/.env.example";
local $cfile = "$opts->{'dir'}/.env";
-r $cfileorig || return (0, "Failed to copy source : <tt>$out</tt>.");
# Copy and update the config file
if (!-r $cfile) {
&run_as_domain_user($d, "cp ".quotemeta($cfileorig)." ".
quotemeta($cfile));
local $lref = &read_file_lines($cfile);
local $l;
foreach $l (@$lref) {
if ($l =~ /^DB_DATABASE=/) {
$l = "DB_DATABASE=$dbname";
}
if ($l =~ /^DB_USERNAME=/) {
$l = "DB_USERNAME=$dbuser";
}
if ($l =~ /^DB_HOST=/) {
$l = "DB_HOST=$dbhost";
}
if ($l =~ /^DB_PASSWORD=/) {
$l = "DB_PASSWORD=$dbpass";
}
&flush_file_lines($cfile);
}
if (!$upgrade) {
# Run the SQL setup script
if ($dbtype eq "mysql") {
local $sqlfile = "$opts->{'dir'}/tables-mysql.sql";
&require_mysql();
($ex, $out) = &mysql::execute_sql_file($dbname, $sqlfile, $dbuser, $dbpass);
$ex && return (0, "Failed to run database setup script : <tt>$out</tt>.");
}
local $url = &script_path_url($d, $opts).
($upgrade ? "wp-admin/upgrade.php" : "wp-admin/install.php");
local $userurl = &script_path_url($d, $opts);
local $rp = $opts->{'dir'};
$rp =~ s/^$d->{'home'}\///;
return (1, "FastGS installation complete. It can be accessed at <a href='$url'>$url</a>.", "Under $rp using $dbphptype database $dbname", $userurl);
}
}
# script_fastgs_uninstall(&domain, version, &opts)
# Un-installs a Wordpress installation, by deleting the directory and database.
# Returns 1 on success and a message, or 0 on failure and an error
sub script_fastgs_uninstall
{
my ($d, $version, $opts) = @_;
# Remove the contents of the target directory
my $derr = delete_script_install_directory($d, $opts);
return (0, $derr) if ($derr);
# Remove all wp_ tables from the database
cleanup_script_database($d, $opts->{'db'}, $opts->{'dbtbpref'});
# Take out the DB
if ($opts->{'newdb'}) {
delete_script_database($d, $opts->{'db'});
}
return (1, "FastGS directory and tables deleted.");
}
sub script_fastgs_latest
{
my ($ver) = @_;
return ( "http://fast-gs.com/download/",
"Download\\s+FastGS\\s+([0-9\\.]+)" );
}
sub script_fastgs_site
{
return 'http://fast-gs.com/';
}
1;