From 33737fec66585b6859bcef0c2bf3f7e3988ec1e9 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 30 Dec 2019 00:33:25 +0100 Subject: [PATCH 1/4] Create module boilerplate --- modules/command-line tools/__init__.py | 5 +++++ modules/command-line tools/cmd_tools.py | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 modules/command-line tools/__init__.py create mode 100644 modules/command-line tools/cmd_tools.py diff --git a/modules/command-line tools/__init__.py b/modules/command-line tools/__init__.py new file mode 100644 index 0000000..90465af --- /dev/null +++ b/modules/command-line tools/__init__.py @@ -0,0 +1,5 @@ +from .cmd_tools import CmdToolsModule + + +def get_module(): + return CmdToolsModule() \ No newline at end of file diff --git a/modules/command-line tools/cmd_tools.py b/modules/command-line tools/cmd_tools.py new file mode 100644 index 0000000..a0a8320 --- /dev/null +++ b/modules/command-line tools/cmd_tools.py @@ -0,0 +1,6 @@ +from AbstractModule import AbstractModule + + +class CmdToolsModule(AbstractModule): + def run(self): + print("Commandline Tools") From f5cd3c62341a6d26dc6c4f11d8fae707347f1766 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 30 Dec 2019 01:00:47 +0100 Subject: [PATCH 2/4] Add programs list, implement subprocess to start apt, error handling --- modules/command-line tools/cmd_tools.py | 15 ++++++++++++++- modules/command-line tools/programs.json | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 modules/command-line tools/programs.json diff --git a/modules/command-line tools/cmd_tools.py b/modules/command-line tools/cmd_tools.py index a0a8320..1cf319c 100644 --- a/modules/command-line tools/cmd_tools.py +++ b/modules/command-line tools/cmd_tools.py @@ -1,6 +1,19 @@ +import json +import subprocess + from AbstractModule import AbstractModule class CmdToolsModule(AbstractModule): def run(self): - print("Commandline Tools") + print("Try to install basic Command-line tools") + + with open("modules/command-line tools/programs.json") as config_file: + programms_list = json.load(config_file) + + out = subprocess.run(["apt", "install"] + programms_list, shell=True, capture_output=True) + if len(out.stderr) > 0: + print(out.stderr.decode()) + print("Install might be not complete, please check output above.") + else: + print("Installed successful.") diff --git a/modules/command-line tools/programs.json b/modules/command-line tools/programs.json new file mode 100644 index 0000000..d5a8228 --- /dev/null +++ b/modules/command-line tools/programs.json @@ -0,0 +1,8 @@ +[ + "bleachbit", + "nano", + "xrdp", + "htop", + "bash-completion", + "dialog" +] \ No newline at end of file From 9ec51fa959537a6a1d30e6c8c56e6736047e722f Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 30 Dec 2019 01:25:16 +0100 Subject: [PATCH 3/4] Fix wrong input for subprocess, remove output capturing Concat apt command entirely before execution. --- modules/command-line tools/cmd_tools.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/command-line tools/cmd_tools.py b/modules/command-line tools/cmd_tools.py index 1cf319c..0f7f66b 100644 --- a/modules/command-line tools/cmd_tools.py +++ b/modules/command-line tools/cmd_tools.py @@ -9,11 +9,11 @@ class CmdToolsModule(AbstractModule): print("Try to install basic Command-line tools") with open("modules/command-line tools/programs.json") as config_file: - programms_list = json.load(config_file) + programs_json = json.load(config_file) + programs_list = "" + for program in programs_json: + programs_list += " " + program - out = subprocess.run(["apt", "install"] + programms_list, shell=True, capture_output=True) - if len(out.stderr) > 0: - print(out.stderr.decode()) - print("Install might be not complete, please check output above.") - else: - print("Installed successful.") + subprocess.run("sudo apt install" + programs_list, shell=True) + + print("Script ran to completion.") From e9f92af66f532f103867754a9f2f7d6247580eff Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Fri, 6 Mar 2020 01:23:20 +0100 Subject: [PATCH 4/4] Rename module, split program categories --- modules/command-line tools/__init__.py | 5 ----- modules/command-line tools/cmd_tools.py | 19 ----------------- modules/command-line tools/programs.json | 8 -------- modules/program-installer/__init__.py | 5 +++++ modules/program-installer/module.py | 26 ++++++++++++++++++++++++ modules/program-installer/programs.json | 16 +++++++++++++++ 6 files changed, 47 insertions(+), 32 deletions(-) delete mode 100644 modules/command-line tools/__init__.py delete mode 100644 modules/command-line tools/cmd_tools.py delete mode 100644 modules/command-line tools/programs.json create mode 100644 modules/program-installer/__init__.py create mode 100644 modules/program-installer/module.py create mode 100644 modules/program-installer/programs.json diff --git a/modules/command-line tools/__init__.py b/modules/command-line tools/__init__.py deleted file mode 100644 index 90465af..0000000 --- a/modules/command-line tools/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .cmd_tools import CmdToolsModule - - -def get_module(): - return CmdToolsModule() \ No newline at end of file diff --git a/modules/command-line tools/cmd_tools.py b/modules/command-line tools/cmd_tools.py deleted file mode 100644 index 0f7f66b..0000000 --- a/modules/command-line tools/cmd_tools.py +++ /dev/null @@ -1,19 +0,0 @@ -import json -import subprocess - -from AbstractModule import AbstractModule - - -class CmdToolsModule(AbstractModule): - def run(self): - print("Try to install basic Command-line tools") - - with open("modules/command-line tools/programs.json") as config_file: - programs_json = json.load(config_file) - programs_list = "" - for program in programs_json: - programs_list += " " + program - - subprocess.run("sudo apt install" + programs_list, shell=True) - - print("Script ran to completion.") diff --git a/modules/command-line tools/programs.json b/modules/command-line tools/programs.json deleted file mode 100644 index d5a8228..0000000 --- a/modules/command-line tools/programs.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - "bleachbit", - "nano", - "xrdp", - "htop", - "bash-completion", - "dialog" -] \ No newline at end of file diff --git a/modules/program-installer/__init__.py b/modules/program-installer/__init__.py new file mode 100644 index 0000000..cb3e108 --- /dev/null +++ b/modules/program-installer/__init__.py @@ -0,0 +1,5 @@ +from .module import CmdToolsModule + + +def get_module(): + return CmdToolsModule() diff --git a/modules/program-installer/module.py b/modules/program-installer/module.py new file mode 100644 index 0000000..d798e95 --- /dev/null +++ b/modules/program-installer/module.py @@ -0,0 +1,26 @@ +import json +import subprocess + +from AbstractModule import AbstractModule + + +class CmdToolsModule(AbstractModule): + + def __init__(self): + super().__init__() + with open("modules/program-installer/programs.json") as config_file: + self.programs_json = json.load(config_file) + + def run(self): + """Install the most basic tools!""" + print("Try to install basic Command-line tools") + + programs_list = " ".join(p for p in self.programs_json['basic-tools']) + subprocess.run("apt install" + programs_list, shell=True) + + print("Script ran to completion.") + + def hard_drive_tools(self): + """Install tools to look up smart information from your hard-drives""" + programs_list = " ".join(p for p in self.programs_json['hard-drive']) + subprocess.run("apt install " + programs_list, shell=True) diff --git a/modules/program-installer/programs.json b/modules/program-installer/programs.json new file mode 100644 index 0000000..8a225c5 --- /dev/null +++ b/modules/program-installer/programs.json @@ -0,0 +1,16 @@ +{ + "basic-tools": [ + "bleachbit", + "nano", + "xrdp", + "htop", + "bash-completion", + "dialog", + "powertop", + "tree" + ], + "hard-drive": [ + "smartmontools", + "gsmartcontrol" + ] +} \ No newline at end of file