Compare commits

...

5 Commits

Author SHA1 Message Date
Marisa Giancarla 788e0db55d Added server status functions 2022-07-21 11:32:10 +08:00
Marisa Giancarla df600dd9c4 Pull in changes from mcmc 2022-07-21 10:28:53 +08:00
fstltna f6d4b7556c Migrated options 16 & 17 from MCMC 2022-06-02 00:09:06 -07:00
marisag 03d7c5e990 Update version 2022-05-10 01:13:33 -07:00
fstltna dd005dd2b1 Added the install mods option 2022-05-09 23:27:49 -07:00
4 changed files with 388 additions and 10 deletions

View File

@ -1 +1,2 @@
1.14.0 - Added mods from mcmc
1.4.0 - Now stores location of the world.mt file in the ~/.mmcrc settings file.

View File

@ -1,4 +1,4 @@
# Minetest Management Console (1.10.1)
# Minetest Management Console (1.12.0)
Allows you to manage your Minetest server with a text based GUI - Official support sites: [Official Github Repo](https://github.com/fstltna/MinetestManagementConsole) - [Official Forum](https://minecity.online/index.php/forum/management-console)
---

Binary file not shown.

395
mmc
View File

@ -28,13 +28,26 @@ my $DEBUG_MODE = "off";
my $NewsFile = "/home/mtowner/minetest/worlds/world/news.txt";
my $BinDir = "/home/mtowner/bin";
my $ModDir = "/home/mtowner/minetest/mods";
my $KillAllString = "/home/mtowner/minetest/bin/minetestserver";
my $ServerProcess = "minetestserver";
my $ServerStartString = "/home/mtowner/minetest/bin/startminetest";
my $DfCommand = "df -h /dev/sda";
my $DuCommand = "du -h /home/mtowner/|tail -1";
my $FilesToRemove = "$MINETESTDIR/debug.txt $MINETESTDIR/MinetestScreen.log";
my $CrontabCommand = "crontab -e";
my $BuildCommand = "make";
my $WhoCommand = "/usr/bin/w";
my $LastCommand = "/usr/bin/last";
my $TopCommand = "/usr/bin/top";
###################################################
# No changes below here
###################################################
my $MySettings = "$ENV{'HOME'}/.mmcrc";
my $MMC_ver = "1.11.0";
my $MMC_ver = "1.14.0";
my $Record = "false"; # Are results saved?
my $TempDir = "/tmp";
my $RobotName = "";
@ -194,7 +207,7 @@ else
sub CheckServerStatus
{
my $running=`ps ax|grep minetestserver|grep -v grep`;
my $running=`ps ax|grep $ServerProcess|grep -v grep`;
if ($running ne "")
{
$ServerStatus = "Running";
@ -303,7 +316,7 @@ sub DoRestore
system("touch $MINETESTDIR/nostart");
# Kill the server process
print "Killing Minetest process, please wait...\n";
system("killall /home/mtowner/minetest/bin/startminetest");
system("killall $ServerStartString");
sleep(5);
# Create new folder
print "Creating new folder, please wait...";
@ -341,19 +354,221 @@ sub BackupTools
# Run a backup
PrintDebugCommand("$BackupCommand");
system("$BackupCommand");
print "Press Enter To Continue";
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "2")
{
# Do a restore
DoRestore();
print "Press Enter To Continue";
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
}
}
sub RebuildServer
{
chdir($MINETESTDIR);
system("clear");
system($BuildCommand);
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
sub UpdateServer
{
chdir($MINETESTDIR);
system("clear");
system($UpdateCommand);
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
sub UpdateMods
{
chdir($ModDir);
system("clear");
print "Updating your mods\n";
print "==================\n";
my $ModPrompt = "";
my $entered = "";
# system($UpdateCommand);
opendir(DIR, $ModDir) or die "Could not open $ModDir\n";
# Loop for each directory
while (my $filename = readdir(DIR))
{
if (($filename eq ".") || ($filename eq ".."))
{
# Skip over "." and ".."
next;
}
#print "$filename\n" if -d $filename;
if (-d $filename)
{
print "Current mod: $filename:\n";
print "Update this mod (yes/no/quit):";
$ModPrompt = <STDIN>;
chop($ModPrompt);
if (($ModPrompt eq "quit") || ($ModPrompt eq "q"))
{
last;
}
if (($ModPrompt eq "no") || ($ModPrompt eq "n"))
{
next;
}
# chdir("$ModDir/$filename");
system("git pull");
# print "--- Press Enter To Continue ---";
# my $entered = <STDIN>;
}
}
closedir(DIR);
print "--- Press Enter To Continue ---";
$entered = <STDIN>;
}
sub UpdateGame
{
chdir("$MINETESTDIR/game/minetest_game");
system("clear");
system($UpdateCommand);
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
sub ServerToolsMenu
{
my $WantRespawn="ON";
CheckServerStatus();
if (-f "$MINETESTDIR/nostart")
{
$WantRespawn="OFF";
}
$menuselection = $d->menu( title => "Server Tools Menu", text => "Server is $ServerStatus and respawn is $WantRespawn - Select one:",
list => [ '1', 'Run Backup First',
'2', 'Get Updates',
'3', 'Rebuild Server',
'4', 'Update Game',
'5', 'Update Mods',
'q', 'Main Menu' ] );
}
sub ServerTools
{
while (-1)
{
ServerToolsMenu();
if (($menuselection eq "CANCEL") || ($menuselection eq "ESC") || ($menuselection eq "") || ($menuselection eq "q") || ($menuselection eq "Q"))
{
return;
}
elsif ($menuselection eq "1")
{
# Run a backup
system("clear");
PrintDebugCommand("$BackupCommand");
system("$BackupCommand");
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "2")
{
# Pull Updates
PrintDebugCommand("$UpdateCommand");
UpdateServer();
}
elsif ($menuselection eq "3")
{
# Rebuild Server
PrintDebugCommand("$BuildCommand");
RebuildServer();
}
elsif ($menuselection eq "4")
{
# Rebuild Server
PrintDebugCommand("Updating Game");
UpdateGame();
}
elsif ($menuselection eq "5")
{
# Rebuild Server
PrintDebugCommand("Updating Mods");
UpdateMods();
}
}
}
sub ServerStatusMenu
{
my $WantRespawn="ON";
CheckServerStatus();
if (-f "$MINETESTDIR/nostart")
{
$WantRespawn="OFF";
}
$menuselection = $d->menu( title => "Server Status Menu", text => "Server is $ServerStatus and respawn is $WantRespawn - Select one:",
list => [ '1', 'Free Space',
'2', 'Current Version',
'3', 'Shell Users',
'4', 'Last Shell Logins',
'5', 'Running Processes',
'q', 'Main Menu' ] );
}
sub ServerStatusTools
{
while (-1)
{
ServerStatusMenu();
if (($menuselection eq "CANCEL") || ($menuselection eq "ESC") || ($menuselection eq "") || ($menuselection eq "q") || ($menuselection eq "Q"))
{
return;
}
elsif ($menuselection eq "1")
{
# Space Usage
system("clear");
SpaceUsage();
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "2")
{
# Get Version
system("clear");
system("$MINETESTDIR/bin/$ServerProcess --version");
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "3")
{
# Who's Online
system("clear");
system("$WhoCommand");
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "4")
{
# Last Logins
system("clear");
system("$LastCommand");
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "5")
{
# Top Processes
system("clear");
print "--- To exit this command press \"q\" ---";
my $entered = <STDIN>;
system("$TopCommand");
}
}
}
sub DoUpdate
{
my $DesiredDir = $_[0];
@ -362,7 +577,7 @@ sub DoUpdate
chdir ($DesiredDir);
PrintDebugCommand("Running $UpdateCommand in $DesiredDir\n");
system("$UpdateCommand");
print "Press Enter To Continue";
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
@ -396,6 +611,144 @@ sub UpdateTools
}
}
sub InstallMod
{
system("clear");
print "Enter the URL for the mod: ";
my $modurl = <>;
chomp($modurl);
if ($modurl eq "")
{
# Input was blank
print "No URL Specified - aborting\n";
sleep 5;
return;
}
# Try and validate URL
if( lc(substr($modurl, 0, 4)) ne "http")
{
# Doesn;t start with http
print "URL doesn't start with http - aborting\n";
sleep 5;
return;
}
if( lc(substr($modurl, -4)) ne ".git")
{
# Doesn;t end in .git
print "URL doesn't end with .git - aborting\n";
sleep 5;
return;
}
print "URL looks good - trying to clone\n";
chdir($ModDir);
system("git clone $modurl");
print "Were any errors reported? (N/y):";
my $input = <>;
chomp($input);
if (lc($input) eq "y")
{
print "Clone failed, please check URL or correct the issue and try again\n";
sleep 5;
return;
}
system("echo \"-----\n\" >> $MinetestWorld");
if ($? != 0)
{
print "Could not append to file '$MinetestWorld' - check perms: $!";
sleep 5;
return;
}
print "Killing Server Process\n";
system("killall $KillAllString");
print "Process killed...";
print "Waiting for server to restart\n";
my $count = 0;
while ($count < 120)
{
$count += 5;
print "$count ";
sleep 5;
}
print "Checking for new mod in world.mt\n";
my $file = $MinetestWorld;
my $SeenStart = 0;
open(FH, $file) or die("Unable to open file $file for reading");
open(FH2, ">/tmp/newfile") or die("Unable to open file $file for writing");
while(my $String = <FH>)
{
if ($_)
{
chop();
}
if($String =~ /-----/)
{
$SeenStart = -1;
print "Saw Marker\n";
next;
}
if ($SeenStart)
{
my $NewString = $String =~ s/= false/= true/r;
print(FH2 $NewString);
}
else
{
print(FH2 $String);
}
}
close(FH);
close(FH2);
system("cp /tmp/newfile $file");
print "Killing Server Process\n";
system("killall $KillAllString");
print "Process killed...";
print "Waiting for server to restart\n";
my $count = 0;
while ($count < 120)
{
$count += 5;
print "$count ";
sleep 5;
}
print "\nInstall prooess completed\n";
sleep 5;
}
sub RemoveFiles
{
for (split ' ', $FilesToRemove)
{
if (-f $_)
{
unlink($_);
}
}
}
sub SpaceUsage
{
system("clear");
print "System Space:\n";
print "==================\n";
system("$DfCommand");
print "\nSpace Used by You:\n";
print "==================\n";
system("$DuCommand");
print "\nDo you want to remove logs and other expendable items? (N/y): ";
my $input = <>;
chomp($input);
$input = lc($input);
if (($input eq "y") || ($input eq "yes"))
{
RemoveFiles();
print "Possible files removed...\n";
sleep 5;
return;
}
print "Leaving temporary files alone\n";
}
sub MainMenu
{
my $WantRespawn="ON";
@ -420,6 +773,10 @@ sub MainMenu
'12', 'Restart Server',
'13', 'Edit News.txt',
'14', 'Update Utils',
'15', 'Install Mod',
'16', 'Server Status',
'17', 'Scheduled Tasks',
'18', 'Server Tasks',
'q', 'Quit MMC' ] );
}
@ -446,7 +803,7 @@ while (-1)
{
system("$InitDName stop");
sleep(5);
system("killall /home/mtowner/minetest/bin/startminetest");
system("killall $ServerStartString");
}
}
elsif ($menuselection eq "3")
@ -492,7 +849,7 @@ while (-1)
# View online players
system("clear");
system("ls $PlayersDir");
print "Press Enter To Continue";
print "--- Press Enter To Continue ---";
my $entered = <STDIN>;
}
elsif ($menuselection eq "11")
@ -504,7 +861,7 @@ while (-1)
{
# Reset server process
print "Killing Server Process\n";
system("killall /home/mtowner/minetest/bin/minetestserver");
system("killall $KillAllString");
print "Process killed...";
sleep(5);
}
@ -518,6 +875,26 @@ while (-1)
# Update Menu
UpdateTools();
}
elsif ($menuselection eq "15")
{
# Install Mod
InstallMod();
}
elsif ($menuselection eq "16")
{
# Server Status Tools
ServerStatusTools();
}
elsif ($menuselection eq "17")
{
# Space Usage
system("$CrontabCommand");
}
elsif ($menuselection eq "18")
{
# Server Tools
ServerTools();
}
}
exit 0;