aboutsummaryrefslogtreecommitdiff
path: root/tools/aio/modules/download_tools.py
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-12-11 15:02:08 +0800
committercrupest <crupest@outlook.com>2024-03-25 22:25:21 +0800
commit77c5f0d98f8318c8ec99fee64591b0701e270224 (patch)
tree56d7f83e4d4d736890d8d3999379a459b5d96ccf /tools/aio/modules/download_tools.py
parent52566293e75055513d397bf3ad64af969cd1f185 (diff)
downloadcrupest-77c5f0d98f8318c8ec99fee64591b0701e270224.tar.gz
crupest-77c5f0d98f8318c8ec99fee64591b0701e270224.tar.bz2
crupest-77c5f0d98f8318c8ec99fee64591b0701e270224.zip
tools(aio): move aio and related scripts.
Diffstat (limited to 'tools/aio/modules/download_tools.py')
-rw-r--r--tools/aio/modules/download_tools.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/aio/modules/download_tools.py b/tools/aio/modules/download_tools.py
new file mode 100644
index 0000000..beb06d4
--- /dev/null
+++ b/tools/aio/modules/download_tools.py
@@ -0,0 +1,47 @@
+import sys
+from os.path import *
+from urllib.request import *
+from rich.prompt import Confirm
+from .path import *
+from .helper import print_order
+
+
+TOOLS = [("docker-mailserver setup script", "docker-mailserver-setup.sh",
+ "https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/setup.sh")]
+
+
+def download_tools(console):
+ # if we are not linux, we prompt the user
+ if sys.platform != "linux":
+ console.print(
+ "You are not running this script on linux. The tools will not work.", style="yellow")
+ if not Confirm.ask("Do you want to continue?", default=False, console=console):
+ return
+
+ for index, script in enumerate(TOOLS):
+ number = index + 1
+ total = len(TOOLS)
+ print_order(number, total, console)
+ name, filename, url = script
+ # if url is callable, call it
+ if callable(url):
+ url = url()
+ path = join(tool_dir, filename)
+ skip = False
+ if exists(path):
+ overwrite = Confirm.ask(
+ f"[cyan]{name}[/] already exists, download and overwrite?", default=False, console=console)
+ if not overwrite:
+ skip = True
+ else:
+ download = Confirm.ask(
+ f"Download [cyan]{name}[/] to [magenta]{path}[/]?", default=True, console=console)
+ if not download:
+ skip = True
+ if not skip:
+ console.print(f"Downloading {name}...")
+ urlretrieve(url, path)
+ os.chmod(path, 0o755)
+ console.print(f"Downloaded {name} to {path}.", style="green")
+ else:
+ console.print(f"Skipped {name}.", style="yellow")