diff options
| author | crupest <crupest@outlook.com> | 2022-11-26 21:25:18 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2022-11-26 21:25:18 +0800 | 
| commit | 575c51822285fbcbcf8319e6b1459d290f965116 (patch) | |
| tree | 0c0d8738b631aaa4d9b4c59c6b986ed00a70b1cd /tool | |
| parent | e6c4b5249c7055fe323896041044bd7d515490ca (diff) | |
| download | crupest-575c51822285fbcbcf8319e6b1459d290f965116.tar.gz crupest-575c51822285fbcbcf8319e6b1459d290f965116.tar.bz2 crupest-575c51822285fbcbcf8319e6b1459d290f965116.zip  | |
Add install-docker command to aio.
Diffstat (limited to 'tool')
| -rwxr-xr-x | tool/aio.py | 19 | ||||
| -rw-r--r-- | tool/modules/path.py | 7 | 
2 files changed, 24 insertions, 2 deletions
diff --git a/tool/aio.py b/tool/aio.py index 5498141..d39a839 100755 --- a/tool/aio.py +++ b/tool/aio.py @@ -5,9 +5,10 @@ import os.path  import sys  import argparse  import shutil +import subprocess  import urllib.request  from rich.console import Console -from rich.prompt import Prompt, Confirm +from rich.prompt import Confirm  from modules.path import *  from modules.template import Template  from modules.nginx import * @@ -58,11 +59,14 @@ certbot_command_group.add_argument(  certbot_parser.add_argument(      "-t", "--test", action="store_true", default=False, help="Make the commands for test use.") -clear_parser = subparsers .add_parser( +clear_parser = subparsers.add_parser(      "clear", help="Delete existing data so you can make a fresh start.")  clear_parser.add_argument("-D", "--include-data-dir", action="store_true",                            default=False, help="Also delete the data directory.") +install_docker_parser = subparsers.add_parser( +    "install-docker", help="Install docker and docker-compose.") +  args = parser.parse_args()  if args.action == "certbot": @@ -72,6 +76,17 @@ if args.action == "certbot":  if not args.no_hello:      console.print("Nice to see you! :waving_hand:", style="cyan") +if args.action == "install-docker": +    ensure_tmp_dir() +    get_docker_path = os.path.join(tmp_dir, "get-docker.sh") +    urllib.request.urlretrieve("https://get.docker.com", get_docker_path) +    os.chmod(get_docker_path, 0o755) +    subprocess.run(["sudo", "sh", get_docker_path], check=True) +    subprocess.run(["sudo", "usermod", "-aG", "docker", +                   os.getlogin()], check=True) +    exit(0) + +  if args.action == 'print-path':      console.print("Project path =", project_dir)      console.print("Project absolute path =", project_abs_path) diff --git a/tool/modules/path.py b/tool/modules/path.py index c4cf35b..31298ed 100644 --- a/tool/modules/path.py +++ b/tool/modules/path.py @@ -8,10 +8,17 @@ template_dir = os.path.join(project_dir, "template")  nginx_template_dir = os.path.join(template_dir, "nginx")  data_dir = os.path.join(project_dir, "data")  tool_dir = os.path.join(project_dir, "tool") +tmp_dir = os.path.join(project_dir, "tmp")  config_file_path = os.path.join(data_dir, "config")  nginx_config_dir = os.path.join(project_dir, "nginx-config")  log_dir = os.path.join(project_dir, "log") +  def ensure_log_dir():      if not os.path.exists(log_dir):          os.mkdir(log_dir) + + +def ensure_tmp_dir(): +    if not os.path.exists(tmp_dir): +        os.mkdir(tmp_dir)  | 
