From 304c15370eb51e95325415e03b593ed21803ad23 Mon Sep 17 00:00:00 2001 From: morestar Date: Wed, 28 Aug 2019 22:15:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0docker=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E5=8C=96=E7=AE=A1=E7=90=86=E5=99=A8=EF=BC=88=E6=9C=AA=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/install.py b/install.py index 2dd09b9..7115b1f 100644 --- a/install.py +++ b/install.py @@ -190,6 +190,14 @@ def install_samba(self): def install_docker(self): return + def install_portainer(self): + try: + subprocess.run("docker volume create portainer_data", check=True, shell=True) + subprocess.run("docker run -d -p 8000:8000 -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v " + "portainer_data:/data portainer/portainer", check=True, shell=True) + except subprocess.CalledProcessError: + Logger.error("[ERROR] 请先安装docker ce") + class UbuntuService(BaseService): def __init__(self): @@ -337,6 +345,9 @@ def install_docker(self): time.sleep(2) self.install_docker() + def install_portainer(self): + super().install_portainer() + # 树莓派 class DebianService(BaseService): @@ -604,6 +615,9 @@ def install_docker(self): time.sleep(2) self.install_docker() + def install_portainer(self): + super().install_portainer() + class Install: def __init__(self, os_name): @@ -634,12 +648,13 @@ def help_info(): Logger.info("--up 更新Python3版本") Logger.info("-" * 30) Logger.info("--id 安装docker CE") + Logger.info("--ip 安装docker图形化管理工具") def install(self): try: opts, args = getopt.getopt(sys.argv[1:], "-w-p-s-h", ["pv", "hv", "cas", "cps", "uh", "usp", "ih", "has", "im", - "rh", "phl", "up", "ush", "sh", "sth", "id"]) + "rh", "phl", "up", "ush", "sh", "sth", "id", "ip"]) if self.os_name == "Windows": raise Exception("[ERROR] 不支持Windows操作系统") @@ -696,6 +711,8 @@ def install(self): self.service.stop_ha() elif opt == "--id": self.service.install_docker() + elif opt == "--ip": + self.service.install_portainer() except getopt.GetoptError: self.help_info() From 08699220f831800e300d403d110d80432dc6f52c Mon Sep 17 00:00:00 2001 From: morestar Date: Sat, 16 Nov 2019 15:43:54 +0800 Subject: [PATCH 2/2] Update install.py --- install.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/install.py b/install.py index 7115b1f..f7e8f41 100644 --- a/install.py +++ b/install.py @@ -311,7 +311,8 @@ def install_docker(self): shell=True, check=True) Logger.info("[INFO] 准备添加Docker软件源") subprocess.run( - "sudo add-apt-repository \"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable\"", + "sudo add-apt-repository \"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(" + "lsb_release -cs) stable\"", shell=True, check=True) Logger.info("[INFO] 准备安装Docker CE") self.prepare() @@ -330,7 +331,8 @@ def install_docker(self): Logger.info("[INFO] 准备安装Docker图形管理界面") try: subprocess.run("sudo docker volume create portainer_data", shell=True, check=True) - subprocess.run("sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer", shell=True, check=True) + subprocess.run("sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v " + "portainer_data:/data portainer/portainer", shell=True, check=True) except subprocess.CalledProcessError: Logger.error("[ERROR] 安装Docker图形管理界面失败,准备重新安装") time.sleep(2) @@ -547,7 +549,7 @@ def upgrade_python3(self): try: subprocess.run("sudo wget https://www.python.org/ftp/python/3.7.2/{}.tgz".format(pv), shell=True, check=True) - Logger.info("[INFO] 开始解压安装包") + Logger.info("[INFO] 开始解压") time.sleep(2) subprocess.run("sudo tar -zvxf {}.tgz".format(pv), shell=True) os.chdir("{}/{}".format(base_dir, pv)) @@ -579,7 +581,8 @@ def install_docker(self): Logger.info("[INFO] 准备安装docker CE依赖") try: subprocess.run( - "sudo apt-get install apt-transport-https ca-certificates gnupg2 lsb-release software-properties-common", + "sudo apt-get install apt-transport-https ca-certificates gnupg2 lsb-release " + "software-properties-common", shell=True, check=True) Logger.info("[INFO] 准备添加GPG秘钥") @@ -665,7 +668,7 @@ def install(self): Logger.info("[INFO] 检测到Ubuntu系统") self.service = UbuntuService() self.service.prepare() - elif "Debian" in out: + elif "debian" in out: Logger.info("[INFO] 检测到Debian操作系统") self.service = DebianService() self.service.prepare()