Use print helper functions

This commit is contained in:
Lucas Noki 2020-08-02 13:58:47 +02:00
parent b09431877e
commit c067b8c89d
7 changed files with 28 additions and 14 deletions

View File

@ -1,13 +1,15 @@
import subprocess
from shutil import copyfile
from print_helpers import print_bold
def run():
subprocess.call("apt install fail2ban -y", shell=True)
try:
ufw_is_installed = subprocess.check_output("which ufw", shell=True).decode().strip()
print(f"ufw is already installed in {ufw_is_installed}")
print_bold(f"ufw is already installed in {ufw_is_installed}")
except subprocess.CalledProcessError:
subprocess.call("sudo apt install ufw -y", shell=True)
subprocess.call("ufw allow ssh && ufw enable", shell=True)

View File

@ -3,6 +3,8 @@ import random
import subprocess
from os import path
from print_helpers import print_gr
def run_bash():
try:
@ -21,11 +23,10 @@ def run_py():
for i in range(count):
pos = random.randint(0, columns)
hacker = hacker[:pos] + str(num_to_show) + hacker[pos + 1:]
print("\033[92m" + hacker)
print_gr(hacker)
except KeyboardInterrupt:
print(columns)
print("Finished")
print("\033[0m")
print_gr("Finished")
functions = {

View File

@ -1,11 +1,11 @@
import subprocess
from print_helpers import print_gr
from print_helpers import print_warn, print_gr
def basic_tools():
"""Install the most basic tools!"""
print("Try to install basic Command-line tools")
print_warn("Try to install basic Command-line tools")
subprocess.run(
"apt update && apt-get install -y bleachbit nano htop bash-completion dialog powertop tree wget vim git",
shell=True

View File

@ -1,5 +1,7 @@
import subprocess
from print_helpers import print_gr
def run():
print("Running update")
@ -8,7 +10,7 @@ def run():
subprocess.call(["apt", "dist-upgrade", "-y"])
subprocess.call(["apt", "autoremove", "-y"])
subprocess.call(["apt", "autoclean", "-y"])
print("All update processes finished, please check output for further details.")
print_gr("All update processes finished, please check output for further details.")
functions = {

View File

@ -3,6 +3,8 @@ import subprocess
import time
from os import path
from print_helpers import print_bold
def start():
"""Starts a Teamspeak Server with docker-compose"""
@ -12,9 +14,10 @@ def start():
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))
logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode(
"UTF-8")
print_bold("Server Query Admin Account: " + re.search(r"loginname=.*", logs).group(0))
print_bold("Server Admin Token: " + re.search(r"token=(.*)", logs).group(1))
def stop():

View File

@ -5,6 +5,8 @@ from pathlib import Path
from PyInquirer import prompt
from print_helpers import print_gr, print_bold
vim_root = Path().home().joinpath(".vim")
vimrc_path = str(Path().home().joinpath(".vimrc"))
json_config = {}
@ -22,7 +24,7 @@ def create_plugin_section():
}
]
selected_plugins = prompt(plugin_selection)['modules']
print("\033[4mYour selection:\033[0m")
print_bold("Your selection:")
[print(x) for x in selected_plugins]
# Install vimplug if plugins selected
@ -30,7 +32,7 @@ def create_plugin_section():
if selected_plugins and not os.path.isfile(vimplug_path):
curl_request = f"curl {json_config['pluginmanager_url']} -o {vimplug_path}"
subprocess.call(curl_request, shell=True)
print("Pluginmanager was set up")
print_gr("Pluginmanager was set up")
vimrc_content = ["call plug#begin('~/.vim/plugged')\n"]
for element in selected_plugins:
@ -42,7 +44,7 @@ def create_plugin_section():
def create_setting_section():
default_settings = list(json_config['settings'].values())
print("\n\033[4mDefault settings:\033[0m")
print_bold("Default settings:")
[print(i) for i in default_settings]
vimrc_content = list(map(lambda x: x + "\n", default_settings))
@ -86,7 +88,7 @@ def run():
# Exec plugin manager
install_plugins = "vim +PlugInstall +qall"
subprocess.call(install_plugins, shell=True)
print("Module finished successfully!")
print_gr("Module finished successfully!")
functions = run

View File

@ -12,3 +12,7 @@ def print_warn(text):
def print_blue(text):
print("\033[94m" + "[+] " + text + "\033[0m")
def print_bold(text):
print("\033[1m" + text + "\033[0m")