From 14c58905b8514049b7e222a5f2dd39fc87300d73 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 21 Mar 2020 22:29:07 +0100 Subject: [PATCH] Implement Teamspeak module --- main.py | 4 +++- modules/teamspeak/.gitignore | 3 +++ modules/teamspeak/Teamspeak.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 modules/teamspeak/.gitignore create mode 100644 modules/teamspeak/Teamspeak.py diff --git a/main.py b/main.py index f1ea7ec..0362dc4 100644 --- a/main.py +++ b/main.py @@ -5,13 +5,15 @@ from modules.install.ToolsInstaller import ToolsInstaller from modules.swap.SwapModule import SwapModule from modules.systemupdate.Systemupdate import Systemupdate from modules.vim.VimModule import VimModule +from modules.teamspeak.Teamspeak import Teamspeak modules = { "helloworld": HelloWorld().run, "install": ToolsInstaller, "swap": SwapModule().run, "update": Systemupdate().run, - "vim": VimModule().run + "vim": VimModule().run, + "teamspeak": Teamspeak } fire.Fire(modules) diff --git a/modules/teamspeak/.gitignore b/modules/teamspeak/.gitignore new file mode 100644 index 0000000..fed9262 --- /dev/null +++ b/modules/teamspeak/.gitignore @@ -0,0 +1,3 @@ +ts3_data +*.tar +*.gz \ No newline at end of file diff --git a/modules/teamspeak/Teamspeak.py b/modules/teamspeak/Teamspeak.py new file mode 100644 index 0000000..63d1863 --- /dev/null +++ b/modules/teamspeak/Teamspeak.py @@ -0,0 +1,30 @@ +import subprocess +from os import path +import time +import re + + +class Teamspeak: + + def start(self): + """Starts a Teamspeak Server with docker-compose""" + show_creds = False if path.exists(path.join(path.dirname(__file__), "ts3_data")) else True + subprocess.run("docker-compose up -d", shell=True, cwd=path.dirname(__file__)) + if show_creds: + logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode("UTF-8") + while re.search(r"token", logs) is None: + time.sleep(2) + logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode("UTF-8") + print("Server Query Admin Account: " + re.search(r"loginname=.*", logs).group(0)) + print("Server Admin Token: " + re.search(r"token=(.*)", logs).group(1)) + + def stop(self): + """Stops the Teamspeak Server with docker-compose""" + subprocess.run("docker-compose down -v", shell=True, cwd=path.dirname(__file__)) + + def pack_data(self, name="ts3_data.tar.gz"): + """Pack all user data of the server started with this script as tar file""" + subprocess.run(f"tar -zcvf {name} ts3_data", shell=True, cwd=path.dirname(__file__)) + + def show_logs(self): + subprocess.run("docker-compose logs", shell=True, cwd=path.dirname(__file__))