From 76c5dc836392c0acbbc44791d8187e8ea42276ff Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 10 Mar 2020 23:33:52 +0100 Subject: [PATCH] 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)