From dcb8374f7077f6d845a6c42e1f1c1b06eab76de2 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 10 Mar 2020 23:02:33 +0100 Subject: [PATCH 01/13] Add docker in installer --- modules/install/ToolsInstaller.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index 0a0d408..7a758b1 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -13,11 +13,28 @@ class ToolsInstaller: 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) + subprocess.run("apt-get 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) + subprocess.run("apt-get install " + programs_list, shell=True) + + def docker(self): + """Install the Docker service on the machine""" + print("Removing any old installations") + subprocess.run("apt-get remove docker docker-engine docker.io containerd runc", shell=True) + print("Set up docker apt-key") + subprocess.run("apt-get update", shell=True) + subprocess.run("apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common", shell=True) + subprocess.run("curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", shell=True) + subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) + subprocess.run("add-apt-repository " + "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs)stable\"", shell=True) + print("Installing the Service") + subprocess.run("apt-get update", shell=True) + subprocess.run("apt-get install docker-ce docker-ce-cli containerd.io", shell=True) + print("Checking the installation") + subprocess.run("docker run hello-world", shell=True) From 7705ba9cae0ee172222cde2ec5e6e77c1d96e478 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 10 Mar 2020 23:12:19 +0100 Subject: [PATCH 02/13] Add auto accept and platform distinction in docker --- modules/install/ToolsInstaller.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index 7a758b1..a4f1922 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -1,4 +1,5 @@ import json +import platform import subprocess @@ -24,17 +25,26 @@ class ToolsInstaller: def docker(self): """Install the Docker service on the machine""" + print("Removing any old installations") subprocess.run("apt-get remove docker docker-engine docker.io containerd runc", shell=True) print("Set up docker apt-key") subprocess.run("apt-get update", shell=True) - subprocess.run("apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common", shell=True) + subprocess.run( + "apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common", + shell=True) subprocess.run("curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", shell=True) subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) - subprocess.run("add-apt-repository " - "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs)stable\"", shell=True) + if "ubuntu" in platform.version().lower(): + subprocess.run("add-apt-repository " + "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"", + shell=True) + elif "debian" in platform.version().lower(): + subprocess.run("add-apt-repository " + "\"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable\"", + shell=True) print("Installing the Service") subprocess.run("apt-get update", shell=True) - subprocess.run("apt-get install docker-ce docker-ce-cli containerd.io", shell=True) + subprocess.run("apt-get install -y docker-ce docker-ce-cli containerd.io", shell=True) print("Checking the installation") subprocess.run("docker run hello-world", shell=True) From 76c5dc836392c0acbbc44791d8187e8ea42276ff Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 10 Mar 2020 23:33:52 +0100 Subject: [PATCH 03/13] Check if sources.list entry is already there --- modules/install/ToolsInstaller.py | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index a4f1922..3d30e97 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -25,26 +25,38 @@ class ToolsInstaller: def docker(self): """Install the Docker service on the machine""" - print("Removing any old installations") subprocess.run("apt-get remove docker docker-engine docker.io containerd runc", shell=True) - print("Set up docker apt-key") subprocess.run("apt-get update", shell=True) subprocess.run( "apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common", shell=True) - subprocess.run("curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", shell=True) - subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) - if "ubuntu" in platform.version().lower(): - subprocess.run("add-apt-repository " - "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"", - shell=True) - elif "debian" in platform.version().lower(): - subprocess.run("add-apt-repository " - "\"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable\"", - shell=True) + + print("Checking for entry in /etc/apt/sources.list") + with open("/etc/apt/sources.list") as apt_list: + line = apt_list.read() + if "download.docker.com/linux/" not in line.lower(): + print("apt-repo is not installed, setting up docker apt-key") + if "ubuntu" in platform.version().lower(): + subprocess.run("curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", + shell=True) + subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) + subprocess.run("add-apt-repository " + "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"", + shell=True) + elif "debian" in platform.version().lower(): + subprocess.run("curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -", + shell=True) + subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) + subprocess.run("add-apt-repository " + "\"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable\"", + shell=True) + else: + print("skip adding of the key") + print("Installing the Service") subprocess.run("apt-get update", shell=True) subprocess.run("apt-get install -y docker-ce docker-ce-cli containerd.io", shell=True) + print("Checking the installation") - subprocess.run("docker run hello-world", shell=True) + subprocess.run("docker run --rm hello-world", shell=True) From df127f63e2153e51ffdd89a64be09c58dff43585 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 11 Mar 2020 00:16:39 +0100 Subject: [PATCH 04/13] Dynamically adjust url and gpg key --- modules/install/ToolsInstaller.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index 3d30e97..42e8156 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -38,19 +38,22 @@ class ToolsInstaller: if "download.docker.com/linux/" not in line.lower(): print("apt-repo is not installed, setting up docker apt-key") if "ubuntu" in platform.version().lower(): - subprocess.run("curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", - shell=True) - subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) - subprocess.run("add-apt-repository " - "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"", - shell=True) + linux_distro = "ubuntu" elif "debian" in platform.version().lower(): - subprocess.run("curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -", - shell=True) - subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) - subprocess.run("add-apt-repository " - "\"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable\"", - shell=True) + linux_distro = "debian" + else: + print("Version not supported by this installer") + return + + subprocess.run("curl -fsSL " + f"https://download.docker.com/linux/${linux_distro}/gpg " + "| sudo apt-key add -", + shell=True) + subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) + subprocess.run("add-apt-repository \"deb [arch=amd64] " + f"https://download.docker.com/linux/${linux_distro}" + "$(lsb_release -cs) stable\"", + shell=True) else: print("skip adding of the key") From 2a2805150e3028dc98f1ed5948ffd3b5f98fdbba Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 11 Mar 2020 00:29:55 +0100 Subject: [PATCH 05/13] Pull out base url --- modules/install/ToolsInstaller.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index 42e8156..d494c79 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -44,15 +44,12 @@ class ToolsInstaller: else: print("Version not supported by this installer") return + + base_url = f"https://download.docker.com/linux/${linux_distro}" - subprocess.run("curl -fsSL " - f"https://download.docker.com/linux/${linux_distro}/gpg " - "| sudo apt-key add -", - shell=True) + subprocess.run("curl -fsSL " + base_url + "/gpg | sudo apt-key add -", shell=True) subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) - subprocess.run("add-apt-repository \"deb [arch=amd64] " - f"https://download.docker.com/linux/${linux_distro}" - "$(lsb_release -cs) stable\"", + subprocess.run("add-apt-repository \"deb [arch=amd64] " + base_url + " $(lsb_release -cs) stable\"", shell=True) else: print("skip adding of the key") From 43016d7326d8530d780b32774c65bd0e96ee9ff6 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 11 Mar 2020 00:33:29 +0100 Subject: [PATCH 06/13] Remove wrong dollar sign --- modules/install/ToolsInstaller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index d494c79..4c6893c 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -44,8 +44,8 @@ class ToolsInstaller: else: print("Version not supported by this installer") return - - base_url = f"https://download.docker.com/linux/${linux_distro}" + + base_url = f"https://download.docker.com/linux/{linux_distro}" subprocess.run("curl -fsSL " + base_url + "/gpg | sudo apt-key add -", shell=True) subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) From 5fc955e405898d8b4e02bbbd93261d2c1e2d59e4 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 11 Mar 2020 00:38:42 +0100 Subject: [PATCH 07/13] Remove programms.json --- modules/install/ToolsInstaller.py | 13 ++----------- modules/install/programs.json | 16 ---------------- 2 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 modules/install/programs.json diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index 4c6893c..a84ee23 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -1,27 +1,18 @@ -import json import platform import subprocess class ToolsInstaller: - def __init__(self): - with open("modules/install/programs.json") as config_file: - self.programs_json = json.load(config_file) - def basic_tools(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-get install" + programs_list, shell=True) - + subprocess.run("apt-get install bleachbit nano xrdp htop bash-completion dialog powertop tree", 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-get install " + programs_list, shell=True) + subprocess.run("apt-get install smartmontools gsmartcontrol", shell=True) def docker(self): """Install the Docker service on the machine""" diff --git a/modules/install/programs.json b/modules/install/programs.json deleted file mode 100644 index 8a225c5..0000000 --- a/modules/install/programs.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "basic-tools": [ - "bleachbit", - "nano", - "xrdp", - "htop", - "bash-completion", - "dialog", - "powertop", - "tree" - ], - "hard-drive": [ - "smartmontools", - "gsmartcontrol" - ] -} \ No newline at end of file From e5f90f6c0c4d7210acc214033790937ed624b30f Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 11 Mar 2020 00:41:17 +0100 Subject: [PATCH 08/13] Add -y option to all apt-get commands --- modules/install/ToolsInstaller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index a84ee23..b2fc5fc 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -7,12 +7,12 @@ class ToolsInstaller: def basic_tools(self): """Install the most basic tools!""" print("Try to install basic Command-line tools") - subprocess.run("apt-get install bleachbit nano xrdp htop bash-completion dialog powertop tree", shell=True) + subprocess.run("apt-get install -y bleachbit nano xrdp htop bash-completion dialog powertop tree", shell=True) print("Script ran to completion.") def hard_drive_tools(self): """Install tools to look up smart information from your hard-drives""" - subprocess.run("apt-get install smartmontools gsmartcontrol", shell=True) + subprocess.run("apt-get install -y smartmontools gsmartcontrol", shell=True) def docker(self): """Install the Docker service on the machine""" From 9209f0bf3f848d6a80894280b8409f00402b666a Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 21 Mar 2020 02:07:42 +0100 Subject: [PATCH 09/13] Fix warnings in lnxtools.sh change apt to apt-get --- lnxtools.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lnxtools.sh b/lnxtools.sh index 77ef64b..3dc3971 100755 --- a/lnxtools.sh +++ b/lnxtools.sh @@ -5,13 +5,13 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" if [ "$1" == "prepare" ] then echo "Preparing your system for the first run" - apt update -y && apt upgrade -y - apt install python3.7 python3-pip -y + apt-get update -y && apt-get upgrade -y + apt-get install python3.7 python3-pip -y pip3 install setuptools wheel regex - cd $DIR + cd "$DIR" || exit pip3 install -r requirements.txt python3 main.py helloworld else - cd $DIR + cd "$DIR" || exit python3 main.py "$@" fi From 372e11f0c212ca30c4a8ee7a47890101a7c4b1a3 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 21 Mar 2020 02:08:22 +0100 Subject: [PATCH 10/13] Add system info generation to hello world script --- modules/helloworld/HelloWorld.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/helloworld/HelloWorld.py b/modules/helloworld/HelloWorld.py index c30b036..da7e0c2 100644 --- a/modules/helloworld/HelloWorld.py +++ b/modules/helloworld/HelloWorld.py @@ -1,6 +1,13 @@ +import subprocess + + class HelloWorld: """docstring for SampleModule.""" def run(self): print("This shows that your installation is working correctly.") print("You can now start using the tool.") + output = subprocess.check_output("cat /etc/*-release", shell=True).decode("UTF-8") + print("Your system information \n" + output) + with open("your_system_information.txt", "w") as file: + file.write(output) From b55318da263121857f82c7e27655c0eeea78e40f Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 21 Mar 2020 04:07:53 +0100 Subject: [PATCH 11/13] Use official docker install script add docker compose --- modules/install/ToolsInstaller.py | 40 ++++--------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index b2fc5fc..4538361 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -1,4 +1,3 @@ -import platform import subprocess @@ -16,38 +15,7 @@ class ToolsInstaller: def docker(self): """Install the Docker service on the machine""" - print("Removing any old installations") - subprocess.run("apt-get remove docker docker-engine docker.io containerd runc", shell=True) - subprocess.run("apt-get update", shell=True) - subprocess.run( - "apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common", - shell=True) - - print("Checking for entry in /etc/apt/sources.list") - with open("/etc/apt/sources.list") as apt_list: - line = apt_list.read() - if "download.docker.com/linux/" not in line.lower(): - print("apt-repo is not installed, setting up docker apt-key") - if "ubuntu" in platform.version().lower(): - linux_distro = "ubuntu" - elif "debian" in platform.version().lower(): - linux_distro = "debian" - else: - print("Version not supported by this installer") - return - - base_url = f"https://download.docker.com/linux/{linux_distro}" - - subprocess.run("curl -fsSL " + base_url + "/gpg | sudo apt-key add -", shell=True) - subprocess.run("apt-key fingerprint 0EBFCD88", shell=True) - subprocess.run("add-apt-repository \"deb [arch=amd64] " + base_url + " $(lsb_release -cs) stable\"", - shell=True) - else: - print("skip adding of the key") - - print("Installing the Service") - subprocess.run("apt-get update", shell=True) - subprocess.run("apt-get install -y docker-ce docker-ce-cli containerd.io", shell=True) - - print("Checking the installation") - subprocess.run("docker run --rm hello-world", shell=True) + subprocess.run("curl -fsSL https://get.docker.com | bash", shell=True) + subprocess.run("curl -L \"https://github.com/docker/compose/releases/download/" + "1.25.4/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose" + "&& chmod +x /usr/local/bin/docker-compose", shell=True) From 657b864202903dc8891a29e8f736ca7d995f3b32 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 21 Mar 2020 04:11:01 +0100 Subject: [PATCH 12/13] Use file exists to check wether install is needed run screenfetch in helloworld module --- lnxtools.sh | 9 ++++----- modules/helloworld/HelloWorld.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lnxtools.sh b/lnxtools.sh index 3dc3971..e4ee61b 100755 --- a/lnxtools.sh +++ b/lnxtools.sh @@ -1,17 +1,16 @@ #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$DIR" || exit +FILE=./your_system_information.txt -if [ "$1" == "prepare" ] -then +if [ ! -f "$FILE" ]; then echo "Preparing your system for the first run" apt-get update -y && apt-get upgrade -y - apt-get install python3.7 python3-pip -y + apt-get install curl screenfetch python3.7 python3-pip -y pip3 install setuptools wheel regex - cd "$DIR" || exit pip3 install -r requirements.txt python3 main.py helloworld else - cd "$DIR" || exit python3 main.py "$@" fi diff --git a/modules/helloworld/HelloWorld.py b/modules/helloworld/HelloWorld.py index da7e0c2..50975bb 100644 --- a/modules/helloworld/HelloWorld.py +++ b/modules/helloworld/HelloWorld.py @@ -6,8 +6,8 @@ class HelloWorld: def run(self): print("This shows that your installation is working correctly.") + subprocess.call("screenfetch", shell=True) print("You can now start using the tool.") output = subprocess.check_output("cat /etc/*-release", shell=True).decode("UTF-8") - print("Your system information \n" + output) with open("your_system_information.txt", "w") as file: file.write(output) From d53ad4b68483d2991ced9ebb6773b07a2fa17e1b Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 21 Mar 2020 04:11:14 +0100 Subject: [PATCH 13/13] Add wget to basic_tools --- modules/install/ToolsInstaller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/install/ToolsInstaller.py b/modules/install/ToolsInstaller.py index 4538361..e6c64f9 100644 --- a/modules/install/ToolsInstaller.py +++ b/modules/install/ToolsInstaller.py @@ -6,7 +6,8 @@ class ToolsInstaller: def basic_tools(self): """Install the most basic tools!""" print("Try to install basic Command-line tools") - subprocess.run("apt-get install -y bleachbit nano xrdp htop bash-completion dialog powertop tree", shell=True) + subprocess.run("apt-get install -y bleachbit nano xrdp htop bash-completion dialog powertop tree wget", + shell=True) print("Script ran to completion.") def hard_drive_tools(self):