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 import subprocess
from shutil import copyfile from shutil import copyfile
from print_helpers import print_bold
def run(): def run():
subprocess.call("apt install fail2ban -y", shell=True) subprocess.call("apt install fail2ban -y", shell=True)
try: try:
ufw_is_installed = subprocess.check_output("which ufw", shell=True).decode().strip() 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: except subprocess.CalledProcessError:
subprocess.call("sudo apt install ufw -y", shell=True) subprocess.call("sudo apt install ufw -y", shell=True)
subprocess.call("ufw allow ssh && ufw enable", shell=True) subprocess.call("ufw allow ssh && ufw enable", shell=True)

View File

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

View File

@ -1,11 +1,11 @@
import subprocess import subprocess
from print_helpers import print_gr from print_helpers import print_warn, print_gr
def basic_tools(): def basic_tools():
"""Install the most 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( subprocess.run(
"apt update && apt-get install -y bleachbit nano htop bash-completion dialog powertop tree wget vim git", "apt update && apt-get install -y bleachbit nano htop bash-completion dialog powertop tree wget vim git",
shell=True shell=True

View File

@ -1,5 +1,7 @@
import subprocess import subprocess
from print_helpers import print_gr
def run(): def run():
print("Running update") print("Running update")
@ -8,7 +10,7 @@ def run():
subprocess.call(["apt", "dist-upgrade", "-y"]) subprocess.call(["apt", "dist-upgrade", "-y"])
subprocess.call(["apt", "autoremove", "-y"]) subprocess.call(["apt", "autoremove", "-y"])
subprocess.call(["apt", "autoclean", "-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 = { functions = {

View File

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

View File

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

View File

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