eqemu_update.pl additions for EQEmu Installer to come [skip ci]

This commit is contained in:
Akkadius 2015-10-06 14:26:53 -05:00
parent 2680fc1a83
commit ffe1bede52

View File

@ -14,6 +14,7 @@ use POSIX qw(strftime);
use File::Path; use File::Path;
use File::Find; use File::Find;
use URI::Escape; use URI::Escape;
use Time::HiRes qw(usleep);
$time_stamp = strftime('%m-%d-%Y', gmtime()); $time_stamp = strftime('%m-%d-%Y', gmtime());
@ -49,9 +50,6 @@ no warnings;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
#::: Cleanup staged folder...
rmtree("updates_staged/");
my $confile = "eqemu_config.xml"; #default my $confile = "eqemu_config.xml"; #default
open(F, "<$confile"); open(F, "<$confile");
my $indb = 0; my $indb = 0;
@ -66,16 +64,6 @@ while(<F>) {
elsif(/<db>(.*)<\/db>/i) { $db = $1; } elsif(/<db>(.*)<\/db>/i) { $db = $1; }
} }
if($ARGV[0] eq "installer"){
print "Running EQEmu Server installer routines...\n";
map_files_fetch_bulk();
opcodes_fetch();
plugins_fetch();
quest_files_fetch();
lua_modules_fetch();
exit;
}
$console_output = $console_output =
"============================================================ "============================================================
EQEmu: Automatic Upgrade Check EQEmu: Automatic Upgrade Check
@ -119,6 +107,34 @@ if($path eq ""){
exit; exit;
} }
if($ARGV[0] eq "installer"){
print "Running EQEmu Server installer routines...\n";
mkdir('logs');
mkdir('updates_staged');
fetch_latest_windows_binaries();
map_files_fetch_bulk();
opcodes_fetch();
plugins_fetch();
quest_files_fetch();
lua_modules_fetch();
get_remote_file("https://raw.githubusercontent.com/Akkadius/EQEmuInstall/master/lua51.dll", "lua51.dll", 1);
#::: Database Routines
print "MariaDB :: Creating Database 'peq'\n";
print `"$path" --host $host --user $user --password="$pass" -N -B -e "DROP DATABASE peq;CREATE DATABASE peq"`;
if($OS eq "Windows"){ @db_version = split(': ', `world db_version`); }
if($OS eq "Linux"){ @db_version = split(': ', `./world db_version`); }
$bin_db_ver = trim($db_version[1]);
check_db_version_table();
$local_db_ver = trim(get_mysql_result("SELECT version FROM db_version LIMIT 1"));
fetch_peq_db_full();
print "\nFetching Latest Database Updates...\n";
main_db_management();
print "\nApplying Latest Database Updates...\n";
main_db_management();
exit;
}
#::: Create db_update working directory if not created #::: Create db_update working directory if not created
mkdir('db_update'); mkdir('db_update');
@ -128,15 +144,19 @@ if(trim(get_mysql_result("SHOW COLUMNS FROM db_version LIKE 'Revision'")) ne ""
print "Old db_version table present, dropping...\n\n"; print "Old db_version table present, dropping...\n\n";
} }
if(get_mysql_result("SHOW TABLES LIKE 'db_version'") eq "" && $db){ sub check_db_version_table{
print get_mysql_result(" if(get_mysql_result("SHOW TABLES LIKE 'db_version'") eq "" && $db){
CREATE TABLE db_version ( print get_mysql_result("
version int(11) DEFAULT '0' CREATE TABLE db_version (
) ENGINE=InnoDB DEFAULT CHARSET=latin1; version int(11) DEFAULT '0'
INSERT INTO db_version (version) VALUES ('1000');"); ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
print "Table 'db_version' does not exists.... Creating...\n\n"; INSERT INTO db_version (version) VALUES ('1000');");
print "Table 'db_version' does not exists.... Creating...\n\n";
}
} }
check_db_version_table();
if($OS eq "Windows"){ @db_version = split(': ', `world db_version`); } if($OS eq "Windows"){ @db_version = split(': ', `world db_version`); }
if($OS eq "Linux"){ @db_version = split(': ', `./world db_version`); } if($OS eq "Linux"){ @db_version = split(': ', `./world db_version`); }
@ -307,7 +327,10 @@ sub database_dump_compress {
print `perl db_dumper.pl database="$db" loc="backups" compress`; print `perl db_dumper.pl database="$db" loc="backups" compress`;
} }
sub script_exit{ } sub script_exit{
#::: Cleanup staged folder...
rmtree("updates_staged/");
}
#::: Returns Tab Delimited MySQL Result from Command Line #::: Returns Tab Delimited MySQL Result from Command Line
sub get_mysql_result{ sub get_mysql_result{
@ -357,31 +380,44 @@ sub get_remote_file{
if($OS eq "Windows"){ if($OS eq "Windows"){
#::: For non-text type requests... #::: For non-text type requests...
if($content_type == 1){ if($content_type == 1){
use LWP::Simple qw(getstore); $break = 0;
if(!getstore($URL, $Dest_File)){ while($break == 0) {
print "Error, no connection or failed request...\n\n"; use LWP::Simple qw(getstore);
} if(!getstore($URL, $Dest_File)){
else{ # print "Error, no connection or failed request...\n\n";
print " o URL: (" . $URL . ")\n"; }
print " o Saved: (" . $Dest_File . ") \n"; # sleep(1);
#::: Make sure the file exists before continuing...
if(-e $Dest_File) {
$break = 1;
print " [URL] :: " . $URL . "\n";
print " [Saved] :: " . $Dest_File . "\n";
} else { $break = 0; }
usleep(500);
} }
} }
else{ else{
require LWP::UserAgent; $break = 0;
my $ua = LWP::UserAgent->new; while($break == 0) {
$ua->timeout(10); require LWP::UserAgent;
$ua->env_proxy; my $ua = LWP::UserAgent->new;
my $response = $ua->get($URL); $ua->timeout(10);
$ua->env_proxy;
if ($response->is_success){ my $response = $ua->get($URL);
open (FILE, '> ' . $Dest_File . ''); if ($response->is_success){
print FILE $response->decoded_content; open (FILE, '> ' . $Dest_File . '');
close (FILE); print FILE $response->decoded_content;
print " o URL: (" . $URL . ")\n"; close (FILE);
print " o Saved: (" . $Dest_File . ") \n"; }
} else {
else { # print "Error, no connection or failed request...\n\n";
print "Error, no connection or failed request...\n\n"; }
if(-e $Dest_File) {
$break = 1;
print " [URL] :: " . $URL . "\n";
print " [Saved] :: " . $Dest_File . "\n";
} else { $break = 0; }
usleep(500);
} }
} }
} }
@ -473,6 +509,53 @@ sub copy_file{
copy $l_source_file, $l_dest_file; copy $l_source_file, $l_dest_file;
} }
sub fetch_latest_windows_binaries{
print "\n --- Fetching Latest Windows Binaries... --- \n";
get_remote_file("https://raw.githubusercontent.com/Akkadius/EQEmuInstall/master/master_windows_build.zip", "updates_staged/master_windows_build.zip", 1);
print "\n --- Fetched Latest Windows Binaries... --- \n";
print "\n --- Extracting... --- \n";
unzip('updates_staged/master_windows_build.zip', 'updates_staged/binaries/');
my @files;
my $start_dir = "updates_staged/binaries";
find(
sub { push @files, $File::Find::name unless -d; },
$start_dir
);
for my $file (@files) {
$dest_file = $file;
$dest_file =~s/updates_staged\/binaries\///g;
print "Installing :: " . $dest_file . "\n";
copy_file($file, $dest_file);
}
print "\n --- Done... --- \n";
rmtree('updates_staged');
}
sub fetch_peq_db_full{
print "Downloading latest PEQ Database... Please wait...\n";
get_remote_file("http://edit.peqtgc.com/weekly/peq_beta.zip", "updates_staged/peq_beta.zip", 1);
print "Downloaded latest PEQ Database... Extracting...\n";
unzip('updates_staged/peq_beta.zip', 'updates_staged/peq_db/');
my $start_dir = "updates_staged\\peq_db";
find(
sub { push @files, $File::Find::name unless -d; },
$start_dir
);
for my $file (@files) {
$dest_file = $file;
$dest_file =~s/updates_staged\\peq_db\///g;
if($file=~/peqbeta|player_tables/i){
print "MariaDB :: Installing :: " . $dest_file . "\n";
get_mysql_result_from_file($file);
}
if($file=~/eqtime/i){
print "Installing eqtime.cfg\n";
copy_file($file, "eqtime.cfg");
}
}
}
sub map_files_fetch_bulk{ sub map_files_fetch_bulk{
print "\n --- Fetching Latest Maps... (This could take a few minutes...) --- \n"; print "\n --- Fetching Latest Maps... (This could take a few minutes...) --- \n";
get_remote_file("http://github.com/Akkadius/EQEmuMaps/archive/master.zip", "maps/maps.zip", 1); get_remote_file("http://github.com/Akkadius/EQEmuMaps/archive/master.zip", "maps/maps.zip", 1);