ausgaben auf dem terminal verbessert
This commit is contained in:
parent
bf2b7d9f36
commit
51b8e30b84
|
@ -2,13 +2,15 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require __DIR__.'/scripts/class.TerminalMessage.php';
|
||||||
require __DIR__.'/scripts/func.downloadFile.php';
|
require __DIR__.'/scripts/func.downloadFile.php';
|
||||||
require __DIR__.'/scripts/class.FactorioVersion.php';
|
require __DIR__.'/scripts/class.FactorioVersion.php';
|
||||||
require __DIR__.'/scripts/class.Systemctl.php';
|
require __DIR__.'/scripts/class.Systemctl.php';
|
||||||
require __DIR__.'/scripts/class.ValveRcon.php';
|
require __DIR__.'/scripts/class.ValveRcon.php';
|
||||||
|
|
||||||
|
|
||||||
|
$cli = new \NAE\Terminal\TerminalMessage();
|
||||||
|
|
||||||
|
|
||||||
// Welches Build ist gewünscht?
|
// Welches Build ist gewünscht?
|
||||||
$target_build = "stable";
|
$target_build = "stable";
|
||||||
|
@ -43,7 +45,7 @@ $current_version_str = (function(){
|
||||||
|
|
||||||
})();
|
})();
|
||||||
$current_version = new \NAE\Factorio\FactorioVersion($current_version_str);
|
$current_version = new \NAE\Factorio\FactorioVersion($current_version_str);
|
||||||
echo "CURRENT_VERSION: ".$current_version->getVersion().PHP_EOL;
|
$cli->sendInfo( "CURRENT_VERSION: ".$current_version->getVersion() );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +54,8 @@ $live_versions = json_decode(file_get_contents("https://factorio.com/api/latest-
|
||||||
|
|
||||||
// Anhand von Build und Edition die richtige Version auswählen.
|
// Anhand von Build und Edition die richtige Version auswählen.
|
||||||
$latest_version = new \NAE\Factorio\FactorioVersion($live_versions[$target_build][$target_edition]);
|
$latest_version = new \NAE\Factorio\FactorioVersion($live_versions[$target_build][$target_edition]);
|
||||||
echo "LATEST_VERSION: ".$latest_version->getVersion().PHP_EOL.PHP_EOL;
|
$cli->sendInfo( "LATEST_VERSION: ".$latest_version->getVersion() );
|
||||||
|
echo PHP_EOL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,47 +84,48 @@ function writeBackVersion() : bool {
|
||||||
$download_success = false;
|
$download_success = false;
|
||||||
$extract_success = false;
|
$extract_success = false;
|
||||||
|
|
||||||
echo "# [ PRÜFE AUF FACTORIO UPDATES ]".PHP_EOL;
|
$cli->sendTitle( "PRÜFE AUF FACTORIO UPDATES" );
|
||||||
|
|
||||||
if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
|
|
||||||
echo "## [ NEUE VERSION GEFUNDEN : UPDATE STARTET ]".PHP_EOL;
|
$cli->sendTitle( "NEUE VERSION GEFUNDEN : UPDATE STARTET" );
|
||||||
|
|
||||||
if(file_exists($download_output)) { // liegt noch ein altes Server Archiv im Vertzeichnis?
|
if(file_exists($download_output)) { // liegt noch ein altes Server Archiv im Vertzeichnis?
|
||||||
|
|
||||||
echo PHP_EOL."[ ALTE SERVER FILES GEFUNDEN : STARTE LÖSCHVORGANG ]".PHP_EOL;
|
$cli->sendTitle( "ALTE SERVER FILES GEFUNDEN : STARTE LÖSCHVORGANG", 1 );
|
||||||
|
|
||||||
if( unlink($download_output) ) { // altes Archiv löschen
|
if( unlink($download_output) ) { // altes Archiv löschen
|
||||||
|
|
||||||
echo "-> ALTE SERVER FILES ERFOLGREICH GELÖSCHT!".PHP_EOL;
|
$cli->sendSuccess( "ALTE SERVER FILES ERFOLGREICH GELÖSCHT!" );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "-> ERR : ALTE SERVER FILES ERFOLGREICH GELÖSCHT!".PHP_EOL;
|
$cli->sendError( "ALTE SERVER FILES KONNTEN NICHT GELÖSCHT WERDEN!", true );
|
||||||
die(1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo PHP_EOL."[ STARTE DOWNLOAD DER SERVER FILES ]".PHP_EOL;
|
|
||||||
|
echo PHP_EOL;
|
||||||
|
$cli->sendTitle( "STARTE DOWNLOAD DER SERVER FILES", 1 );
|
||||||
|
|
||||||
if(\NAE\Functions\Curl\downloadFile($download_output, $download_source)) { // Download der neuen Server Files
|
if(\NAE\Functions\Curl\downloadFile($download_output, $download_source)) { // Download der neuen Server Files
|
||||||
|
|
||||||
echo "-> DOWNLOAD SUCCESS!".PHP_EOL;
|
$cli->sendSuccess( "DOWNLOAD SUCCESS!" );
|
||||||
$download_success = true;
|
$download_success = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "-> ERR : DOWNLOAD FEHLGESCHLAGEN!".PHP_EOL;
|
$cli->sendError( "DOWNLOAD FEHLGESCHLAGEN!", true );
|
||||||
die(1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($download_success) {
|
if($download_success) {
|
||||||
|
|
||||||
echo PHP_EOL."[ STARTE DAS ENTPACKEN DER NEUEN SERVER FILES ]".PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
$cli->sendTitle( "STARTE DAS ENTPACKEN DER NEUEN SERVER FILES", 1 );
|
||||||
|
|
||||||
exec("tar -xvf \"$download_output\" > /dev/null", $output, $return); // Entpacken
|
exec("tar -xvf \"$download_output\" > /dev/null", $output, $return); // Entpacken
|
||||||
|
|
||||||
|
@ -129,20 +133,18 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
|
|
||||||
if( rename(__DIR__."/factorio", __DIR__."/factorio-".$latest_version->getVersion()) ) { // Umbenennen mit Versionsnummer
|
if( rename(__DIR__."/factorio", __DIR__."/factorio-".$latest_version->getVersion()) ) { // Umbenennen mit Versionsnummer
|
||||||
|
|
||||||
echo "-> Neue Server Files wurden Erfolgreich entpackt!".PHP_EOL;
|
$cli->sendSuccess( "Neue Server Files wurden Erfolgreich entpackt!" );
|
||||||
$extract_success = true;
|
$extract_success = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "-> ERR : Umbenennen des Factorio Ordners mit Versionsnummer Fehlgeschlagen!".PHP_EOL;
|
$cli->sendError( "Umbenennen des Factorio Ordners mit Versionsnummer Fehlgeschlagen!", true );
|
||||||
die(1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "-> ERR : Entpacken der Server Files ist Fehlgeschlagen!".PHP_EOL;
|
$cli->sendError( "Entpacken der Server Files ist Fehlgeschlagen!", true );
|
||||||
die(1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,13 +186,13 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
$rcon->sendCommand("ACHTUNG: Server wird in kürze für ein Update gestoppt, bitte trennen Sie Ihre Verbindung zum Server. Der Server wird in kürze wieder verfügbar sein. Zeit bis zum Stopp: 60 Sekunden.", false);
|
$rcon->sendCommand("ACHTUNG: Server wird in kürze für ein Update gestoppt, bitte trennen Sie Ihre Verbindung zum Server. Der Server wird in kürze wieder verfügbar sein. Zeit bis zum Stopp: 60 Sekunden.", false);
|
||||||
|
|
||||||
if($rcon->getError() !== null) {
|
if($rcon->getError() !== null) {
|
||||||
echo "[!] ERR : RCON Verbindung konnte nicht aufgebaut werden!".PHP_EOL;
|
$cli->sendWarning( "RCON Verbindung konnte nicht aufgebaut werden!" );
|
||||||
$rcon = null;
|
$rcon = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
|
|
||||||
echo "[!] ERR : RCON Verbindung konnte nicht aufgebaut werden!".PHP_EOL;
|
$cli->sendWarning( "RCON Verbindung konnte nicht aufgebaut werden!" );
|
||||||
$rcon = null;
|
$rcon = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -204,18 +206,19 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
|
|
||||||
// Server Stoppen
|
// Server Stoppen
|
||||||
if($service->stop()) {
|
if($service->stop()) {
|
||||||
echo "[+] FACTORIO SERVER WURDE GESTOPPT!".PHP_EOL;
|
$cli->sendInfo( "FACTORIO SERVER WURDE GESTOPPT!" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// neue Versionsnummer in .env Datei übernehmen
|
// neue Versionsnummer in .env Datei übernehmen
|
||||||
if(writeBackVersion()) {
|
if(writeBackVersion()) {
|
||||||
echo "[+] Version in Environment File ist aktualisiert".PHP_EOL;
|
$cli->sendInfo( "Version in Environment File wurde aktualisiert" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dateien aus alten Server Files kopieren..
|
// Dateien aus alten Server Files kopieren..
|
||||||
if( is_dir(__DIR__."/factorio-".$current_version->getVersion()) && is_dir(__DIR__."/factorio-".$latest_version->getVersion()) ) {
|
if( is_dir(__DIR__."/factorio-".$current_version->getVersion()) && is_dir(__DIR__."/factorio-".$latest_version->getVersion()) ) {
|
||||||
|
|
||||||
echo PHP_EOL."[ Kopiere Konfigurations-Dateien in den neuen Server Pfad ]".PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
$cli->sendTitle( "Kopiere Konfigurations-Dateien in den neuen Server Pfad", 1 );
|
||||||
|
|
||||||
foreach($copy_paths as $copy_id => $copy_name) {
|
foreach($copy_paths as $copy_id => $copy_name) {
|
||||||
|
|
||||||
|
@ -224,20 +227,20 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
|
|
||||||
if(file_exists($copy_source)) {
|
if(file_exists($copy_source)) {
|
||||||
|
|
||||||
echo "[ Kopierenvorgang Nr. ".($copy_id+1)." von ".count($copy_paths)." - $copy_name ] ";
|
$cli->sendTitle( "Kopierenvorgang Nr. ".($copy_id+1)." von ".count($copy_paths)." - $copy_name", 2 );
|
||||||
if(copy($copy_source, $copy_dest)) {
|
if(copy($copy_source, $copy_dest)) {
|
||||||
|
|
||||||
echo "-> Kopiervorgang Erfolgreich!".PHP_EOL;
|
$cli->sendSuccess( "Kopiervorgang Erfolgreich!" );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "-> ERR : Kopiervorgang Fehlgeschlagen!".PHP_EOL;
|
$cli->sendError( "Kopiervorgang Fehlgeschlagen!" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo " - Quelle nicht vorhanden!".PHP_EOL;
|
$cli->sendWarning( "Quelle nicht vorhanden!" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,20 +251,23 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
// Fix file permissions..
|
// Fix file permissions..
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
global $latest_version;
|
global $latest_version, $cli;
|
||||||
|
|
||||||
|
$cli->sendTitle( "Rechte im neuen Server-Verzeichnis werden korrigiert", 1 );
|
||||||
exec("chown -R factorio:factorio \"".__DIR__."/factorio-".$latest_version->getVersion()."\"", $output, $return);
|
exec("chown -R factorio:factorio \"".__DIR__."/factorio-".$latest_version->getVersion()."\"", $output, $return);
|
||||||
if($return === 0) {
|
if($return === 0) {
|
||||||
echo "[+] Rechte im neuen Server verzeichnis korrigiert.".PHP_EOL;
|
$cli->sendSuccess( "Rechte erfolgreich korrigiert!" );
|
||||||
} else {
|
} else {
|
||||||
echo "[!] ERR : Rechte im neuen Server verzeichnis konnten nicht korrigiert werden.".PHP_EOL;
|
$cli->sendError( "Rechte konnten nicht korrigiert werden!", true );
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
if($service->start()) {
|
if($service->start()) {
|
||||||
echo "[+] FACTORIO SERVER WURDE WIEDER GESTARTET!".PHP_EOL;
|
$cli->sendSuccess( "FACTORIO SERVER WURDE WIEDER GESTARTET!" );
|
||||||
|
} else {
|
||||||
|
$cli->sendError( "FACTORIO SERVER KONNTE NICHT WIEDER GESTARTET WERDEN!", true );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -271,6 +277,6 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Keine aktuellere Version verfügbar!
|
// Keine aktuellere Version verfügbar!
|
||||||
echo "-> Kein Update verfügbar.".PHP_EOL;
|
$cli->sendInfo( "Kein Update verfügbar." );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NAE\Terminal;
|
||||||
|
|
||||||
|
class TerminalMessage {
|
||||||
|
|
||||||
|
public function send(string $msg) {
|
||||||
|
echo $msg . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendTitle(string $msg, int $layer=0) {
|
||||||
|
$layerString = "#";
|
||||||
|
for($i=0; $i<$layer; $i++) {
|
||||||
|
$layerString .= "#";
|
||||||
|
}
|
||||||
|
self::send( "\033[1m[$layerString] $msg\033[0m" . PHP_EOL );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendSuccess(string $msg) {
|
||||||
|
self::send( "\033[1;32m[SUCCESS] $msg\033[0m" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendInfo(string $msg) {
|
||||||
|
self::send( "\033[1;34m[INFO] $msg\033[0m" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendError(string $msg, bool $critical=false) {
|
||||||
|
self::send( "\033[1;31m[ERROR] $msg\033[0m" );
|
||||||
|
if ($critical) {
|
||||||
|
die(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendWarning(string $msg, bool $critical=false) {
|
||||||
|
self::send( "\033[1;33m[WARNING] $msg\033[0m" );
|
||||||
|
if ($critical) {
|
||||||
|
die(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue